Page 1 of 1

Setting cookie and refreshing.

Posted: Mon Jan 16, 2012 4:55 am
by Rob_Scott
Hi,

I am trying to set a language cookie.

I have a row of different flags which all have values and set a language cookie.

However i can only redirect to the homepage, and i just want to refresh the current page.

Here is my php script......

<?php
setcookie("lang", urlencode($_GET["lang"]));
$url = "http://www.bertgroup.co.uk/?q=node/16";
header( "Location: $url" );
?>

And the html i am using to link to the script.......

<a class="no_underline" href="setlang.php?lang=EN"><img class="header_language_flags" src="images/flag_EN.jpg" value="EN"/>

<a class="no_underline" href="setlang.php?lang=FR"><img class="header_language_flags" src="images/flag_FR.jpg" value="FR">

Thanks,

Rob

Re: Setting cookie and refreshing.

Posted: Wed Jan 18, 2012 7:39 am
by theserve
You could possibly use the $_SERVER['HTTP_REFERRER'] value to redirect back to the page they came from.

Code: Select all

<?php
setcookie("lang", urlencode($_GET["lang"]));
$url = $_SERVER['HTTP_REFERRER'];
header( "Location: $url" );
?>

Re: Setting cookie and refreshing.

Posted: Thu Jan 19, 2012 4:36 am
by Rob_Scott
Thanks for the reply, I have used your piece of code and it just wants to refresh to www.bertgroup.co.uk/setlang.php?lang=EN,

Any ideas how to get around this?

Thanks.

Rob

Re: Setting cookie and refreshing.

Posted: Thu Jan 19, 2012 9:10 am
by theserve
Why don't you just include the code at the top of every page using a common file and catch a setlang variable. Then you can just make the link open the page you are on.

Code: Select all

if(!empty($_GET['setlang']))
{
setcookie("lang", urlencode($_GET["lang"]));
}