Redirect some url's script

Discussion in 'Programming' started by joesgraphics, Jan 3, 2007.

  1. #1
    Hi do any of you no a script that will redirect a list of url's to a difrent page if it could be made of php plz thanks. :)
     
    joesgraphics, Jan 3, 2007 IP
  2. infernaliuns

    infernaliuns Active Member

    Messages:
    121
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #2
    :confused:

    It is this that you are looking for?

    
    
    <?
    
    header("Location: http://www.php.net");
    
    ?>
    
    
    PHP:
     
    infernaliuns, Jan 3, 2007 IP
  3. joesgraphics

    joesgraphics Peon

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Nop sorry let me tell you more i want to hav a list of banned urls to a script and when some 1 comes from that site they will get redirected to a page i want if that helps more.
     
    joesgraphics, Jan 3, 2007 IP
  4. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <?php
    
    $sendTo = 'http://www.mysite.com/you/are/banned.php';
    
    $blackList = array(
      'badsite.com',
      'badsubdomain.goodsite.com',
      'goodsite.com/baddir',
      'goodsite.com/gooddir/badscript.php'
    );
    
    if ( ! empty($_SERVER['HTTP_REFERER'] ) {
    
      foreach ( $blackList as $url ) {
        if ( strpos($_SERVER['HTTP_REFERER'],$url) ) {
          header('Location: ' . $sendTo);
        }
      }
    }
    
    ?>
    PHP:
    That sort of thing? (untested)
     
    rodney88, Jan 5, 2007 IP
  5. joesgraphics

    joesgraphics Peon

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi i get this error
    Parse error: syntax error, unexpected '{' in /home/****/public_html/****/**** on line 10
     
    joesgraphics, Jan 6, 2007 IP
  6. Pat Gael

    Pat Gael Banned

    Messages:
    1,331
    Likes Received:
    68
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Why not try mod_rewrite via .htaccess instead?

    Do it this way:

    
    RewriteEngine On
    RewriteCond %{HTTP_REFERER} ^http://(www\.)?banned1.com.*$ [NC,OR]
    RewriteCond %{HTTP_REFERER} ^http://(www\.)?banned2.net.*$ [NC,OR]
    RewriteCond %{HTTP_REFERER} ^http://(www\.)?banned3.info*$ [NC]
    RewriteRule \.*$ http://my-site.com/banned.php[R,L]
    
    Code (markup):
     
    Pat Gael, Jan 6, 2007 IP
  7. joesgraphics

    joesgraphics Peon

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    should i put this in the htaccess in the folder were i want the sites to be redirected from like lets lay they was coming to a link dump page and i wanted to redrect them from www.doamin.com/linkdump/index.php
    too www.domain.com/youarebanned.php
    for that would i put it in the linkdump folder is that right. thanks for the help any ways.
     
    joesgraphics, Jan 6, 2007 IP
  8. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Whoops, my fault. Forgot a closing ). Corrected version is below, or just use the rewrites above.

    <?php
    
    $sendTo = 'http://www.mysite.com/you/are/banned.php';
    
    $blackList = array(
      'badsite.com',
      'badsubdomain.goodsite.com',
      'goodsite.com/baddir',
      'goodsite.com/gooddir/badscript.php'
    );
    
    if ( ! empty($_SERVER['HTTP_REFERER']) ) {
    
      foreach ( $blackList as $url ) {
        if ( strpos($_SERVER['HTTP_REFERER'],$url) ) {
          header('Location: ' . $sendTo);
        }
      }
    }
    
    ?>
    PHP:
    EDIT: Yes, the .htaccess would go in your linkdump folder - then any requests to the linkdump dir (site.com/linkdir, site.com/linkdir/page.php, site.com/linkdir/anotherdir/script.php) will all be checked and redirected if they come from a banned site.
     
    rodney88, Jan 6, 2007 IP
  9. joesgraphics

    joesgraphics Peon

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Now i get :

    Parse error: syntax error, unexpected T_VARIABLE in /home/****/public_html/****/**** on line 1

    Thanks for all your help.
     
    joesgraphics, Jan 6, 2007 IP