btr2007 Posted December 12, 2007 Share Posted December 12, 2007 Me again, my problem has now moved on to the cookies and the setting of them. The login is working and that is great but I have code which is meant to change the login area to say 'you are now logged in' and of course have a logout button. But the problem is my cookies don't seem to be setting correctly. setcookie('user', $client, time()+60*60*24*30, "/", ".mydomain.com/", 1); setcookie('pass', $pass, time()+60*60*24*30, "/", ".mydomain.com/", 1); header("Location: http://www.brickcollection.com/btr/test.php"); Then whenever any other page loads it executes this code: if (isset($_COOKIE['user']) && isset($_COOKIE['pass'])) { $client = mysql_real_escape_string($_COOKIE['user']); $pass = mysql_real_escape_string($_COOKIE['pass']); It then checks what type of user you are etc. At the end of the above if stmt I added an else saying 'print 'No Cookies Set';' When I then test the page even after logging it still says the that you are not logged in, but I know that i am because it has redirected to the logged in page. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 12, 2007 Share Posted December 12, 2007 This ".mydomain.com/" should just be "/" if you want it for the whole site. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 12, 2007 Share Posted December 12, 2007 setcookie ('user', $client, time () + (60*60*24*30),'/'); Quote Link to comment Share on other sites More sharing options...
btr2007 Posted December 12, 2007 Author Share Posted December 12, 2007 that may have done it, it comes up saying you are logged in and everything but once the cookies are set it has errors along the lines of Warning: Cannot modify header information - headers already sent by (output started at /index.php:7) in /check-user.php on line 18 and also one for line 19 line 18 and 19 are the lines of code that set the cookies Quote Link to comment Share on other sites More sharing options...
atticus Posted December 12, 2007 Share Posted December 12, 2007 I'm a noob, but I did have a similar problem with sessions and logins. I learned from someone on this forum that if the page is encoded in: UTF-8, that it will sometimes give that error. When I changed my encoding in my text editor to ANSI, my problem was solved. Maybe it will work for you? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 13, 2007 Share Posted December 13, 2007 That error means you sent output to the browser before you set the cookie. Quote Link to comment Share on other sites More sharing options...
btr2007 Posted December 13, 2007 Author Share Posted December 13, 2007 So where is it best to set the cookies? In the check-user.php file nothing is outputted to the browser. Is it because in index.php check-user.php isn't called until further down the page, in the middle of all the html. I'm getting this error in another place as well, but I think once one is sorted i'll be able to sort the other one Quote Link to comment Share on other sites More sharing options...
revraz Posted December 13, 2007 Share Posted December 13, 2007 You just need to rearrange your code so the cookie is set before that page or includes sent output to the browser. 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.