Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 26th, 2005, 2:54 PM   #1
TCStyle
Programmer
 
Join Date: Jan 2005
Location: Albany, NY
Posts: 43
Rep Power: 0 TCStyle is on a distinguished road
Testing to see if a cookie is set

I am writting a member register/login script for my site, but have run into a problem. When the user logs in, the information from my html form goes to a page with this script on it:

<?
mysql_connect("localhost", "root") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

$UserName= $_POST['UserName'];
$Password= $_POST['Password'];

$result = mysql_query("SELECT * FROM memberNess
WHERE UserName='$UserName'") or die(mysql_error());

$row = mysql_fetch_array($result);

if ($row['UserName'] == $UserName && $row['Password'] == $Password)
{
setcookie("LoginCookie", "Cookie Is Set", time()+86400);
echo "Welcome, your are now logged in";
} else {
print "An error has occured";
}

?>

Now, I cannot find a problem with this script, but when I test to see if my cookie is set it says its not? Any help greatly apperciated
TCStyle is offline   Reply With Quote
Old Jan 26th, 2005, 3:48 PM   #2
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
You should post the code that you are using to check the cookie. We'll be able to help you better.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Jan 26th, 2005, 3:59 PM   #3
TCStyle
Programmer
 
Join Date: Jan 2005
Location: Albany, NY
Posts: 43
Rep Power: 0 TCStyle is on a distinguished road
as

All I'm using to check is the isset function, so:

if (isset($_COOKIE['LoginCookie']))
{
echo "Yup its set";
}
if (!isset($_COOKIE['LoginCookie']))
{
echo "This shit is pissing me off";
}
TCStyle is offline   Reply With Quote
Old Jan 26th, 2005, 4:22 PM   #4
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
are you developing on a Windows XP box and IE6? If so there are issues with cookies and the way you set the domain.

From the Microsoft page:
"Internet Explorer 6 implements advanced cookie filtering that is based on the Platform for Privacy Preferences (P3P) specification. By default, Internet Explorer 6 blocks third-party cookies that do not have a compact policy (a condensed computer-readable privacy statement) or third-party cookies that have a compact policy which specifies that personally identifiable information is used without your implicit consent. First-party cookies that have a compact policy which specifies that personally identifiable information is used without implicit consent are downgraded (deleted when you close Internet Explorer). First-party cookies that do not have a compact policy are leashed (restricted so that they can only be read in the first-party context)."

See:
http://support.microsoft.com/default...260971&GSSNB=1

For more about P3P:
http://www.w3.org/P3P/


Also more info can be found at: http://ca3.php.net/manual/en/function.setcookie.php near the bottom in the user comments.

If you are using something else other than Windows XP and IE6 then i would next check to see if your browser is set to allow cookies. If it is, then i am not sure where to look next. Maybe in your php.ini file?

Also to save your self some time use an else statment:
[PHP]
if (isset($_COOKIE['cookie']))
{
echo "Worked.";
}
else
{
echo "Didn't Work.";
}
[/PHP]
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!

Last edited by Pizentios; Jan 26th, 2005 at 4:30 PM.
Pizentios is offline   Reply With Quote
Old Jan 26th, 2005, 4:42 PM   #5
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Might i suggest, sessions.

[php]
<?php
mysql_connect("localhost", "root") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

$UserName= $_POST['UserName'];
$Password= $_POST['Password'];

$result = mysql_query("SELECT * FROM memberNess
WHERE UserName='$UserName'") or die(mysql_error());

$row = mysql_fetch_array($result);

if ($row['UserName'] == $UserName && $row['Password'] == $Password)
{
session_start();
$_SESSION["LoginCookie"] = "Session Is Set";
echo "Welcome, your are now logged in";
} else {
print "An error has occured";
}

?>
[/php]

Test this with:

[php]
<?php
echo ((isset($_SESSION)?"The session is set!":"Awwh fuck.");
?>
[/php]
__________________


Last edited by tempest; Jan 26th, 2005 at 4:46 PM.
tempest is offline   Reply With Quote
Old Jan 26th, 2005, 5:03 PM   #6
TCStyle
Programmer
 
Join Date: Jan 2005
Location: Albany, NY
Posts: 43
Rep Power: 0 TCStyle is on a distinguished road
Hmm

Thanks alot for your help, I'm absolutely stuck now. I tried viewing it in Mozilla fire foz, IE6, I also checked it out on my linux machine... still not working. What makes me wonder even more is the fact that my other isset function on another page of my site works and detects the cookie, but this one, with the same syntax but different contact doesnt?? It might have something to do with xampp... anyway, thanks again for your help, and if anyone else has anys suggestions I'd apperciate it.

EDIT::: Sessions work! Thanks!
TCStyle is offline   Reply With Quote
Old Jan 26th, 2005, 5:29 PM   #7
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
Yeah, Sessions are more secure as well. i have some code that you might be interested in located at:

http://programmingforums.org/forum/s...ead.php?t=1385

it uses postgres though and a class that i made for postgres, but it will secure your site just like apache does if you add the code to each page.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Jan 26th, 2005, 5:48 PM   #8
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Nice class, pizentos.
__________________

tempest is offline   Reply With Quote
Old Jan 27th, 2005, 10:30 AM   #9
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
Thanks. I use it all the time. When i have the time i am also going to add encryption to it, so people can't sniff the usernames and passwords.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:45 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC