Jump to content

[SOLVED] Cookie + session


web_master

Recommended Posts

Hi,

 

Ive got a cookie for identify the registered user. But - I must to have the session number to. How can I add the session number if I had a cookie:

 

<?php

//Create array of supported languages
$languages = array('en', 'hu', 'sr');

//Check the $_GET value if exists
if (isset($_GET['language']) && in_array($_GET['language'], $languages)) {
  $language = $_GET['language'];
  $_SESSION['language'] = $language;
  setcookie('language', $language, time()+60*60*24*365);

//Check the COOKIE value if $language not set
} elseif (isset($_COOKIE['language']) && in_array($_COOKIE['language'], $languages)) {
  $language = $_COOKIE['language'];
  $_SESSION['language'] = $language;

//Check the SESSION value if $language not set (in case cookies disabled)
} elseif (isset($_SESSION['language']) && in_array($_SESSION['language'], $languages)) {
  $language = $_SESSION['lang'];

//Language still not set, use default
} else {
  $language = $languages[3];
  $_SESSION['language'] = $language;
  setcookie('language', $language, time()+60*60*24*365);

}
?>

 

Thanx in advanced

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.