redirecting...

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by TarinC, Oct 25, 2005.

  1. TarinC

    TarinC New Member

    Messages:
    698
    Likes Received:
    0
    Trophy Points:
    0
    lets say that there is a site, but half the time you get the page cannot be displayed error.

    i want to redirect to it but if it doesnt work, it redirects to another site. is this possible? and if it is can you tell me how?
     
  2. Phil

    Phil Retired Staff

    Messages:
    7,344
    Likes Received:
    0
    Trophy Points:
    36
    You mean redirect by like a .tk?
     
  3. Bryon

    Bryon I Fix Things

    Messages:
    8,149
    Likes Received:
    101
    Trophy Points:
    48
  4. TarinC

    TarinC New Member

    Messages:
    698
    Likes Received:
    0
    Trophy Points:
    0
    site1 - The page i will create
    site2 - the page i want to redirect to
    site3 - in case 2 is not up.

    i want to create a page that will redirect to 2. when the site isnt up it will redirect to a 3rd site instead of the 2nd site.

    is there a code to do that?
     
    Last edited: Oct 25, 2005
  5. Jim

    Jim New Member

    Messages:
    170
    Likes Received:
    0
    Trophy Points:
    0
    <?php
    if(fopen("http://site2")){
    echo "<script>window.location='http://site2';</script>";
    } else {
    echo "<script>window.location='http://site3';</script>";
    }
    ?>
     
    Last edited: Oct 25, 2005
  6. Bryon

    Bryon I Fix Things

    Messages:
    8,149
    Likes Received:
    101
    Trophy Points:
    48
    Same thing I said. You should replace the javascript with just an HTTP header, and it will always work whether the vistor has JS disabled or not.
     
  7. TarinC

    TarinC New Member

    Messages:
    698
    Likes Received:
    0
    Trophy Points:
    0
    im sorry but im noob!

    i dont get that.
     
  8. Bryon

    Bryon I Fix Things

    Messages:
    8,149
    Likes Received:
    101
    Trophy Points:
    48
  9. TarinC

    TarinC New Member

    Messages:
    698
    Likes Received:
    0
    Trophy Points:
    0
    i did that and i get a error:

    Warning: fopen() expects at least 2 parameters, 1 given
    in "the file" on line 7

    line 7 of the script would be: if(fopen("http://site2")){
     
    Last edited: Oct 25, 2005
  10. oab

    oab New Member

    Messages:
    918
    Likes Received:
    0
    Trophy Points:
    0
    you have to put whether you want to read or write or somthing i think im to lazy to look it up..
     
  11. Kay

    Kay New Member

    Messages:
    804
    Likes Received:
    0
    Trophy Points:
    0
    Here you go

    Simply add this code to your php document:

    Code:
     
    <?php
    header("Location: http://[color=red]www.blaa.com[/color]/");
    ?>
    
    Change what is in red to your own website URL

    You must add this on the first line of your document, else it will NOT work!
     
  12. Bryon

    Bryon I Fix Things

    Messages:
    8,149
    Likes Received:
    101
    Trophy Points:
    48
    That error is because fopen() expects at least the first 2 arguments to be passed to it. Check out the PHP manual on it: http://php.net/fopen


    I would recommend using:

    PHP:
    <?php
       $site1 
    "http://www.yahoo.com";
       
    $site2 "http://www.google.com";
       
    $handle = @fopen($site1"r");
       if (
    $handle) {
         
    fclose($handle);
          
    header("Location: $site1"); // Redirecting to $site1
       
    } else {
         
    fclose($handle);
          
    header("Location: $site2"); // Redirecting to $site2
       
    }  
    ?>
    Edit: Wait wait wait. I have to fix something
    Edit 2: There ya go, I fixed it.
     
    Last edited: Oct 26, 2005
  13. TarinC

    TarinC New Member

    Messages:
    698
    Likes Received:
    0
    Trophy Points:
    0
    WOW! Thank you nedren! i got it to work!!!
     
  14. Bryon

    Bryon I Fix Things

    Messages:
    8,149
    Likes Received:
    101
    Trophy Points:
    48
    Your welcome. Try to understand what it's doing. First it puts two URL's into two seperate variables, $site1, and $site2. Then it trys to open a connection to the first URL. If the connection fails, it will make $handle false, which would make the if statement not true for the first "part" of it, which would cause it to execute whatever is in the "else" part of it, thus redirecting the browser to $site2. If the connection is opened, $handle would be true, and contain the data put into it from fopen(), so the first "block" in the if statement would execute, and redirect the browser to $site1.

    I hope you understand that...
     
  15. TarinC

    TarinC New Member

    Messages:
    698
    Likes Received:
    0
    Trophy Points:
    0
    yes thanks i understand. im not good with php.
     
  16. TarinC

    TarinC New Member

    Messages:
    698
    Likes Received:
    0
    Trophy Points:
    0
    ok i got it to work but lately it doesnt work. here is the error log:

    [07-Nov-2005 22:50:51] PHP Warning: fclose(): supplied argument is not a valid stream resource in /backup/home/tpsx10h/public_html/tps/custom/php/server.php on line 9
    [07-Nov-2005 22:52:55] PHP Warning: fopen(http://tps.servecounterstrike.com:27016/ip.w): failed to open stream: Connection timed out in /backup/home/tpsx10h/public_html/tps/custom/php/server.php on line 4

    it used to work but now i got this...

    inside the file:
    Code:
    <?php
    $site1 = "[url="http://tps.servecounterstrike.com:27016/ip.w"]http://tps.servecounterstrike.com:27016/ip.w[/url]";
    $site2 = "[url="http://tps.x10hosting.com/tps/custom/html/offline.html"]http://tps.x10hosting.com/tps/custom/html/offline.html[/url]";
    $handle = @fopen($site1, "r");
    if ($handle) {
    fclose($handle);
    header("Location: $site1"); // Redirecting to $site1
    } else {
    fclose($handle);
    header("Location: $site2"); // Redirecting to $site2
    }
    ?>
    
    please help! thanks

    for the script to start from the begining click here:
    http://tps.x10hosting.com/tps/custom/html/loadingOLD.html
     
    Last edited: Nov 8, 2005
  17. Bryon

    Bryon I Fix Things

    Messages:
    8,149
    Likes Received:
    101
    Trophy Points:
    48
    Hmm I'm not sure why your getting those errors. Have you used it for a link before such as:
    http://tps.servecounterstrike.com:27016/ip.w

    ?

    I would think that it would work fine, but it might be the different port other then php, http, and ftp that PHP isn't allowing to open. Let me check quick what stream types are allowed in php.ini.

    Ok well, this is what I found:
    Registered PHP Streams: php, http, ftp, compress.zlib

    So that might be the problem.

    I might be wrong with all this though, if the port 27016 has an HTTP or an FTP server residing on it. :-\

    Hmm. So I guess the question is, did the script before work fine?

    If so, what did you change that caused it to stop working?
     
  18. TarinC

    TarinC New Member

    Messages:
    698
    Likes Received:
    0
    Trophy Points:
    0
    it worked fine on november 6 and earlier.

    i changed the file directory and i came back to this forum remade the script:

     
    Last edited: Nov 8, 2005
  19. Bryon

    Bryon I Fix Things

    Messages:
    8,149
    Likes Received:
    101
    Trophy Points:
    48
    PHP:

    <?php
       $site1 
    "http://www.yahoo.com";
       
    $site2 "http://www.google.com";
       
    $handle = @fopen($site1"r");
       if (
    $handle) {
          
    header("Location: $site1"); // Redirecting to $site1
          
    fclose($handle);
       } else {
          
    header("Location: $site2"); // Redirecting to $site2
       
    }  
    ?> 

    Try that...
     
  20. TarinC

    TarinC New Member

    Messages:
    698
    Likes Received:
    0
    Trophy Points:
    0
    tried it.. it doesnt work.
     

Share This Page