how to redirect?

Discussion in 'PHP' started by promotingspace.net, Sep 19, 2007.

  1. #1
    Hi
    I need to redirect to the advertiser's website after some analysis. but header is not working
    i use another tag that sometimes works and sometimes not:
    echo "<script> window.parent.ifrmTEXTFRNewWin('$url')</script>";
    PHP:
    is there a solution? i'm still having problem. the original code is:
    searchclicks.php:

    <?php
    include 'global.php';
    $keyword=$_SESSION['q'];
    $publisher=clean($_GET['publisher']);
    $advertiser=clean($_GET['advertiser']);
    $listing=clean($_GET['listing']);
    
    $price=getcost($keyword,$listing);
    
    $sql2="SELECT * FROM advertiser WHERE id='$advertiser' ";
    $result2=mysql_query($sql2) or die (mysql_error());
    $row2=mysql_fetch_array($result2);
    $advertiserbalance=$row2['balance'];
    if ($advertiserbalance<$price) echo "The advertiser does not have enough balance in his/her account";
    else{
    $advertiserbalance-=$price;
    $sql3="SELECT * FROM publisher WHERE id='$publisher' ";
    $result3=mysql_query($sql3) or die (mysql_error());
    $row3=mysql_fetch_array($result3);
    $publisherbalance=$row3['balance'];
    $price=$price*3/4 ;
    $publisherbalance+=$price;
    $sqlu1= "UPDATE advertiser SET balance='$advertiserbalance' WHERE id='$advertiser'";
    $resultup1=mysql_query($sqlu1) or die(mysql_error()) ;
    if (!$resultup1) echo "There was a problem during the analysis. Please contact us to inform aout the issue";
    else{
    $sqlu2= "UPDATE publisher SET balance='$publisherbalance' WHERE id='$publisher'";
    $resultup2=mysql_query($sqlu2) or die(mysql_error()) ;
    $sql4="SELECT * FROM listing WHERE id='$listing' ";
    $result4=mysql_query($sql4) or die (mysql_error());
    $row4=mysql_fetch_array($result4);
    $url=$row4['url'];
    //var_dump($row4);
    
    //header("Location : $url");
    //header('Location: '.$url); 
    echo "<script> window.parent.ifrmTEXTFRNewWin('$url')</script>";
    }
    }
    ?>
    PHP:
     
    promotingspace.net, Sep 19, 2007 IP
  2. MakeADifference

    MakeADifference Peon

    Messages:
    476
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I would use the header function from php rather than the JavaScript redirect.

    Try to use header function with a 301 redirect, it works for me.
    Here is some sample code..
    <?
    $url = "http://www.google.com/";
    header( "HTTP/1.1 301 Moved Permanently" );
    header( 'Location: ' .$url ) ;
    ?>

    Make sure that you do not have any white space before the php block otherwise the redirect will not work as the response stream is already opened and the header is written.

    In your code also check for any white spaces in the file.
     
    MakeADifference, Sep 19, 2007 IP
  3. luiscardozo

    luiscardozo Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Make sure that globals.php does not have white spaces or empty lines.
    What if before each "echo" (in this code, there are error messages reporting) you put a "die" or "exit"? It assures that the script stop here, and no further processing is done (that is, if each of these errors are fatal, of course).

    From http://php.net/header:
     
    luiscardozo, Sep 20, 2007 IP
  4. msaqibansari

    msaqibansari Peon

    Messages:
    84
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Use the following code to redirect to specific page after 4 seconds.

    <html>
    <head>
    <meta http-equiv="Refresh" content="4;url=http://www.domain.com/link.html">
    </head>
    <body>
    </body>
    </html>
     
    msaqibansari, Sep 20, 2007 IP
  5. promotingspace.net

    promotingspace.net Peon

    Messages:
    361
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    none of above worked
    please visit this link tho see what happens and click on one of the ad links:
    http://www.php.jothost.com/adsense/test.php
    I need something to move the page out of the iframe. in that page i'm using header( 'Location: ' .$url ) ; other codes didn't work though
     
    promotingspace.net, Sep 26, 2007 IP