file_get_contents

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
heliobarbosa
Forum Newbie
Posts: 1
Joined: Fri Nov 04, 2005 3:53 pm

file_get_contents

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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");
Post Reply