Cookie Help (the one below didn't help)

Status
Not open for further replies.

jasgor9

New Member
Messages
40
Reaction score
0
Points
0
I have a login page, which sends 2 variables (via POST) named username and password. The password is md5-ed, because the password in the MySQL Database is stored under MD5 encryption. The browser is sent to this page, which processes the form. If the user enters correct information (username and password), i want it to delete the cookie "telc" if it is there, and then set the cookie "telc", with the value being the entered username, for an hour (time()+3600). It processes the form when ran. If the username or password is wrong, it does go to wrong.php?err=Password, and if the info is correct, it goes to membersOnly/index.php. When i try to load the cookie from the members page (membersOnly/index.php), it is blank. I looked at post not too long ago about cookies but it didn't help.

Form Processing Page:
PHP:
$username = $_POST['username'];
$password1 = $_POST['password'];
$password = md5($password1);

mysql_connect("localhost", "mysql-username", "mysql-password");
mysql_select_db("mysql-database");

$chk = mysql_query("SELECT * FROM memberdatatable WHERE Username = '$username'");

$memArray = mysql_fetch_array($chk);

if($password==$memArray['Password']) {
setcookie("telc","",1);
setcookie("telc",$username,time()+3600);
include("http://members.telvior.com/membersOnly/index.php");
}
else
{
header("Location: wrong.php?err=Password");
}

Members Area:
PHP:
print $_COOKIE['telc'];
^^^ That, on the member's page, is where it says 'hello, ___', so the code for that is: Hello, <?php print $_COOKIE['telc']; ?>

Here is the url to the problem: http://members.telvior.com/login
(the username is 'test' and the password is 'test')
 

jasgor9

New Member
Messages
40
Reaction score
0
Points
0
Sorry to repost, but i have already tried that and it didn't work.
 

VPmase

New Member
Messages
914
Reaction score
0
Points
0
You should use sessions as well as cookies.

PHP:
<?
	session_start();
	$ip = $_SERVER['REMOTE_ADDR'];
	$_SESSION[$ip] = 1;
	setcookie('test', $ip);#, time()+86400
	function checkOnlineStatus($uip){
		if (isset($_SESSION[$uip]){
			return $_SESSION[$uip];
		} else {
			return 'not logged it';
		}
	}
	$user = checkOnlineStatus[$ip];
?>

<html>
<body>
<?=$_SESSION[$ip]?>
<?=$_COOKIE['test']?>
</body>
</html>
That is a very basic script.
 
Last edited:
Status
Not open for further replies.
Top