2016-03-22 4 views
0

login.phphalte Sitzung in file_get_content zwischen verschiedener Datei

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

getfile.php

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

ich ersten Anruf login.php will und dann getfile.php mit file_get_content oder curl aber wenn Anruf getFile.php Sitzung ist leer wie kann Sitzung von login.php in getfile.php behalten?

$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); 

Antwort

0

Ihr Code funktioniert. Verwenden Sie einfach session_start() im dritten Block und verwenden Sie die vollständige URL in file_get_contents.