Jump to content

[SOLVED] darn setcookie() wont work..


clown[NOR]

Recommended Posts

I'm tearing every single hear off my head now... i just cant get this set cookie to work... does anyone have any clue why it wont work?

both $tmpUser & $tmpPass contains value...have double checked that...

 

<?php

	include('config/db.php');
	$tmpUser = trim($_POST['username']);
	$tmpPass = trim($_POST['password']);
	setcookie("username", $tmpUser, time()+24*3600*12);
	if (!mysql_connect($dbHost, $dbUser, $dbPass)) { die("Unable to connect to DB"); }
	if (!mysql_select_db($dbName)) { die("Unable to select to DB"); }

	$query = "SELECT * FROM users WHERE username = '" . mysql_real_escape_string($tmpUser) . "'";
	$result = mysql_query($query);
	if (!$result) { die("Could not run query from DB"); }

	while ($dbField = mysql_fetch_assoc($result)) {
		$chkPass = $dbField['password'];
	}
	if ($tmpPass != $chkPass) {
		echo "Wrong password";
		#header("Location: index.php");
		#exit;
	} else {
		echo "You have been signed in as: ".$_COOKIE['username'];
		#$query = "UPDATE users SET status = 'ONLINE' WHERE username = '" . mysql_real_escape_string($_COOKIE['username']) . "' AND status = 'OFFLINE'";
		#if (!mysql_query($query)) { die("Could not run query from DB"); }

		#header("Location: index.php");
	}

?>

Link to comment
Share on other sites

um, its prolly setting but you cant veiw cookie contents on the page that its set, ie, refresh and itll work

 

also, its header information, so your database connection isoutput, thats prolly why

 

um, i think i use itm but am not sure

 

look at output buffereing, start_ob(), fluch_ob ()

 

um, searhc some of my previously "cookies" or "lgin system" sort of stuff started by me

theres a nice explaination there

 

gdlk

Link to comment
Share on other sites

i figured it out... it must have been something about the setcookie .. what I did was:

i changed this line:

"UPDATE users SET status = 'ONLINE' WHERE username = '" . mysql_real_escape_string($_COOKIE['username']) . "' AND status = 'OFFLINE'";

 

to this

"UPDATE users SET status = 'ONLINE' WHERE username = '" . mysql_real_escape_string($tmpUser) . "' AND status = 'OFFLINE'";

 

i posted the solution to... incase somebody else is facing the same issue....

Link to comment
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.