Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > PHP

Reply
 
LinkBack Thread Tools
Old February 17th, 2009, 12:11 PM   #1
WebForumz Member
 

Join Date: Jul 2006
Location: poole
Age: 28
Posts: 77
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 edd_jedi is on a distinguished road
Cookie help

I have a frustrsting problem that I hope is very easy to solve!

As an example, on various pages of my site I set a cookie called region, and give it one of 3 values: uk, usa, or jap. All I want to do is call the value already set to a cookie in the isset command. The code I keep coming across is:

Code:
if ( isset ($_COOKIE['region'] ) ) {
    header("Location: index.php");
}
But I want to find out what specific value is set, not just wether the cookie actually exists or not! How can I do this? Would it be something along the lines of:

Code:
 if ( isset ($_COOKIE['region'] $_VALUE['uk'] ) ) {
     header("Location: uk.php");
 } else if ( isset ($_COOKIE['region'] $_VALUE['usa'] ) ) {
      header("Location: usa.php");
} else if ( isset ($_COOKIE['region'] $_VALUE['jap'] ) ) {
      header("Location: jap.php");
Thanks.
edd_jedi is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old February 22nd, 2009, 02:48 AM   #2
WebForumz Member
 

Join Date: Jul 2007
Location: Australia
Age: 18
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Evilaussie is on a distinguished road
Re: Cookie help

The easiest way to do this would be to use $_SESSION data. Saves having to have multiple cookies as you can set it into the one session. I'm not sure how you have set it up, so i cant give you direct advice; However say you have a dropdown menu asking them to select what page they want to view (UK, USA or Jap) and once they have submitted that form, you direct them to a certain page depending upon what they selected; just do:

Code:
if(isset($_POST['submit'])) {
  
$_SESSION['region'] = $_POST['region'];

That's just the basic grab the form data and store it into a session. Once it is stored, (Dont forget to session_start() first.) you have that session data set and then you can use a function to determine were to direct them. Eg:

Code:
function Region($Region) {
  if(
$Region == "UK") {
     
header('location: uk.php');
  }
  elseif(
$Region == "USA") {
     
header('location: usa.php'); 
  }
  elseif(
$Region == "Jap") {
     
header('location: jap.php');
  }
  else {
     echo 
"Submit the form!";
  }

Then at the start of the page, execute the function. (I'm assuming you understand the code i used, thus i didn't go into too much explanation.). Hope it helped.
Evilaussie is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Tags
cookies , php


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with cookie program wahboo JavaScript 0 December 8th, 2008 09:48 PM
Cookie Problem! leathem JavaScript 0 September 24th, 2008 04:39 AM
Fortune Cookie alexgeek The Café 7 October 11th, 2007 09:13 AM
Cookie Help! graeme JavaScript 3 June 17th, 2006 10:22 AM
Cookie Data thoulden Classic ASP 2 August 23rd, 2005 08:02 AM


Search Engine Optimization by vBSEO 3.2.0 RC8