Jump to content

can php set a cookie or varible? so i only perform an action once


ident

Recommended Posts

Basically my site is having a few bugs with how it displays IE. It works fine in FF.  while i am sorting this i added a redirction page to alert the user.

 

<?php
function ae_detect_ie()
{
    if (isset($_SERVER['HTTP_USER_AGENT']) && 
    (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
        return true;
    else
        return false;
}
?>

<?php  if (ae_detect_ie()) {  ?>
echo "<script language='javascript'>
window.location = "http://www.url.com/Ie.php"
</script>";

<?php }  ?>

 

Obviously each time they hit index.php it displays this. How can i add a varible or something so it only redirects them once.

 

than ks

You could set a session variable and then check to see whether or not the session variable exists. The session variable, however, will last until they exit their browser.

 

<?php
session_start();
function ae_detect_ie()
{
    if (isset($_SERVER['HTTP_USER_AGENT']) && 
    (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
        return true;
    else
        return false;
}
?>

<?php 
if(is_null($_SESSION['viewed'])){
if (ae_detect_ie()) {  ?>
echo "<script language='javascript'>
window.location = "http://www.url.com/Ie.php"
</script>";
<?php
$_SESSION['viewed'] = 1;
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.