Jump to content

Recommended Posts

Okay, so im making a simple login system, and im using cookies. When I was just testing, my login.php was just setting a cookie, with the value of 123, but with my login system, each user has their own unique key, and then data is checked against that in the lookup. It worked in testing the cookie, and my main page recognized it had been set, but now in my login page, it doens't. I had trouble with headers, and so the ob_start() is in db.php (an include, at the bottom of that page)

 

Previous, I didn't buffer it, but now i have to. So, this is my problem - it shows no errors, but seems to not set the cookie.

 

My login code:

<?
include 'db.php';
?>
<html><title>Space Battle :: Login</title>
<body bgcolor="black" text="#fff">
<h3>Login</h3><br>
<?
if (!isset($_POST['user'])){
?>
<table width="500"><form action="" method="post">
<tr><td width="130">
Username:<br>
Password:
</td><td width="300">
<input type="text" maxlength="50" name="user"><br>
<input type="password" maxlength="50" name="pass">
</td></tr></table>
<br>
<input type="submit" value="Go!"></form>
<?
}else{
$name = htmlentities($_POST['user']);
$pass = md5($_POST['pass']);
$result = mysql_query("SELECT * FROM `Players` WHERE `name` = '$name' AND `password` = '$pass'");
$num = mysql_num_rows($result);
if ($num == 1){
$row = mysql_fetch_array($result);
$key = $row['s_key'];
setcookie("login", $key, time()+(60*60*24*365));
ob_end_flush();
}else{
$fail = "<br><b><i><font color=\"red\">FISSION MAILED: Try Again</font></i></b>";
}
if (isset($fail)){
echo $fail;
}else{
echo "<br>Login Successful. Redirecting now.";
?>
<meta http-equiv="REFRESH" content="2;url=index.php"></HEAD>
<?
}
}
?>

 

???

 

 

Ps, i know its not indented, im using a web editor. Sorry.

 

Link to comment
https://forums.phpfreaks.com/topic/104753-solved-cookies-and-such/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.