Page 1 of 1
Sessions problem maybe bug?
Posted: Sun Nov 04, 2007 6:30 pm
by hakperest
I am using a file like as follow (a.php)
Code: Select all
<? session_start();
$_SESSEION["a"]="any thing";
echo $_SESSEION["a"];
?>
when I want call this file by
file() or
file_get_contents() functions sessions not working anyway.
b.php
Code: Select all
<?
echo file_get_contents("http://localhost/a.php");
?>
I can not see anything at second file (b.php)
Re: Sessions problem maybe bug?
Posted: Sun Nov 04, 2007 7:30 pm
by Christopher
It should be:
Code: Select all
<? session_start();
$_SESSION["a"]="any thing";
echo $_SESSION["a"];
?>
and what's not working?
Posted: Sun Nov 04, 2007 8:35 pm
by Weirdan
and what's not working?
obviously he would get new session every time he request the file - file_get_contents() won't save session cookie for him.
correction
Posted: Mon Nov 05, 2007 4:00 am
by hakperest
Thanks for your replies.
any sessions that saved before. for example
when I call following page independently, I can see value of session. but when I want get it by file(); command sessions work only for which sessions that defined newly.
Code: Select all
<? session_start();
$_SESSION["n"]="any thing 1<br>";
echo $_SESSION["n"].$_SESSION["m"];
?>
by calling page I see
but using file(); or file_get_contents(); command , I see like:
Posted: Mon Nov 05, 2007 4:13 am
by onion2k
file() and file_get_contents() can't use sessions. To use a session you need to save a cookie.
Use curl instead -
http://uk3.php.net/curl
Posted: Mon Nov 05, 2007 6:51 am
by seppo0010
Using file or file_get_contents you are using a different session. If you open the page with you browser, your browser is the client and is storing the cookie with the session id, but if you open it from Apache, your client is Apache and the session id is different