Results 1 to 7 of 7

Thread: pause Xsec before redirect in a php IF ELSE (see inside)

  1. #1
    Join Date
    Jun 2006
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default pause Xsec before redirect in a php IF ELSE (see inside)

    Hi, hope the title was clear so that you arrived here...

    i will first show my code then explain
    Code:
    <?php
    #Valid news?
    if ($news_bol > 0 && ($debut <= $today && $fin >= $today))
    {
    echo "<script type='text/javascript'>location.href='news.php';</script>";
    }
    # Valid video?
    else if ($videos_bol > 0 && ($debut_v <= $today && $fin_v >= $today))
    {
    echo "<script type='text/javascript'>location.href='video.php';</script>";
    }
    else
    {
    echo "<script 
    type='text/javascript'>location.href='promo.php';</script>";
    }
    ?>
    here it is, so i check a value in php, if the value is right, i execute a javascript redirect, else i exec another, i first tried to pause my page with a php sleep() but that brings problems with my other pages executed at the same moment.so maybe there is a way in the javascript part of this?

    can someone tell me how to pause the execution of the redirect for X seconds?
    it would be so helpfull .

    Thanks already.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You shouldn't be using this here. Use PHP to output a Refresh header:
    Code:
    header('Refresh: 5;url=video.php');
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jun 2006
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    EDIT:
    Should this work? cause it dosn't seem to do:
    <?php
    #premier IF pour voir si il existe une NEWS valide
    if ($news_bol > 0 && ($debut <= $today && $fin >= $today))
    {
    header('Refresh: 5;url=news.php');
    }
    # ELSE IF pour voir si il esxite une VIDEO valide
    else if ($videos_bol > 0 && ($debut_v <= $today && $fin_v >= $today))
    {
    header('Refresh: 5;url=video.php');
    }
    else
    {
    header('Refresh: 5;url=promo.php');
    }
    ?>

    yes but the redirect is conditionnal, can i do multiple conditions redirect with header function?

    cause header needs to be first , without spaces and so on...i 'll have a look that way but i don't know if this will be what i need.

    thanks for the help anyway.
    Last edited by noobster; 03-30-2007 at 02:38 PM.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    yes but the redirect is conditionnal, can i do multiple conditions redirect with header function?
    Yes, there is no problem, so long as you don't output anything before redirecting. If your code style makes this difficult (which is a bad design, by the way), the easy way out is to use output buffering to buffer everything then output it at the end.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jun 2006
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Allright my redirection works, way better, thanks for that

    i try to do what i can at coding, you can't be good in one day


    could you tell me what is so wrong in the code i just send earlier? so that i could improve?

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Output buffering works like so:
    Code:
    ob_start();
    // Do some things that produce output
    $v = ob_get_clean();
    $v then contains the output produced. This can be wrapped around the whole page, and the result of ob_get_clean() printed directly at the end:
    Code:
    print ob_get_clean();
    ... thus easily solving the no-output-before-headers problem, although at the cost of some additional memory usage for the server.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Jun 2006
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks i'll keep that in mind although header redirection works, could do that before anything else .

    Thanks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •