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?

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.