and.hunt Posted June 5, 2006 Share Posted June 5, 2006 I am trying to use cookies in my site: <?phpif (isset($_COOKIE["language_english"]))echo "<?php require("./english/menu.php"); ?>" . $_COOKIE["language_english"] . "<br />";if (isset($_COOKIE["language_german"]))echo "<?php require("./german/menu.php"); ?>";else"";?> When I try to load the page i get an error:Parse error: syntax error, unexpected '/' in /usr/export/www/vhosts/funnetwork/hosting/andrewjrvhunt/page/index.php on line 23(page: http://andrewjrvhunt.an.funpic.de/page/index.php). When I remove the <?php require("./english/menu.php"); ?> part out the page works. How can I get this to work properly? Link to comment Share on other sites More sharing options...
Jack McKalling Posted June 5, 2006 Share Posted June 5, 2006 (edited) Are you sure the path is correct?[*Edit:] I oversaw the echoed php tags, that is whats wrong Skym is right Edited June 5, 2006 by Dan The Prof Link to comment Share on other sites More sharing options...
skym Posted June 5, 2006 Share Posted June 5, 2006 There is a syntax error...echo "<?php require("./english/menu.php"); ?>" ?! <?phpif (isset($_COOKIE["language_english"])) {require("./english/menu.php");echo $_COOKIE["language_english"] . "<br />";}if (isset($_COOKIE["language_german"]))require("./german/menu.php");elseecho "";?> Link to comment Share on other sites More sharing options...
and.hunt Posted June 5, 2006 Author Share Posted June 5, 2006 Thanks, it works now. Also, is there a good guide to cookies anywhere? Link to comment Share on other sites More sharing options...
aspnetguy Posted June 5, 2006 Share Posted June 5, 2006 try this one http://www.w3schools.com/php/php_cookies.asp Link to comment Share on other sites More sharing options...
and.hunt Posted June 5, 2006 Author Share Posted June 5, 2006 I'd like a more detailed one, that is the first one i tried. ANd i have another problem, i try to get a cookie to be made, but none is made (I use FF, whenever a cookie is to be set I get a message, but in this case i don't.): <?php setcookie("language_english", $name, time()+36000);?> (i have it right at the start of the document, before the opening html tag) Link to comment Share on other sites More sharing options...
aspnetguy Posted June 5, 2006 Share Posted June 5, 2006 I'd like a more detailed one, that is the first one i tried. ANd i have another problem, i try to get a cookie to be made, but none is made (I use FF, whenever a cookie is to be set I get a message, but in this case i don't.):<?php setcookie("language_english", $name, time()+36000);?> (i have it right at the start of the document, before the opening html tag) <{POST_SNAPBACK}> Can you post the full code...it will help us debug. Link to comment Share on other sites More sharing options...
and.hunt Posted June 5, 2006 Author Share Posted June 5, 2006 It's okay now, i've realised what ive been doing wrong. But is it possible to dothis: <?phpif (isset($_COOKIE["language_english"])) {require("./english/menu.php");echo $_COOKIE["language_english"] . "<br />";}if (isset($_COOKIE["language_german"]))require("./german/menu.php");elseecho "";?> But instead of having two cookies, have it set up that the first option displays if ther's a cookie called language, with value english, and the other one when the cookies value is german? Link to comment Share on other sites More sharing options...
skym Posted June 5, 2006 Share Posted June 5, 2006 Yes, and if the folders are named just like the cookie values, then you can shorten your code: <?phpif (isset($_COOKIE["language"])) {require("./" . $_COOKIE["language"] . "/menu.php");echo $_COOKIE["language"] . "<br />";}?> Link to comment Share on other sites More sharing options...
justsomeguy Posted June 5, 2006 Share Posted June 5, 2006 There's a lot of good information about cookies at php.net here:http://www.php.net/manual/en/function.setcookie.phpMake sure you read the comments too. Link to comment Share on other sites More sharing options...
and.hunt Posted June 5, 2006 Author Share Posted June 5, 2006 Many thanks. Now I can continue building my page. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now