fesan Posted March 13, 2013 Share Posted March 13, 2013 Hi... Updating a small site of mine. I had a header that read header("location: full-web-page-url"). I replaced this code so it is a bit easier to update my pages in the future. I then added this code: host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = 'index.php'; The page has worked flawless before i did this and now i have a "refresh delay". The first page is a form that a user submits. This takes the user to a new page with the execute code(no visuals for user). after execution the page runs this code(se below) to take them back with info about the execution. _SESSION["message"] = "Eventinfoen er endret."; header("Location: http://$host$uri/$extra"); The header works fine and the code executes fine, but the session message is not echoed on the next page before i press refresh in my browser. In the php manual i find this: Session ID is not passed with Location header even if session.use_trans_sid is enabled. It must by passed manually using SID constant. Does this involve every session variables? If that is the case how do i use a SID constant to transfer all my variables? Quote Link to comment https://forums.phpfreaks.com/topic/275624-header/ Share on other sites More sharing options...
Love2c0de Posted March 13, 2013 Share Posted March 13, 2013 (edited) You declare a session as $_SESSION['session_name']. You missed the dollar sign. $_SESSION is a superglobal, just like $_SERVER which you used previously. Take a look here:http://php.net/manual/en/language.variables.superglobals.php Also, I'm pretty sure if you start a session in a file, then locate to a new file using a header() call, then you have to restart the session also with session_start(). If you locate to the new page with an include() or require(), you don't have to re-declare the session_start(). Depends what you want to do because obviously after including the file it will return to the calling script eventually. Hope this helps. Kind regards, L2c. Edited March 13, 2013 by Love2c0de Quote Link to comment https://forums.phpfreaks.com/topic/275624-header/#findComment-1418458 Share on other sites More sharing options...
fesan Posted March 13, 2013 Author Share Posted March 13, 2013 yea, i missed out the dollar sign while copying! it is in the original code. There is no change in the pages except from i have changed the header goal from an direct URL to a PHP made url. Before i changed the code everything worked out as i wanted. The Index.php has a "session_start()" at the veyr start so it s re-declared every time the page is refreshed. Quote Link to comment https://forums.phpfreaks.com/topic/275624-header/#findComment-1418460 Share on other sites More sharing options...
Love2c0de Posted March 13, 2013 Share Posted March 13, 2013 (edited) Run a var_dump() on $uri just after setting it. It's returning an empty string for me even though when I do print_r($_SERVER), there is a value in theat index. There is a problem which lies in your dirname() call I think, you are passing a filename when you should be passing a directory name. Whether it is affecting it I don't know because you seem adamant you are successfully getting to the header page and the only place you use the $uri variable is in the header call.. Kind regards, L2c. Edited March 13, 2013 by Love2c0de Quote Link to comment https://forums.phpfreaks.com/topic/275624-header/#findComment-1418465 Share on other sites More sharing options...
fesan Posted March 14, 2013 Author Share Posted March 14, 2013 (edited) i did a var_dump() on all 3 variables: string(15) "www.bahrawy.net" string(13) "/dev/ballroom" string(9) "index.php" echo $host.$uri."/".$page; www.bahrawy.net/dev/ballroom/index.php I can't see the the difference between these two: - header("Location: http://$host$uri/$page"); - header("Location: http://www.bahrawy.net/dev/ballroom/index.php"); and thanks for the help by the way! Edited March 14, 2013 by fesan Quote Link to comment https://forums.phpfreaks.com/topic/275624-header/#findComment-1418667 Share on other sites More sharing options...
Solution fesan Posted March 14, 2013 Author Solution Share Posted March 14, 2013 Ahhh.... i found the error! Just me doing stupid things without thinking! My process page is not included in my index where the rest of my includes are. Therefore my variables where not set in the process page. Thanks for the push!! Quote Link to comment https://forums.phpfreaks.com/topic/275624-header/#findComment-1418669 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.