Jump to content

Cookies


and.hunt
 Share

Recommended Posts

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

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

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

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)

Can you post the full code...it will help us debug.
Link to comment
Share on other sites

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...