redirect php page

Discussion in 'PHP' started by lansiko, Jun 22, 2010.

  1. #1
    lansiko, Jun 22, 2010 IP
  2. shubhamjain

    shubhamjain Active Member

    Messages:
    215
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    63
    #2
    Two ways - Using ".htaccess" [URL rewriting] or Writing viewer.php.

    Using the latter way -
    just write viewer.php.
     
    shubhamjain, Jun 22, 2010 IP
  3. lansiko

    lansiko Guest

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks! I got it working:

    	if($_GET['file'])
    header("Location: images/".$_GET['file']);
    Code (markup):
     
    lansiko, Jun 22, 2010 IP
  4. uldtot

    uldtot Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    maybe you want to secure that script a little bit.

    Filter out these:"/" , "\" and "."

    to avoid people from redirecting to etc/passwd file.
     
    uldtot, Jun 23, 2010 IP
  5. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #5
    if (preg_match('~^\w+\.(jpg|gif|png)$~i', $_GET['file']))
    header("Location: images/".$_GET['file']);
    PHP:
     
    danx10, Jun 23, 2010 IP
  6. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #6
    You can also do that with htaccess to have SEO Friendly URLS too :)
    Add this too you htaccess

    
    RewriteEngine On
    RewriteRule ^images/([^/]*)$ /viewer.php?file=$1 [L]
    
    
    Code (markup):
     
    roopajyothi, Jun 23, 2010 IP
  7. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #7
    Try this...,
    header("Location: ".$_GET['file']);
    its general..!
     
    strgraphics, Jun 23, 2010 IP