[php]cookie's

Skilled Illusionist
Joined
Jan 14, 2005
Messages
395
Reaction score
2
hello,
i making a language option for dutch/english but now i want to remeber it
with cookie i know how to add it but i dont know how to make a option if you have that cookie that it redirect to the page with the value english or dutch
ill post the source to explain

lang.php
PHP:
<form action="lang2.php" method="post">
      <div align="center">
        <p><img src="en.gif" width="63" height="40" /> 
          <label><br />
          <input name="English" type="submit" id="English" value="English" />
          <br />
          </label>
        </p>
      </div>
  <p align="center"><img src="dutch-flag.jpg" width="63" height="40" /><br>
    <input name="Dutch" type="submit" id="Dutch" value="Dutch" />
    </br>
    </p>
      </p>
      </p>
</form>
<p align="center"><strong>Please select your language / Selecteer u taal </strong></p>

lang2.php where the information will be saved
PHP:
<?php if($_POST['Dutch']){                 
setcookie("dutch", "".$_POST['Dutch']."", time()+36000000000);
?>
<html>
<head>
<Title>[NL]welkom op deze website</Title>
</head>
<body>
welkom op de website !
</body>
</html>
<?
} elseif($_POST['English']){
setcookie("english", "".$_POST['English']."", time()+36000000000);
?>
<html>
<head>
<Title>[ENG]welcom to this website</Title>
</head>
<body>
Welcome on the website !
</body>
</html>
<?
} else {
echo "we dont support that !";
} ?>

anyone can help :sq_yellow ?
 
Your form can be easier, example
lang1.php
PHP:
<html>

<head>
  <title>Language Page 2</title>
</head>

<body>

<b>Select your language</b><br>
<form method="POST" action="lang2.php">
  <input type="submit" value="english" name="lang">
  <input type="submit" value="dutch" name="lang">
</form>

</body>

</html>

lang2.php
PHP:
<html>

<head>
  <title>Language Page 2</title>
</head>

<body>

<?php

if (isset($_POST['lang'])) {
	if ($_POST['lang'] == 'english') {
    	echo 'You have selected English';
    } elseif ($_POST['lang'] == 'dutch') {
    	  echo 'You have selected Dutch';
      }
} else {
	  echo 'Please select your language at lang1.php';
  }

?>

</body>

</html>

Then in lang2.php you just have to add cookies function, hope this helps.

I did one about multilingual page long ago,
PHP:
 multilingual page - Computer World Hosting Networks[/url]
 
Back