Current location: Hot Scripts Forums » Programming Languages » PHP » Cookie problem


Cookie problem

Reply
  #1 (permalink)  
Old 06-13-05, 02:46 PM
Tempestshade Tempestshade is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Cookie problem

I have

setcookie("user", $user, time() + 7200);
setcookie("pass", $rpass, time() + 7200);

to save my cookie and

$user = $_COOKIE['user'];
$pass = $_COOKIE['pass'];

to call my cookie. But when i call my cookie. The cookie = nothing
__________________
http://www.cashbackhosting.net - Cashback Hosting. Cheap Web Hosting starting at $1.50
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-13-05, 03:54 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
check your browser settings, code looks ok...
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-13-05, 06:51 PM
Tempestshade Tempestshade is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
i don't think its that. Another error i noticed was
Warning: Cannot modify header information - headers already sent by (output started at /home/tempest/public_html/chat/index.php:17) in /home/tempest/public_html/chat/index.php on line 36

Warning: Cannot modify header information - headers already sent by (output started at /home/tempest/public_html/chat/index.php:17) in /home/tempest/public_html/chat/index.php on line 37

Code:
<html>
<head>
<title>Tempest's Chat</title>
</head>
<body>
<CenteR>
<form action=index.php?action=login method=post>
Username:<input type=text name=username>
<br>
Password:<input type=password name=password>
<br>
<input type=submit value=Login>
</form>
<Br>
<a href="register.php">Register</a>
</center>
<?php
extract($_GET);
extract($_POST);
$action = $_GET['action'];
$user = $_POST['username'];
$pass = $_POST['password'];
$rpass = md5($pass);

mysql_connect("localhost", "", "")or 
die(mysql_error()); 
mysql_select_db();

$uo1 = mysql_query("SELECT COUNT(name) FROM user where online='1'");
$uo = mysql_result($uo1,0);
print "<Center>There are $uo people online</centeR>";

If ($action == "login") {
$data = mysql_fetch_assoc(mysql_query("SELECT name, pass, room FROM user WHERE name = '$user'"));
If ($rpass == "$data[pass]") {
setcookie("user", $user, time() + 7200);
setcookie("pass", $rpass, time() + 7200);
mysql_query("update user set online='1' where name='$user'");
print "
<head><META HTTP-EQUIV=\"Refresh\"
CONTENT=\"0; URL=main.php\"> </head>";
} else {
print "<center><b>Wrong password</b></center>";
}

}
?>
Thats all code


EDIT

No it doesn't work for anyone. Not just me
__________________
http://www.cashbackhosting.net - Cashback Hosting. Cheap Web Hosting starting at $1.50
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 06-13-05, 07:00 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
ah thats different

php doesnt like it if you use a switch or any GET function to process a page, so things like redirecting and setting cookies wont work! u have to create a seperate file for the user to login to so that you can get rid of the 'If ($action == "login") {' statement!
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 06-14-05, 06:31 AM
Tempestshade Tempestshade is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
lol ive already tried that.
__________________
http://www.cashbackhosting.net - Cashback Hosting. Cheap Web Hosting starting at $1.50
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 06-14-05, 06:37 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
index.php:

Code:
<html>
<head>
<title>Tempest's Chat</title>
</head>
<body>
<center>
<form action="login.php" method="post">
Username:<input type="text" name="username">
<br>
Password:<input type="password" name="password">
<br>
<input type="submit" value="Login">
</form>
<br>
<a href="register.php">Register</a>
</center>
</body>
</html>
login.php:

PHP Code:

<?php

extract
($_GET);
extract($_POST);
$action $_GET['action'];
$user $_POST['username'];
$pass $_POST['password'];
$rpass md5($pass);

mysql_connect("localhost""""")or 
die(
mysql_error()); 
mysql_select_db();

$uo1 mysql_query("SELECT COUNT(name) FROM user where online='1'");
$uo mysql_result($uo1,0);
print 
"<Center>There are $uo people online</centeR>";

$data mysql_fetch_assoc(mysql_query("SELECT name, pass, room FROM user WHERE name = '$user'"));
If (
$rpass == "$data[pass]") {
setcookie("user"$usertime() + 7200);
setcookie("pass"$rpasstime() + 7200);
mysql_query("update user set online='1' where name='$user'");
header ("Location: main.php");
} else {
print 
"<center><b>Wrong password</b></center>";
}

?>
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting a cooke (time it expires) mcrob PHP 4 04-27-05 01:13 PM
Passing info between pages w/ URL HairySpider JavaScript 6 01-09-05 09:47 AM
Count problem kasic ASP.NET 1 10-20-04 01:23 AM
Asp and Microsoft Access 2002 problem gop373 ASP 2 10-06-04 10:13 AM
cookie problem darkcarnival PHP 11 12-27-03 07:17 PM


All times are GMT -5. The time now is 09:09 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.