dezkit Posted September 14, 2008 Share Posted September 14, 2008 Does anybody know why i cant access a session that is in another directory? for example I registered a session in the root. When i go to any directory, and try to echo the session, it shows nothing, does anybody know whyy? Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/ Share on other sites More sharing options...
dezkit Posted September 14, 2008 Author Share Posted September 14, 2008 oh and btw, by directory i mean folders, not subdirectories, my bad Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641266 Share on other sites More sharing options...
DeanWhitehouse Posted September 14, 2008 Share Posted September 14, 2008 You have put session_start(); on everypage? Â Also try doing echo session_id(); on the page Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641269 Share on other sites More sharing options...
PFMaBiSmAd Posted September 14, 2008 Share Posted September 14, 2008 The session.cookie_path determines the path that the session cookie will match. The default value of / should match any path - session.cookie_path string session.cookie_path specifies path to set in session_cookie. Defaults to /. See also session_get_cookie_params() and session_set_cookie_params(). Â Check what your session.cookie_path setting is using a phpinfo(); statement. Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641271 Share on other sites More sharing options...
dezkit Posted September 14, 2008 Author Share Posted September 14, 2008 @blade: Yeah, i see like 10 to 20 numbers. Â @PFMAB: ill check that right now, thanks @PFMAB: i just checked it, and it is set to "/" Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641278 Share on other sites More sharing options...
DeanWhitehouse Posted September 14, 2008 Share Posted September 14, 2008 OK, then so u can have sessions, is the subdirectory the same url e.g. mysite.com/page.php (is the main one then subdirectory is) sub.mysite.com , or is it mysite.com/folder/index.php. Â If its sub.mysite.com i dont think sessions will pass through, also are you sure you are echoing the right session name , and if it has anything stored on it , try error_reporting(E_ALL); at the top. Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641282 Share on other sites More sharing options...
dezkit Posted September 14, 2008 Author Share Posted September 14, 2008 What the hell. I put "echo session_id();" on "/" "/administrator/" and "/administrator/email" Â ALSO, everytime i refresh the pages, the session id changes!! Â @blade: i have mysite.com/ mysite.com/administrator/ and mysite.com/administrator/email/ Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641284 Share on other sites More sharing options...
redarrow Posted September 14, 2008 Share Posted September 14, 2008 can we see some code please ass long as every page got <?php session_start(); <<< at the beging ?> should work......... dont forget we mean every page including pages in other sub directorys.......... Â have you set the session's correctly........... Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641287 Share on other sites More sharing options...
DeanWhitehouse Posted September 14, 2008 Share Posted September 14, 2008 yes, session_id(); will be different everytime, because its a temporary id from session start (i beleive) Â And yes ,session_start(); must be on every single page, everyone (other wise the person will go to one and there session will be destroyed) Â Â Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641291 Share on other sites More sharing options...
dezkit Posted September 14, 2008 Author Share Posted September 14, 2008 this is part of my checklogin.php in the public_html folder <?php if($count=="1"){ session_register("myusername"); header("location: http://www.mysite.com/index.php"); } else { header("location: http://www.mysite.com/home.php?type=841927408208"); } ?> Â this is part of my index.php in the public_html/administrator/ folder <?php session_start(); if(!session_is_registered(myusername)){ header("location:http://www.mysite.com/home.php?type=609421098494"); } ?> ... BLAH BLAH BLAH ... <?php $page = $_GET["page"]; $ext = $_GET["ext"]; if($page == "email"){ include_once("http://www.mysite.com/administrator/email/"); } else { echo "<-- Click to navigate."; echo session_id(); } ?> Â this is part of my index.php in the public_html/administrator/email/ folder <?php session_start(); if(!session_is_registered(myusername)){ header("location:http://www.mysite.com/home.php?type=609421098494"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641292 Share on other sites More sharing options...
DeanWhitehouse Posted September 14, 2008 Share Posted September 14, 2008 <?php if($count=="1"){ session_register("myusername"); header("location: http://www.mysite.com/index.php"); } else { header("location: http://www.mysite.com/home.php?type=841927408208"); } ?> Â Where is session start? Â also this is outdated i think , change session_register("myusername"); to $_SESSION['session_name'] = $value; Â and change if(!session_is_registered(myusername)){ to if(!isset($_SESSION['session_name'])){ Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641296 Share on other sites More sharing options...
dezkit Posted September 14, 2008 Author Share Posted September 14, 2008 Now that i changed "$_SESSION['session_name'] = $value;" to "$_SESSION['session_name'] = $value;" Â I get the same session id, but i still have the same problem. Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641302 Share on other sites More sharing options...
DeanWhitehouse Posted September 14, 2008 Share Posted September 14, 2008 Where is session start? Â It is not on the page where the session is created. Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641303 Share on other sites More sharing options...
dezkit Posted September 14, 2008 Author Share Posted September 14, 2008 PROBLEM SOLVED!! THANKS ALL! especially blade :] Â and instead of changing if(!session_is_registered(myusername)){ to if(!isset($_SESSION['session_name'])){ Â I changed if(!session_is_registered(myusername)){ to if(isset($_SESSION['session_name'])){ Â Notice there is no exclamation point. Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641304 Share on other sites More sharing options...
DeanWhitehouse Posted September 14, 2008 Share Posted September 14, 2008 Yes, i assumed you were checking to see if the session wasnt there, by checking to see if it exists (if not do) Â But no problem, remeber session start, also maybe update your learning resource (for sessions anyways) Â Â Edit: Click solved at the bottom : Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641307 Share on other sites More sharing options...
dezkit Posted September 14, 2008 Author Share Posted September 14, 2008 Oh wtf. When i put in your code, it didn't work, when i removed the exclamation point, 5 seconds later, it stopped working, now i put back the exclamation point, and its back to working. Â either i have down syndrome or i am just tired. :/ Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641311 Share on other sites More sharing options...
dezkit Posted September 14, 2008 Author Share Posted September 14, 2008 Wow. PROBLEM remains. Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641330 Share on other sites More sharing options...
DeanWhitehouse Posted September 14, 2008 Share Posted September 14, 2008 what problem and its back to working. Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641334 Share on other sites More sharing options...
redarrow Posted September 14, 2008 Share Posted September 14, 2008 it ur browser................ Â Â the browser needs to shut for some time before a new session works............... Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641337 Share on other sites More sharing options...
dezkit Posted September 14, 2008 Author Share Posted September 14, 2008 Okay, i'm gonna try to explain it clearly. Â 1. You log in with the username and password in /public_html/index.php 2. The script checks if the username and password is correct, and if the username and password is correct, it creates a session called "myusername" and assigns it to $myusername, then the script redirects to the home page. 3. On top of the home page, there is a log in menu, the log in is actually a page called loginmenu.php in the public_html/ but it is actually include()'ed into the home page. 4. When somebody is logged in, it echos "hello $myusername" and it echos it good. Also to the right of Hello $myusername, it shows a link to "/administrator/" 5. This is where the problem is. When somebody goes to /administrator/, while the session is active, i see the login menu, instead of "Hello $myusername." 6. When i return to the root, it shows hello $myusername, and once again when i click /administrator/, i see the login menu, also btw, the login menu in /administrator/index.php is really and include of loginmenu.php in the root. Â Â thanks you guys very very much! Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641349 Share on other sites More sharing options...
dezkit Posted September 14, 2008 Author Share Posted September 14, 2008 And when i go to mysite.com/administrator/ or mysite.com/administrator/email without being logged in... i get redirected to the home page, meaning, that i don't have the session registered. (good thing) Â Â EDIT: 600 POSTS WOOT Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641369 Share on other sites More sharing options...
DeanWhitehouse Posted September 14, 2008 Share Posted September 14, 2008 On these pages the session they are checking for , or the value is it the same as the session you have been set? Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641374 Share on other sites More sharing options...
dezkit Posted September 14, 2008 Author Share Posted September 14, 2008 <?php session_start(); if(!isset($_SESSION["myusername"])){ echo "session is not set" } else { echo "session is set" } ?> Â meaning that i check if $_SESSION["myusername"] has a value, not what the value is. Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641386 Share on other sites More sharing options...
DeanWhitehouse Posted September 14, 2008 Share Posted September 14, 2008 Isset doesnt check if it has a value , it checks if the $var (in this case session) is present  try <?php session_start(); if(isset($_SESSION["myusername"])){ echo "session is set" } else { echo "session is set" } ?>  There is no reason why this or the previous one wont work. Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641391 Share on other sites More sharing options...
dezkit Posted September 14, 2008 Author Share Posted September 14, 2008 Oh yeah, and when i copied and pasted index.php from /administrator/ and made it admintest.php in the root, same shit. so i am guessing the file has something bad in it? Quote Link to comment https://forums.phpfreaks.com/topic/124198-my-sessions-are-broken/#findComment-641410 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.