alluoshi Posted April 22, 2009 Share Posted April 22, 2009 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? Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 22, 2009 Share Posted April 22, 2009 Why pass the session ID over in the URL when you can grab it at any time using session_id() Quote Link to comment Share on other sites More sharing options...
alluoshi Posted April 22, 2009 Author Share Posted April 22, 2009 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). Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 22, 2009 Share Posted April 22, 2009 $sid=session_id(); Then pass $sid in a URL. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.