Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Continuing Sessions in Socket-Retrieved Pages

Status
Not open for further replies.

cjohnson

Programmer
Dec 4, 2002
3
US
Hi.

I'm working on a project where I need to send a user an e-mail whose content is identical to an already existing PHP-generated web page. (This web page relies on session data to do its work.) The mail function in PHP requires that I save the HTML of this page into a variable and send it along as the third parameter. The simplest way to retrieve the HTML is through a socket connection, correct? The problem I'm suffering from, however, is that when I try to GET a page through a socket, the session information is not retained for the page being retrieved. To correct this, I try sending along ?session_name()=session_id() after the name of the page in the GET header. However, doing this causes the browser to hang indefinitely.

Here's the code I've been working with.

$fp = fsockopen (" 80, $errno, $errstr);

fputs ($fp, "GET /itemizeFoods.php?" . session_name() . "=" . session_id() . " HTTP/1.0\n\n");

while (! feof ($fp)) {
$message .= fgets ($fp, 128);
}

mail ($target_email,
'Food Reports',
$message,
"From: $source_email\n"
. "Reply-To: $source_email\n"
. 'X-Mailer: PHP/' . phpversion() . "\n"
. "Content-type: text/html; charset=iso-8859-1\n" );

I've also tried just passing the query string as ?id=session_id() (not PHPSESSID=session_id() and including at the top of the the PHP-generated page the following.

session_id($id);
session_start();

This also causes the browser to hang.

If I open a new browser and manually type itemizeFoods.php?PHPSESSID=396 (or whatever the ID happens to be of my current session) or link to itemizeFoods.php?396 the session continues just fine. The page loads properly and session variable values are consistent. It's only when I try to retrieve a page through a socket that the problem arises.

Others have referred me to the curl library, but the installation of PHP I have to work with was not compiled with curl and can't be changed.

If you have any ideas as to how I might fix or circumvent my problem, please let me know.

--
Chris Johnson
 
The pages are not only on the same server, but in the same directory.

--
Chris Johnson
 
That's what I'm doing, actually, until I find a better solution. This solution is just a bit too redundant, and changes to one script might fail to make it over to the shadow.

Theoretically, the socket solution should work, right?

--
Chris Johnson
 
Take a look at PHP's include(), include_once(), require(), and require_once() functions (
You can create a file with the PHP code necessary to produce your needed output to an array. Each file can include() that file and run it. The displaying scipt can show the data, the emailing script can email it.

And you have one code base on which both outer scripts operate. Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top