Sessions problem maybe bug?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
hakperest
Forum Newbie
Posts: 5
Joined: Sun Nov 04, 2007 6:18 pm

Sessions problem maybe bug?

Post 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)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Sessions problem maybe bug?

Post by Christopher »

It should be:

Code: Select all

<? session_start();
$_SESSION["a"]="any thing";
echo $_SESSION["a"];
?>
and what's not working?
(#10850)
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
User avatar
hakperest
Forum Newbie
Posts: 5
Joined: Sun Nov 04, 2007 6:18 pm

correction

Post by hakperest »

Thanks for your replies.
any sessions that saved before. for example

Code: Select all

$_SESSION["m"]="any thing 2";
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

Code: Select all

any thing 1<br>any thing 2
but using file(); or file_get_contents(); command , I see like:

Code: Select all

any thing 1<br>
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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
User avatar
seppo0010
Forum Commoner
Posts: 47
Joined: Wed Oct 24, 2007 4:13 pm
Location: Buenos Aires, Argentina

Post 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
Post Reply