Jump to content

Cookies


dlyles

Recommended Posts

I've searched the site and saw plenty of things on cookies, but I'm still getting something wrong.  I'm getting the following error

Parse error: syntax error, unexpected T_STRING in /var/opt/data/rgbdata/apache/htdocs/checklogin.php on line 26

from this:
[code]
setcookie('".$_POST['myusername']."',$myusername);
[/code]
Link to comment
Share on other sites

wonderful thing bout variables, once data is set, " ' are no longer necessary... you can use em... but not necessary...
[code]
$time = 60 * 60 * 24 * 60 + time(); #two months
setcookie($_POST['myusername'],$myusername,$time);
setcookie("$_POST['myusername']","$myusername","$time"); #same thing, dont use ' or it'll take the $time as a string, not a variable.
[/code]
Link to comment
Share on other sites

Thanks.  I used

[code]
setcookie($_POST['myusername'],$myusername,$time);
[/code]
and got the same error
Warning: Cannot modify header information - headers already sent by (output started at /var/opt/data/rgbdata/apache/htdocs/checklogin.php:2) in /var/opt/data/rgbdata/apache/htdocs/checklogin.php on line 27
Link to comment
Share on other sites

Yeah, I did, however...

[code]
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);


if($count==1){
// Register $myusername, $mypassword and redirect to file "mainpage.php"
$time = 60 * 60 * 24 * 60 + time(); #two months
setcookie($_POST['myusername'],$myusername,$time);

$_Session["username"]=$_POST['myusername'];
$_Session["password"]=$_POST['mypassword'];
// session_register("myusername");
// session_register("mypassword");
//echo "<meta http-equiv='Refresh' content='0; url=mainpage.php'>";
exit;
//header("location:mainpage.php");
}
else {
echo "Wrong Username or Password";
}
?>
[/code]
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.