Current location: Hot Scripts Forums » Programming Languages » PHP » Cookie should initiate redirect, but flash stops it


Cookie should initiate redirect, but flash stops it

Reply
  #1 (permalink)  
Old 07-15-06, 07:59 PM
zitwep zitwep is offline
Wannabe Coder
 
Join Date: Aug 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Cookie should initiate redirect, but flash stops it

Hi there,

I have the following code on one of my sites as intro page

PHP Code:

<?PHP

    
    
//Coded by lightning-hosting (max)
    //Counter Agency Intro Page, setting cookies for first visits, so intro only shows on first time
    
    
    
if(isset($_GET['show'])) {
    
        if(
$_GET['show'] == 'yes') {
        
            
setcookie("cacomintroskip","skip",time()-60*60*24*7*365);
            echo 
"Cookie delteted";
            
        }
        
    }

    if(isset(
$_COOKIE['cacomintroskip'])) {

        if(
$_COOKIE['cacomintroskip'] == 'skip') {
        
        echo 
"<meta http-equiv=\"refresh\" content=\"0; URL=http://www.counter-agency.com/portal\">";
        exit();
        
        
        }
        
    }
    
    
    if(isset(
$_GET['skip'])) {
        
        if(
$_GET['skip'] == 'true') {
        
        echo 
"<meta http-equiv=\"refresh\" content=\"0; URL=http://www.counter-agency.com/portal\">";
            
            
        }
        
    }
        
    if(isset(
$_GET['dontshowagain'])) {
        
        if(
$_GET['dontshowagain'] == 'true') {
        
            
setcookie("cacomintroskip","skip",time()+60*60*24*7*365);
            echo 
$_COOKIE['counter-agency.com_introskip'];
            echo 
"<meta http-equiv=\"refresh\" content=\"0; URL=http://www.counter-agency.com/portal\">";
            
            
        }
    
    }
    
?>


<html>
    <head>
        <title>Counter-Agency.com - Greatest (S)hit</title>
        <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
        <script src="foo.js" type="text/javascript"></script>
        <link href="class.css" rel="stylesheet" media="screen">
    </head>
    
    <body bgcolor="#333333">
        <p align="center">
        <br /><br /><br /><br><br><br>
        
        <script type="text/javascript">RunFoo();</script>


        <br /><br /><br />
        <font color="#999999" face="Arial, Helvetica, sans-serif">
        <table border="0" align="center" width="50%">
            <tr>
                <td align="left"><a href="index.php?skip=true">Intro überspringen</a></td>
                <td align="right"><a href="index.php?dontshowagain=true">Nicht mehr zeigen</a></td>
            </tr>
        </table>
        </font>
        </p>
        
    </body>
</html>
The problem is that if I set the cookie, this should not be displaying anymore, but somehow the flash is stopping an immediate redirect, I tried with exit and everything but nothing works. Once the page is loaded and I press F5 (refresh) suddenly it recognizes the cookie and redirects me.

Does anybody know why that is?

PS: You might wonder what the javascript does, the script in the header includes the function run_foo, and runfoo will simply print my flash code, so that the border around flash is not shown since the new Microsoft "UPDATE".

Thanks for any help
best regards
zitwep
Reply With Quote
  #2 (permalink)  
Old 07-15-06, 08:03 PM
zitwep zitwep is offline
Wannabe Coder
 
Join Date: Aug 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Hmmmm,...now it works, no idea how come since I didnt do anything, but well, thanks for reading anyway ;-)

Greetz
zitwep
Reply With Quote
  #3 (permalink)  
Old 07-15-06, 08:53 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Any cookie variable $_COOKIE['...'] in the PHP script is not actually set when you do the setcookie(...) statment. The setcookie causes the cookie to be sent to the browser, but this is not sent back to a PHP script until the page is refreshed or is revisited (headers exchanged with the browser, which gives the cookies for your domain to the server.)

From the PHP manual -
Quote:
Common Pitfalls:
Cookies will not become visible until the next loading of a page that the cookie should be visible for. To test if a cookie was successfully set, check for the cookie on a next loading page before the cookie expires. Expire time is set via the expire parameter. A nice way to debug the existence of cookies is by simply calling print_r($_COOKIE);.
You can fake this to make your code work by setting the cookie variable at the same time you do the setcookie -
PHP Code:

setcookie("cacomintroskip","skip",time()-60*60*24*7*365);

$_COOKIE['cacomintroskip'] = 'skip'
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
Reply

Bookmarks


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

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Flash Programmer wanted - Romania valheru Job Offers & Assistance 1 07-13-06 09:04 AM
access cookie from different path crmpicco JavaScript 1 02-21-06 03:03 PM
Setting a cooke (time it expires) mcrob PHP 4 04-27-05 12:13 PM
cookie for initial flash intro dsulvett Flash & ActionScript 0 02-22-05 11:06 AM
Passing info between pages w/ URL HairySpider JavaScript 6 01-09-05 08:47 AM


All times are GMT -5. The time now is 07:21 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.