Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

if Isset cookie else redirect to another link

Posted on 2007-04-04
6
Medium Priority
?
1,486 Views
Last Modified: 2007-07-21
// this is the index.php file below

session_start();

$frm_country = $_POST['submit'];
$_SESSION['country'] = $frm_country;
setcookie("country",$frm_country, time()+3600);

// check if cookie is set
if (isset($_COOKIE["country"]))
{
   $country = $_COOKIE["country"];
   $country = $_SESSION['country'];

}
else
{
   header("Location: http://www.cars.com/worldmap.php");   /* Redirect browser */
}

----------------------------------------

i have replaced the real website with 'cars'.
Basically if the country cookie has no value then
go to worldmap.php where you can click on the country then where the form will send a POST
which will contain the country in $frm_country.
but what actually happen with the above code
is when i clear my browser cookie and go to index.php
it automatically transfers me to worldmap.php because there is no cookie value set
and then once i click on 'australia' it puts the cookie in the browser but it remains
on the same worldmap.php until i hit the country again.
0
Comment
Question by:Alpha_AI
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 5

Expert Comment

by:richswyatt
ID: 18851362
Can I see the code you are using in Worldmap.php to submit the users country click?
0
 

Author Comment

by:Alpha_AI
ID: 18851558
sure.

<form action='index1.php' method='POST' >
        <input type='hidden' name='north_america' value='1' />
        <input name="submit" type="submit" style="background-color: transparent; border: none; cursor: pointer; text-decoration: underline; color: #59200d;"  value="northamerica" />
      </form></td>
      <td width="8%"><form action='index1.php' method='POST' >
        <input type='hidden' name='south_america' value='1' />
        <input name="submit" type="submit" style="background-color: transparent; border: none; cursor: pointer; text-decoration: underline; color: #59200d;"  value="South America" />
      </form></td>
      <td width="9%"><form action='index1.php' method='POST' >
        <input type='hidden' name='central_america' value='1' />
        <input name="submit2" type="submit" style="background-color: transparent; border: none; cursor: pointer; text-decoration: underline; color: #59200d;"  value="Central America" />
      </form></td>
      <td width="4%"><div align="center"><form action='index1.php' method='POST' >
        <input type='hidden' name='europe' value='1' />
        <input name="submit" type="submit" style="background-color: transparent; border: none; cursor: pointer; text-decoration: underline; color: #59200d;"  value="Europe" />
      </form></div></td>
      <td width="5%"><form action='index1.php' method='POST' >
        <input type='hidden' name='france' value='1' />
        <input name="submit" type="submit" style="background-color: transparent; border: none; cursor: pointer; text-decoration: underline; color: #59200d;"  value="France" />
      </form></td>
      <td width="5%"><form action='index1.php' method='POST' >
        <input type='hidden' name='australia' value='1' />
        <input name="submit" type="submit" style="background-color: transparent; border: none; cursor: pointer; text-decoration: underline; color: #59200d;"  value="australia" />
      </form></td>
      <td width="8%"><form action='index1.php' method='POST' >
        <input type='hidden' name='new_zealand' value='1' />
        <input name="submit" type="submit" style="background-color: transparent; border: none; cursor: pointer; text-decoration: underline; color: #59200d;"  value="newzealand" />
      </form></td>
      <td width="7%"><form action='index1.php' method='POST' >
        <input type='hidden' name='middle_east' value='1' />
        <input name="submit" type="submit" style="background-color: transparent; border: none; cursor: pointer; text-decoration: underline; color: #59200d;"  value="Middle East" />
      </form>

0
 

Author Comment

by:Alpha_AI
ID: 18851574
index.php is at the moment index1.php
until i go live where ya know i rename index1.php to index.php

cheers

Ben

0
 
LVL 5

Accepted Solution

by:
richswyatt earned 500 total points
ID: 18851664
Hmm - it seems to me that you are setting the cookie before they even click a country.

This is way it seems to me: someone hits your site - the index.php page - and it s/b redirecting them to the worldmap page if no cookie.  Put a condition around the cookie set so that it only does it when $_POST['submit'] is not blank.
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question