SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Nov 2000
    Posts
    741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ugent help need with simple redirect

    I have this code to redirect someone to another page. The php line must remain there as it is.

    PHP Code:
    <?php $id=2; include('/home/xxx/public_html/bbb/rr_rrr.php');?>
    <script language="JavaScript">
    <!--
       window.location.replace('http://mylink.com/xys?sub=xx');
    //-->
    </script>
    But now I need to redirect the person to a page that depends on some variables. The following script works:

    PHP Code:
    <?php $id=2; include('/home/xxx/public_html/bbb/rr_rrr.php');?>
    <?php
    $sub
    =$_GET['sub'];
    $offer=$_GET['offer'];

    if (
    $offer == "111") {$product "http://mylink.com/xcv?sub=yy";}
    if (
    $offer == "222") {$product "http://mylink.com/xys?sub=xx";} 
    header("Location: $product");
    exit();
    ?>
    However, I need the redirect section as javascript. How can I achieve this?

    Thanks,

    Jon

  2. #2
    SitePoint Addict
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've always used the following for js redirects:
    Code:
    <script type="text/javascript">window.location.href='http://www.newsite.com';</script>
    Do you know what the difference is?

    Using your example and the js redirect you used it might look like this:
    PHP Code:
    <?php
    $id
    =2; include('/home/xxx/public_html/bbb/rr_rrr.php');

    $sub=$_GET['sub'];
    $offer=$_GET['offer'];

    $product '';
    if (
    $offer == "111") {$product "http://mylink.com/xcv?sub=yy";}
    if (
    $offer == "222") {$product "http://mylink.com/xys?sub=xx";}
    if(!empty(
    $product)) {echo '<script type="text/javascript">'."window.location.replace('".$product."');</script>";}

    exit();
    ?>

  3. #3
    SitePoint Guru
    Join Date
    Nov 2000
    Posts
    741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That did it 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
  •