poofacer Posted August 28, 2007 Share Posted August 28, 2007 My problem revolves around the setting of cookies. My sample website has a simple login with username and password fields. When I log in, the cookies are set. however when I return to Index.php(main page) or just type localhost (so the index part doesn't show up) it doesn't show me as logged in. The username and password fields should be replaced with the username and different user CP links. Only when I click on a link which uses the "?action=whatever" does the user CP show up. But every time I click on Home, it goes back to the empty fields. Why aren't my cookies being read at the Index.php? Here is my code. Yes there is some raw HTML above this code. But I don't think this should matter. I also tried the isset function which has the same behaviour. <?php $auth=$_COOKIE["auth"]; if($auth == "yes") { echo "// "."<B>".$_COOKIE["username"]." </B>"."//"; echo "<A HREF=\"javascript:void(0)\" onClick=\"window.open('stats.php','User Stats',config='width=400,height=200,scrollbars=yes')\"> Stats </A> // "; echo "<A HREF=\"javascript:void(0)\" onClick=\"window.open('memberlist.php','Members List',config='width=400,height=200,scrollbars=yes')\">Memberlist </A> // "; echo " profile //"; echo "<A HREF=\"logout.php\">[Log out]</A>"; } else { echo " <FORM method='post' action=\"logged.php\"><B>MEMBER LOGIN:</B> Username:<INPUT type='text' size='15' maxlength='30' name='username'> Password:<INPUT type='text' size='15' maxlength='30' name='password'> <INPUT type='Submit' VALUE='Go'> <A HREF=\"/?act=register\">register</A> <A HREF=\"/?act=forgotpassword\">forgot password?</A> </FORM> "; } Here is my code for placing the cookies from a different file(to avoid header errors). This is not the complete code. I omitted by database login information and SQL queries. <?php if ($num > 0) { setcookie("auth","yes",time()+3600); //USER AND PASS ARE CORRECT setcookie("username",$user,time()+3600); echo "you are logged in."; } else { echo "<B>Invalid Username or Password.</B>"; echo "you are not logged in"; } ?> Thank you for your time. Quote Link to comment https://forums.phpfreaks.com/topic/67114-strange-login-problem/ Share on other sites More sharing options...
php_tom Posted August 28, 2007 Share Posted August 28, 2007 Maybe this is a dumb question but its worth asking: do you have cookies enabled in your browser? Quote Link to comment https://forums.phpfreaks.com/topic/67114-strange-login-problem/#findComment-336588 Share on other sites More sharing options...
poofacer Posted August 28, 2007 Author Share Posted August 28, 2007 Yes ofcourse, or I couldn't log into this site I assume. But now that you mention it, I am using Opera Browser for Windows and it is causing the problem. I also tried in IE 6 and it has a similar problem. It is ok with localhost/index.php but not with localhost itself(doesn't show me logged in). Firefox is the only browser which interprets my code correctly. Another question, I haven't specified the type of HTML coding. ie. Transitional, Strict. I do not have the DOC TYPE header. Could this be tricking the browsers? PS: Firefox is too gangster. Quote Link to comment https://forums.phpfreaks.com/topic/67114-strange-login-problem/#findComment-336603 Share on other sites More sharing options...
poofacer Posted August 28, 2007 Author Share Posted August 28, 2007 Can someone shed some light on my post above this? Quote Link to comment https://forums.phpfreaks.com/topic/67114-strange-login-problem/#findComment-336674 Share on other sites More sharing options...
Jessica Posted August 28, 2007 Share Posted August 28, 2007 send ALL of the arguments that setcookie takes Quote Link to comment https://forums.phpfreaks.com/topic/67114-strange-login-problem/#findComment-336680 Share on other sites More sharing options...
designationlocutus Posted August 28, 2007 Share Posted August 28, 2007 Hmm could you use sessions? Quote Link to comment https://forums.phpfreaks.com/topic/67114-strange-login-problem/#findComment-336681 Share on other sites More sharing options...
poofacer Posted August 28, 2007 Author Share Posted August 28, 2007 I sent all the arguments but Opera still handles the cookies in a funky manner. Quote Link to comment https://forums.phpfreaks.com/topic/67114-strange-login-problem/#findComment-336711 Share on other sites More sharing options...
poofacer Posted August 29, 2007 Author Share Posted August 29, 2007 Can somebody see why Opera and IE cannot handle the cookies properly while Firefox can? Quote Link to comment https://forums.phpfreaks.com/topic/67114-strange-login-problem/#findComment-337366 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.