Search
Left Quote    Black holes are where God divided by zero.
- Steven Wright    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: hmm? cookies
  This user is offline  ki
  Subject: "hmm? cookies" Posted: @ 7:18 pm on Dec 02 2006   

Member #: 204
Rank: User - (50)
Since: 09/16/06
Posts: 53
From: Florida

I was just wonderins, ive been using the cookie system used for this member login same exact one and some reason when i go here, im auto logged in and when i got to my site i have to login even when I dont close my browser, mine only lasts for a session time and the cookie never works for mine, any suggestions?


woohoo!
    Viewed: 18,361 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: hmm? cookies" Posted: @ 2:44 am on Dec 05 2006    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

make sure the cookie is being set in your login code would be 1st step




-bs0d | AllSyntax.com

    Viewed: 18,335 Times | Reply to This | To top
  This user is offline  ki
  Subject: "re: hmm? cookies" Posted: @ 3:31 am on Dec 05 2006    

Member #: 204
Rank: User - (50)
Since: 09/16/06
Posts: 53
From: Florida

it does. I use

Code:

$joined =''.$_POST[' username'].'[ ]'.md5($_POST[ 'password']). '';
setcookie('log in_cookie', $joined, 2147483647, '/', '.www.tragical .net');
< br>

it works fine




woohoo!

    Viewed: 18,330 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: hmm? cookies" Posted: @ 12:53 pm on Dec 05 2006    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

How do you know it set the cookie? Test it by something like,

if(isset($_COOK IE['login_cook ie'])) {
echo('cookie WAS set');
} else {
echo('cookie NOT set');
}



Edited at 12:58:53 pm on 12/05/06


-bs0d | AllSyntax.com

    Viewed: 18,319 Times | Reply to This | To top
  This user is offline  ki
  Subject: "re: hmm? cookies" Posted: @ 8:19 pm on Dec 05 2006    

Member #: 204
Rank: User - (50)
Since: 09/16/06
Posts: 53
From: Florida

ok I tested it it like this

Code:

<?
if($_GET['p'] == "test&qu ot {
if(isset($_COOK IE['login_cook ie'])) {
echo('cookie WAS set');
} else {
echo('cookie NOT set');
}

}
if($_GET['p'] == "set&quo t {
$joined = "ki[]&qu ot;.md5('passw ord');
setcookie('log in_cookie', $joined, 2147483647, '/', 'www.tragical. net');
}
if($_GET['p'] == "del&quo t {
setcookie('log in_cookie', "", time()-21474836 47, '/', 'www.tragical. net');
}
?>



ok I didnt even set it at first then I got cookie WAS set, then I delete it, then I try it again, I get the same thing. so whats up?




woohoo!

    Viewed: 18,305 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: hmm? cookies" Posted: @ 4:07 am on Dec 06 2006    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

You might need to refresh after the cookie is set? The cookie is set in login.php, then header() redirects to the home page. In your page_header code of home page check if cookie was set.

also explore php.net/setcoo kie and read through that a bit and through the comments. I have it setup exactly as the tutorial is, and it seems to work for everyone.

Also consider re-examining your page_header code and login code to make sure nothing was left out and that the variables match up to ones you use.




-bs0d | AllSyntax.com

    Viewed: 18,294 Times | Reply to This | To top
  This user is offline  ki
  Subject: "re: hmm? cookies" Posted: @ 6:19 pm on Dec 06 2006    

Member #: 204
Rank: User - (50)
Since: 09/16/06
Posts: 53
From: Florida

some reason this stuff still isn't working




woohoo!

    Viewed: 18,276 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: hmm? cookies" Posted: @ 6:59 pm on Dec 06 2006    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

post in seperate code boxes your page header code and your login code




-bs0d | AllSyntax.com

    Viewed: 18,272 Times | Reply to This | To top
  This user is offline  ki
  Subject: "re: hmm? cookies" Posted: @ 9:44 pm on Dec 06 2006    

Member #: 204
Rank: User - (50)
Since: 09/16/06
Posts: 53
From: Florida

header

Code:

date_default_t imezone_set('E ST');
require_once(' config.php');< br /> session_start( );
if ($_SESSION['lo gged_in'] != 1 && isset($_COOKIE[ 'login_cookie '])) {
list($user, $pass) = explode('[]', $_COOKIE['trag ical_cookie']) ;
$qu = mysql_query(&q uot;SELECT `user_password` FROM `members` WHERE `username` = '".addsl ashes($user).& quot;'";
if (mysql_num_rows ($qu) == 1) {
$passw = mysql_fetch_obj ect($qu);
if ($passw->use r_password == $pass) {
$_SESSION['log ged_in'] = 1;
$_SESSION['use rname'] = $user;
$_SESSION['pas sword'] = $pass;
}
}
}
if(!isset($_SES SION['username ']) && !isset($_SESSIO N['password'] )) {
$_SESSION['log ged_in'] = 0;
$user = "Guest&q uot;;
}



login

Code:
if(isset($_SES SION['username ']) && isset($_SESSION ['password']) ) {
header("L ocation: ?page=";
}

if(isset($_POST ['submit'])) {

if(!$_POST['us ername']) die("Erro r: You must enter your username before logging in.";
if(!$_POST['pa ssword']) die("Erro r: You must enter your password before logging in.";

if(!empty($_POS T['stay_in']) ) {
$joined =''.$_POST[' username'].'[ ]'.md5($_POST[ 'password']). '';
setcookie('log in_cookie', $joined, 2147483647, '/', '.www.tragical .net');

} //end if
//2147483647
//verify user...
$get_user = mysql_query(&q uot;SELECT * FROM `members` WHERE username = '".$_POS T['username'] ."' AND

user_password = '".md5($ _POST['passwor d'])."' ";
$q = mysql_fetch_obj ect($get_user);
if(!$q) die("Logi n Failure: An error occured, please verify your username and password are correct."< img src=http://www. allsyntax.com/f orums/images/sm ilies/wink.gif border=0>;

//set session variables
$_SESSION['log ged_in'] = 1;
$_SESSION['use rname'] = $_POST['userna me'];
$_SESSION['pas sword'] = $_POST['passwo rd'];
session_write_c lose();

header("L ocation: ?page=usercp&q uot;

} else {




woohoo!

    Viewed: 18,262 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: hmm? cookies" Posted: @ 12:18 am on Dec 07 2006    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

When you store the cookie, you use [] between the username and password. I would change that back to | . So thats an adjustment on line 5 in your page header, and line 11 on login.php. Also on your login.php on line 12 where you set the cookie, take the www out.

I dont know if those changes will make a difference, but right off the top those are variances in your code compaired to the tutorial.




-bs0d | AllSyntax.com

    Viewed: 18,253 Times | Reply to This | To top
  This user is offline  ki
  Subject: "re: hmm? cookies" Posted: @ 1:59 am on Dec 07 2006    

Member #: 204
Rank: User - (50)
Since: 09/16/06
Posts: 53
From: Florida

ah now I got it, the [] is the problem with it all, It turns out that when firefox or any other browser for that matter wont read the same as [] but as the code such as like %59 or something




woohoo!

    Viewed: 18,247 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: hmm? cookies" Posted: @ 2:24 am on Dec 07 2006    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

Cool, so it worked? I was also affraid php may try to interpret [] as an array element or something. We use the | just to seperate username from password so it could be almost anything. | makes sense to me. Hope you got it working.




-bs0d | AllSyntax.com

    Viewed: 18,244 Times | Reply to This | To top
  This user is offline  ki
  Subject: "re: hmm? cookies" Posted: @ 5:37 am on Dec 07 2006    

Member #: 204
Rank: User - (50)
Since: 09/16/06
Posts: 53
From: Florida

  bs0d said...

< i> Cool, so it worked? I was also affraid php may try to interpret [] as an array element or something. We use the | just to seperate username from password so it could be almost anything. | makes sense to me. Hope you got it working.

nvm now its not working lol. it decides to end with the session >:O


/////////////// //////////


Nevermind about that post.

It works, I found out in the frustration of the cookie I renamed one of the cookie explode to see if there was an error, now it works
Thanks.



Edited at 05:39:46 am on 12/07/06


woohoo!

    Viewed: 18,236 Times | Reply to This | To top
  This user is offline  infinity000
  Subject: "re: hmm? cookies" Posted: @ 11:20 am on Feb 19 2007    
Member #: 281
Rank: User - (2)
Since: 02/19/07
Posts: 2

I changed it like this :


Code:

$joined =''.$_POST[' username'].'[ ]'.md5($_POST[ 'password']). '';
setcookie(&quo t;login_cookie ", $joined, 2147483647, "/" .'gm');




Code:
setcookie(&quo t;login_cookie "," ", time() - 60, "/" .'gm');




Edited at 11:28:57 am on 02/19/07


    Viewed: 16,779 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank