Page 1 of 1

file_get_contents

Posted: Fri Nov 04, 2005 4:04 pm
by heliobarbosa
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hello People,
My name is Hélio. They forgive my English, but I am Brazilian.

Please they observe the code below. This is the archive ex1.php.

Code: Select all

<?
session_start();
echo session_id() . "<br>";
$tpl=file_get_contents("http://localhost:8080/helio/ex2.php");
echo $tpl;
?>
<a href="ex2.php">Click Here</a>

Now this below is ex2.php:

Code: Select all

<?
session_start();
echo session_id() . "<br>";
?>
They perceive that ex1.php calls ex2.php that they are in the same directory.

However, when I call ex2.php with file_get_contents is created New session_id for the archive ex2.php.

Some form of I exists to use the session 0 variable that I created in the archive ex1.php in the archive ex2.php.

Or then to force ex2.php to read 0 variable created in the Sessao_id of the archive ex1.php?

Bye bye
Hélio


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Fri Nov 04, 2005 4:41 pm
by feyd
by using file_get_contents() on a remote (http) address you have effectively made a separate browser request for the file. use include() instead.

Posted: Fri Nov 04, 2005 4:45 pm
by timvw
Basically, you want to use the session-id to request page2?

Code: Select all

$sessionname = session_name();
$sessionid = session_id();
file_get_contents("http://localhost/ex2.php?$sessionname=$sessionid");