Jump to content

how to use $_COOKIE['PHPSESSID'] inside the header function?


alluoshi

Recommended Posts

I am using the header function for redirection. I would like to include the session id within the URL using the value of the session id that is stored in the cookie. I have 4 files in the same directory. I have "session_start()" in the file main.php where users access this page first. Now When the users access another page (x.php), I want them to be redirected to (y.php) with the session id embedded in the url (this is because Apache logs each request and I need this info later). I would like to retrieve the session id using $_COOKIE['PHPSESSID'] and not session_id(). In the file y.php, I put: header("Location:.../y.php?sessionid=".print $_COOKIE['PHPSESSID']); but didn't work. I noticed that "print $_COOKIE['PHPSESSID']" doesn't work even without header(). I tried $id=$_COOKIE['PHPSESSID'] then "print $id" and it worked. I tried to put $id=$_COOKIE['PHPSESSID'] before the header() so that I can use  header("Location:.../y.php?sessionid=".print $id) but it didn't work even with "ob_start()" in the beginning. Any help please?

because I need Apache to log the url of the request with the session id. Is there a way to define $id=$_COOKIE['PHPSESSID'] in the page main.php after session_start() and allow this variable "$id" to be accessible in any page. In this case I can solve my problem when I use header("Location:.../y.php?sessionid=".print $id).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.