Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-04-2008, 02:58 AM   PM User | #1
crunkbbfe
New Coder

 
Join Date: Jan 2006
Location: California. USA
Posts: 86
Thanks: 1
Thanked 0 Times in 0 Posts
crunkbbfe is an unknown quantity at this point
Setting up a cookie Error

I have the code down below, my error is that when the information is submitted, the cookies are not set. Can anyone see any problem with the script in which it would work?


PHP Code:
<?
$login 
$_POST['login'];
if(isset(
$login)){
$username strip_tags($_POST['username']);
$username strtolower($username);
$username str_replace(" """"$username");
$username str_replace("'""""$username");
$username str_replace("\"""""$username");
$password strip_tags($_POST['password']);
include(
"include/database.php");
$date date("U")-600;
$query mysql_query("SELECT * FROM users WHERE 

username='$username' && password='$password' "
);
if(
mysql_num_rows($query) < 1){
$status "<font color='red'>Invalid Username And/Or Password</font><br 

/>"
;
}else{
setcookie("sesuser",$username);
setcookie("sesid",$date);
$ip $_SERVER['REMOTE_ADDR'];
$datet date("U");
mysql_query("DELETE FROM session WHERE username='$username' ");
$ip $_SERVER['REMOTE_ADDR'];
$date date("U")+3600;
mysql_query("INSERT INTO session VALUES('$username', '$date', '$ip', 

'$password', '$date')"
);
$datee date("F jS Y g:iA");
$datey date("U");
mysql_Query("UPDATE users SET lastlogon='$datee', lastlogo='$datey' 

WHERE username='$username' "
);
$page $_POST['page'];
if(isset(
$page)){
echo 
"<script type=\"text/javascript\">
<!--
window.location = \"$page\"
//-->
</script>"
;
}else{
?>
<script type="text/javascript">
<!--
window.location = "member.php"
//-->
</script>
<?
}}}
include(
"include/logheader.php");
include(
"include/logininfo.php");
?>
__________________
Need a Website?
http://www.webmaking.biz
Free Photo Hosting:
http://www.photophatty.com
crunkbbfe is offline   Reply With Quote
Old 08-04-2008, 03:41 AM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,044
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
Cookies are set within a header.
That means you need to either refresh the page with a new header,
or jump out to another PHP script, set the cookie(s) and jump back.

With the code you provided, I can't really tell what is happening.

But you probably have a form where the user puts in a userid and password?

When that form is submitted, it should jump to a script that verifies the
login and sets a cookie, then goes to another script using:
header ("location: index.php");
... or whatever page it needs to go to. That motion of using header, sets the cookie.

Here's the deal though ....
I question why you're using cookies instead of PHP SESSIONS.
SESSIONS are much more secure.

and another thing .... I think your cookies expire if the browser closes
because you don't specify an expiration date.
mlseim is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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


All times are GMT +1. The time now is 04:14 AM.


Advertisement
Log in to turn off these ads.