Forum Moderators: coopster

Message Too Old, No Replies

unexpected T STRING

Slight problem

         

Stimulus

3:13 pm on Jan 13, 2009 (gmt 0)

10+ Year Member



Hi there all.
Im having a slight problem with an un expected T_STRING
it looks a bit like this
Parse error: parse error, unexpected T_STRING on line 72

72. setcookie(string username[string = $_COOKIE['$username']]);
73. setcookie(string password[string = $_COOKIE['$password']]);

surrealillusions

3:25 pm on Jan 13, 2009 (gmt 0)

10+ Year Member



Welcome to WebmasterWorld!

sometimes the error isnt always on that line it says. Look before that line to see if theres anything that may cause the script to say theres an error on that line.

You may of missed a ; or a ' on the previous line or something more complicated like an opening bracket a few lines before may not be closed in the right place or not at all.

:)

Stimulus

3:50 pm on Jan 13, 2009 (gmt 0)

10+ Year Member



$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['$username'], $hour);
setcookie(Key_my_site, $_POST['$pass'], $hour);

setcookie(string username[string = $_COOKIE['$username']]);
setcookie(string password[string = $_COOKIE['$password']]);

had a lookbut couldnt spot anything

surrealillusions

6:22 pm on Jan 13, 2009 (gmt 0)

10+ Year Member



Actually...your set cookie lines (72 and 73) dont look right. Although ive not dealt with cookies enough to know enough about them.

Have a look through php.net's guide to setting cookies.

[uk3.php.net...]

cameraman

8:09 pm on Jan 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World, Stimulus.

Well, the error is because of the 'string' and 'string =' parts, and you're only supplying one parameter - the name of the cookie (which won't cause an error but isn't likely to be what you're expecting). I assume you're following the function prototype - that's just telling you what sort of data to supply to the function. It's telling you, for example, that this is correct:
setcookie("cookiename","cookievalue");
because the parameters need to be strings, as opposed to:
setcookie(37, 16.4);
which is incorrect because those are numbers.

However, I'm not understanding what you're trying to accomplish. If my user name is joebob, it looks like you're trying to set a cookie named joebob that has a value that you're getting from a cookie named joebob. Are you trying to renew a cookie for another hour? If so, how about:

setcookie($_COOKIE[$username],$_COOKIE[$username],$hour));

That's assuming you've assigned the variable $username previously. Or if you're trying to set it from the posted user name value, change the second parameter above to $_POST['username']

Also, it's not a good idea to save a password in a cookie.