Alpha_AI
asked on
if Isset cookie else redirect to another link
// this is the index.php file below
session_start();
$frm_country = $_POST['submit'];
$_SESSION['country'] = $frm_country;
setcookie("country",$frm_c ountry, 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.
session_start();
$frm_country = $_POST['submit'];
$_SESSION['country'] = $frm_country;
setcookie("country",$frm_c
// 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.
Can I see the code you are using in Worldmap.php to submit the users country click?
ASKER
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>
<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>
ASKER
index.php is at the moment index1.php
until i go live where ya know i rename index1.php to index.php
cheers
Ben
until i go live where ya know i rename index1.php to index.php
cheers
Ben
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.