Jump to content

[SOLVED] My Cookies are crumbling


btr2007

Recommended Posts

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.

 

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.