acidglitter Posted August 7, 2007 Share Posted August 7, 2007 At the very top of my login page it shows this <?php session_start(); header("Cache-control: private"); if ($_SESSION['peachy']){ header("Location: ..."); exit(); } so if you're already logged in, you don't have to login again, and that works perfectly. But when it forwards to the next page (which is in a different folder), it says you're not logged in. This is the current code at the very top of the 2nd page <?php session_start(); header("Cache-control: private"); if(!isset($_SESSION['peachy'])){ echo "you're not logged in"; exit(); } ?> I tried copying the one from the other page, but for some reason it won't work on this page. It worked earlier today but now it won't. I can't figure out whats wrong I think somehow the session is lost.. Link to comment https://forums.phpfreaks.com/topic/63652-really-stupid-question-but-i-cant-figure-it-out/ Share on other sites More sharing options...
teng84 Posted August 7, 2007 Share Posted August 7, 2007 can you show where did you initialize the session Link to comment https://forums.phpfreaks.com/topic/63652-really-stupid-question-but-i-cant-figure-it-out/#findComment-317206 Share on other sites More sharing options...
acidglitter Posted August 7, 2007 Author Share Posted August 7, 2007 Its an html form and the 2nd page shows this.. <?php if(isset($_GET['p'])){ $word=md5($_POST['word']); $where=".."; $chpass=mysql_query("SELECT pass FROM info WHERE pass='$word'"); if(mysql_num_rows($chpass)>0){ $_SESSION['peachy']="yes"; $_SESSION['tableid']="$thesessionid"; header("Location: $where"); } else { echo "Wrong password..<p>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/63652-really-stupid-question-but-i-cant-figure-it-out/#findComment-317208 Share on other sites More sharing options...
Fadion Posted August 7, 2007 Share Posted August 7, 2007 do u have session_start() for the last code u posted? Link to comment https://forums.phpfreaks.com/topic/63652-really-stupid-question-but-i-cant-figure-it-out/#findComment-317227 Share on other sites More sharing options...
acidglitter Posted August 7, 2007 Author Share Posted August 7, 2007 Yep, on the login page and the 2nd page I have session_start() at the top. Everything has been working for months. And then I decided the username part was pointless for this so I deleted it from the info table and the login page, and since then it stopped working..... Link to comment https://forums.phpfreaks.com/topic/63652-really-stupid-question-but-i-cant-figure-it-out/#findComment-317229 Share on other sites More sharing options...
acidglitter Posted August 7, 2007 Author Share Posted August 7, 2007 Is there a way the session could have been lost? Link to comment https://forums.phpfreaks.com/topic/63652-really-stupid-question-but-i-cant-figure-it-out/#findComment-317241 Share on other sites More sharing options...
jst4fun Posted August 7, 2007 Share Posted August 7, 2007 Not sure if my post would be of any help. But just try some changes in your code <?php if(isset($_GET['p'])){ $_SESSION['peachy']= false; $word=md5($_POST['word']); $where=".."; $chpass=mysql_query("SELECT pass FROM info WHERE pass='$word'"); if(mysql_num_rows($chpass)>0){ $_SESSION['peachy']= true; $_SESSION['tableid']="$thesessionid"; header("Location: $where"); } else { echo "Wrong password..<p>"; $_SESSION['peachy']= false; } } ?> and then to check if your login is correct do this <?php session_start(); header("Cache-control: private"); if(!$_SESSION['peachy']){ echo "you're not logged in"; exit(); } ?> Just try this. It might work Link to comment https://forums.phpfreaks.com/topic/63652-really-stupid-question-but-i-cant-figure-it-out/#findComment-317248 Share on other sites More sharing options...
acidglitter Posted August 7, 2007 Author Share Posted August 7, 2007 I tried that, but it didn't work either Link to comment https://forums.phpfreaks.com/topic/63652-really-stupid-question-but-i-cant-figure-it-out/#findComment-317305 Share on other sites More sharing options...
acidglitter Posted August 7, 2007 Author Share Posted August 7, 2007 I fixed the problem. It was all because on the login page, where it says header("Location: $where");, the $where address was http://mysite. When I changed it back to http://www.mysite it worked again.. Why would that tiny difference stop all of this from working? ??? Link to comment https://forums.phpfreaks.com/topic/63652-really-stupid-question-but-i-cant-figure-it-out/#findComment-317361 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.