Need redirect

Discussion in 'PHP' started by humtuma, Aug 12, 2013.

  1. #1
    I am just trying to redirect like
    http://domain.yourdomain.com/redir.php?url=
    Code (markup):
    Where url=anydomain
     
    humtuma, Aug 12, 2013 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,897
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    check out the header commands - have to be done before you output anything to the browser.
    header('http://domain.yourdomain.com/redir.php?url='.$anydomain);
    PHP:
     
    sarahk, Aug 12, 2013 IP
  3. samyak

    samyak Active Member

    Messages:
    280
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    90
    #3
    you can use the header function on PHP. However if you have already created text output, then that function will generate an error.

    In that case you can try this:
    function redirect($anydomain)
    {
        echo '<META http-equiv="refresh" content="0;URL='.$anydomain.'">';
    die();
    }
    
    redirect("http://www.anydomain.com");
    PHP:
    Amit
     
    samyak, Aug 12, 2013 IP
  4. humtuma

    humtuma Notable Member

    Messages:
    1,225
    Likes Received:
    24
    Best Answers:
    3
    Trophy Points:
    250
    #4
    Getting error.



    I need this
    http://domain.yourdomain.com/redir.php?url=mutlipleDomain
    Code (markup):
    Ex-
    http://domain.yourdomain.com/redir.php?url=google.com
    Code (markup):
    when some one put the above url in browser,it will redirect to google.com

    or

    http://domain.yourdomain.com/redir.php?url=bing.com
    Code (markup):
    when some one put the above url,it will redirect to bing.com
     
    humtuma, Aug 13, 2013 IP
  5. samyak

    samyak Active Member

    Messages:
    280
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    90
    #5
    Add the function I gave you on redir.php.

    Then call it with this:
    redirect($_GET['url']);

    If this doesnt work, let me know what error you get.

    Thanks
     
    samyak, Aug 13, 2013 IP
  6. livedating

    livedating Active Member

    Messages:
    161
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    83
    #6
    Actually url should be encoded, please see PHP function urlencode() - its very important!
     
    livedating, Aug 16, 2013 IP