dlyles Posted November 30, 2006 Share Posted November 30, 2006 I've searched the site and saw plenty of things on cookies, but I'm still getting something wrong. I'm getting the following errorParse error: syntax error, unexpected T_STRING in /var/opt/data/rgbdata/apache/htdocs/checklogin.php on line 26from this:[code]setcookie('".$_POST['myusername']."',$myusername);[/code] Link to comment https://forums.phpfreaks.com/topic/29007-cookies/ Share on other sites More sharing options...
Psycho Posted November 30, 2006 Share Posted November 30, 2006 Why the two sets of quotes? Just do this:[code]setcookie($_POST['myusername'],$myusername);[/code] Link to comment https://forums.phpfreaks.com/topic/29007-cookies/#findComment-132886 Share on other sites More sharing options...
taith Posted November 30, 2006 Share Posted November 30, 2006 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 monthssetcookie($_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 https://forums.phpfreaks.com/topic/29007-cookies/#findComment-132888 Share on other sites More sharing options...
dlyles Posted November 30, 2006 Author Share Posted November 30, 2006 Thanks. I used[code]setcookie($_POST['myusername'],$myusername,$time);[/code]and got the same errorWarning: 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 https://forums.phpfreaks.com/topic/29007-cookies/#findComment-132898 Share on other sites More sharing options...
taith Posted November 30, 2006 Share Posted November 30, 2006 aah... you have to put that BEFORE anything is outputed (echo/print)... Link to comment https://forums.phpfreaks.com/topic/29007-cookies/#findComment-132903 Share on other sites More sharing options...
dlyles Posted November 30, 2006 Author Share Posted November 30, 2006 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 monthssetcookie($_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 https://forums.phpfreaks.com/topic/29007-cookies/#findComment-132913 Share on other sites More sharing options...
taith Posted November 30, 2006 Share Posted November 30, 2006 ok... and whats on line 27 of checklogin.php? Link to comment https://forums.phpfreaks.com/topic/29007-cookies/#findComment-132934 Share on other sites More sharing options...
dlyles Posted December 1, 2006 Author Share Posted December 1, 2006 I fixed it. I had to remove whitespaces, etdc. Link to comment https://forums.phpfreaks.com/topic/29007-cookies/#findComment-133513 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.