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

Link to comment
Share on other sites

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;
}
}
?>

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.