Running a file_get_contents () session in PHP

Preamble: My application supports mod_rewrite, and I have an index.php page that loads vaious pages based on Request_URI and prints them as the contents of the page.

Problem: The File () or File_get_contents () function is excellent when loading my other application pages. But as soon as I try to use it to load the page with the session turned on , I have problems.

The main problem is that when I try to transfer an existing session id to a URL from a download page, for example

  $url = "http://localhost/EmplDir/AdminMenu.php";
  return implode('',file($url. "&" . session_name() . "=". session_id()));

My page never loads (or file () never loads content). I suspect that I am using curl functions here, but it has too many options. My advice which waving options to use to load pages about the current PHP session would be helpful.

PS The above seems to be true for both Windows and Linux.

+3
source share
3 answers

You did not separate the query string from the rest of the URL with <? p>

Try

return file_get_contents($url. "?" . session_name() . "=". session_id());

You also need to make sure that the server does not use the session.use-only-cookies configuration parameter .

, script , , script, var_dump ($ _ GET) , . , script, , , , .

. , , , .

+3

script , :

ob_start();
include $_SERVER['DOCUMENT_ROOT'].'/EmplDir/AdminMenu.php';
return ob_get_clean();
+2

session_name session_id ; . , http. Curl, - SimpleBrowser, .

0

Source: https://habr.com/ru/post/1703818/


All Articles