This is a discussion on Cookies are now driving me crazy.... within the PHP General forums, part of the PHP Programming Forums category; I have some code which I'll paste at the end of the e-mail that is throwing an error ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have some code which I'll paste at the end of the e-mail that is
throwing an error and I can't seem to find where the error is... Here is the error: "[Wed Nov 28 15:03:19 2007] [error] PHP Parse error: syntax error, unexpected '{' in /Volumes/RAIDer/webserver/Documents/ OLDB/customer/test/detectuser.php on line 27" Now... I realize that it's not expecting a '{' on line 27... But I checked the brackets, and from what I can tell, they all look balanced...Any help is appreciated! <?php include('defaults.php'); include('dbconnect.php'); //see if detectuser.php has been required, not URL’d. if ($legal_require_php!=1234) exit; // setup global variable $global_user_id, set it to 0, which means no user as auto_increment IDs in MySQL begin with 1 $global_user_id= 0; // now, check if user’s computer has the cookie set if (isset($_COOKIE['cookiename'])) { $cookieval= $_COOKIE['cookiename']; //now parse the ID:LOGCODE value in cooke via explode() function $cookieparsed= explode (":", $cookieval); // $cookie_uid will hold user’s id // $cookie_code will hold user’s last reported logcode $cookie_uid= $cookieparsed[0]; $cookie_code= $cookieparsed[1]; // ensure that ID from cookie is a numeric value if (is_numeric($cookie_uid)) { //now, find the user via his ID $res= mysql_query("SELECT logcode FROM MainLogin WHERE id=$cookie_uid"); // no die() this time, we will redirect if error occurs if ($res) { // now see if user’s id exists in database if (mysql_num_rows($res,0) { $logcode_in_base= mysql_result($res, 0); // now compare LOGCODES in cookie against the one in database if ($logcode_in_base == $cookie_code) { // if valid, generate new logcode and update database $newcode= md5(func_generate_string()); $res= mysql_query("UPDATE MainLogin SET logcode='$newcode' WHERE id=$cookie_uid"); // setup new cookie (replace the old one) $newval= "$cookie_uid:$newcode"; setcookie("cookiename", $newval, time() + 300, "/oldb/", ".raoset.com"); // finally, setup global var to reflect user’s id $global_user_id= $cookie_uid; } else { // redirect if logcodes are not equal echo "Logcodes are not equal"; } } else { // redirect if user ID does not exist in database echo "User not in database"; } } else { // redirect in case of database error echo "database error"; } } else { // redirect if user ID in cookie not numeric echo "Cookie not numeric"; } } ?> -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424 www.raoset.com japruim@raoset.com |
|
|||
|
On Nov 28, 2007 12:08 PM, Jason Pruim <japruim@raoset.com> wrote:
> if ($res) { > // now see if user's id exists in database > if (mysql_num_rows($res,0) { You need another ) on that last line: if (mysql_num_rows($res,0)) { You might want to consider getting an editor/ide that will higlight parse errors for you, makes life much easier. :) My ide of choice is EasyEclipse for PHP ( http://www.easyeclipse.org/site/distributions/php.html ), and there are lots of other great editors out there too. This is not meant to start another "my editor is better than yours" thread, just a suggestion. Brady |
|
|||
|
On Nov 28, 2007 3:08 PM, Jason Pruim <japruim@raoset.com> wrote:
> I have some code which I'll paste at the end of the e-mail that is > throwing an error and I can't seem to find where the error is... Here > is the error: "[Wed Nov 28 15:03:19 2007] [error] PHP Parse error: > syntax error, unexpected '{' in /Volumes/RAIDer/webserver/Documents/ > OLDB/customer/test/detectuser.php on line 27" > > Now... I realize that it's not expecting a '{' on line 27... But I > checked the brackets, and from what I can tell, they all look > balanced...Any help is appreciated! > > > > <?php > include('defaults.php'); > include('dbconnect.php'); > //see if detectuser.php has been required, not URL'd. > if ($legal_require_php!=1234) exit; > // setup global variable $global_user_id, set it to 0, which means > no user as auto_increment IDs in MySQL begin with 1 > $global_user_id= 0; > // now, check if user's computer has the cookie set > if (isset($_COOKIE['cookiename'])) { > $cookieval= $_COOKIE['cookiename']; > //now parse the ID:LOGCODE value in cooke via explode() function > $cookieparsed= explode (":", $cookieval); > // $cookie_uid will hold user's id > // $cookie_code will hold user's last reported logcode > $cookie_uid= $cookieparsed[0]; > $cookie_code= $cookieparsed[1]; > // ensure that ID from cookie is a numeric value > if (is_numeric($cookie_uid)) { > //now, find the user via his ID > $res= mysql_query("SELECT logcode FROM MainLogin WHERE id=$cookie_uid"); > // no die() this time, we will redirect if error occurs > if ($res) { > // now see if user's id exists in database > if (mysql_num_rows($res,0) { > $logcode_in_base= mysql_result($res, 0); > // now compare LOGCODES in cookie against the one in database > if ($logcode_in_base == $cookie_code) { > // if valid, generate new logcode and update database > $newcode= md5(func_generate_string()); > $res= mysql_query("UPDATE MainLogin SET logcode='$newcode' WHERE > id=$cookie_uid"); > // setup new cookie (replace the old one) > $newval= "$cookie_uid:$newcode"; > setcookie("cookiename", $newval, time() + 300, "/oldb/", > ".raoset.com"); > // finally, setup global var to reflect user's id > $global_user_id= $cookie_uid; > } else { > // redirect if logcodes are not equal > echo "Logcodes are not equal"; > } > } else { > // redirect if user ID does not exist in database > echo "User not in database"; > } > } else { > // redirect in case of database error > echo "database error"; > } > } else { > // redirect if user ID in cookie not numeric > echo "Cookie not numeric"; > } > } > ?> > -- > > Jason Pruim > Raoset Inc. > Technology Manager > MQC Specialist > 3251 132nd ave > Holland, MI, 49424 > www.raoset.com > japruim@raoset.com > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Jason, That generally means you forgot to close out a closing param. However, I ran your code just fine. Is the name of that script `detectuser.php` or is that somehow else included? -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107 If at first you don't succeed, stick to what you know best so that you can make enough money to pay someone else to do it for you. |
|
|||
|
On Nov 28, 2007 3:19 PM, Brady Mitchell <mydarb@gmail.com> wrote:
> On Nov 28, 2007 12:08 PM, Jason Pruim <japruim@raoset.com> wrote: > > if ($res) { > > // now see if user's id exists in database > > if (mysql_num_rows($res,0) { > You need another ) on that last line: > > if (mysql_num_rows($res,0)) { > > You might want to consider getting an editor/ide that will higlight > parse errors for you, makes life much easier. :) > > My ide of choice is EasyEclipse for PHP ( > http://www.easyeclipse.org/site/distributions/php.html ), and there > are lots of other great editors out there too. This is not meant to > start another "my editor is better than yours" thread, just a > suggestion. > > Brady > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Should go without saying that I noticed the problem immediately after I sent the message before. I had commented out the MySQL stuff and the function call to get it to run without kicking out errors on there. My goof. -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107 If at first you don't succeed, stick to what you know best so that you can make enough money to pay someone else to do it for you. |
|
|||
|
On Nov 28, 2007, at 3:19 PM, Brady Mitchell wrote: > On Nov 28, 2007 12:08 PM, Jason Pruim <japruim@raoset.com> wrote: >> if ($res) { >> // now see if user's id exists in database >> if (mysql_num_rows($res,0) { > You need another ) on that last line: > > if (mysql_num_rows($res,0)) { > > You might want to consider getting an editor/ide that will higlight > parse errors for you, makes life much easier. :) > > My ide of choice is EasyEclipse for PHP ( > http://www.easyeclipse.org/site/distributions/php.html ), and there > are lots of other great editors out there too. This is not meant to > start another "my editor is better than yours" thread, just a > suggestion. Thanks for spotting it! I think I may need something other then dreamweaver to code in... All I use it for is it's syntax highlighting... I do all my coding by hand... But I think I'll start looking at others :) Off to google! :) -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424 www.raoset.com japruim@raoset.com |