【问题标题】:keep session in file_get_content between different file在不同文件之间的 file_get_content 中保持会话
【发布时间】:2016-03-22 19:27:41
【问题描述】:

登录.php

session_start();
$_SESSION["login"]=true;

getFile.php

if($_SESSION["login"]==true)
    echo "send file";
else
    die("you have not access!");

我想先调用 login.php 然后用 file_get_content 或 curl 调用 getFile.php 但是当调用 getFile.php 会话为空时,如何保持会话从 login.php 到 getfile.php?

$options = array(
            'http' => array(
            'header'=>"Content-type: application/x-www-form-urlencoded\r\nAccept-language: en\r\n" .
               "Cookie: ".session_name()."=".session_id()."\r\n",           
            'method'  => 'POST',
            'content' => http_build_query($data),
        )
    );

    $context  = stream_context_create($options);
    session_write_close();
    $result = file_get_contents($url, false, $context);

【问题讨论】:

    标签: php session curl file-get-contents


    【解决方案1】:

    您的代码正在运行。只需在第三个块中使用 session_start() 并在 file_get_contents 中使用完整的 url。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-19
      • 1970-01-01
      • 2012-11-30
      • 1970-01-01
      • 1970-01-01
      • 2011-03-01
      相关资源
      最近更新 更多