PDA

View Full Version : PHP sessions



radikaled
12-27-2006, 12:07 AM
I'm having problems getting PHP sessions to work. I have a subdomain off of my main domain where the scripts are stored (essentially the site, so subdomain.domain.com/foo.php for example). The following does not work:

<?php
start_session();

echo "SID: ".SID;
?>

This outputs a blank ("") string for the SID variable. I have copied the php.ini into all directories where scripts reside. What am I doing wrong?

areidmtm
12-27-2006, 08:51 AM
Sessions ONLY work for one domain at a time. However, you can transfer the session to another domain.

Make a transfer.php file in the domain that your transferring too.

To transfer the sessions, you need the session ID that you're using and send it to the transfer.php file. You can post the ID or just place it in the URL.



<a href="www.domin.com/transfer.php?sID=<?= session_id(); ?>">Go to other site</a>


Place this code in the transfer.php



<?php
session_id($_GET['sID']);
session_start();
header("Cache-control: private");

?>
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=/page.html">

Pethens
12-27-2006, 12:46 PM
It's expected for SID to be blank if the session id is stored in a cookie. Try browsing the same page with cookies turned off in your browser and see what result you get.

Also, use session_start(), not start_session().