![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jan 2005
Location: Albany, NY
Posts: 43
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() |
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! |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Jan 2005
Location: Albany, NY
Posts: 43
Rep Power: 0
![]() |
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"; } |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() |
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. |
|
|
|
|
|
#5 |
|
Programming Guru
![]() |
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. |
|
|
|
|
|
#6 |
|
Programmer
Join Date: Jan 2005
Location: Albany, NY
Posts: 43
Rep Power: 0
![]() |
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! |
|
|
|
|
|
#7 |
|
Programming Guru
![]() ![]() |
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! |
|
|
|
|
|
#8 |
|
Programming Guru
![]() |
Nice class, pizentos.
__________________
|
|
|
|
|
|
#9 |
|
Programming Guru
![]() ![]() |
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! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|