Action in header/location

Discussion in 'PHP' started by fex, Jul 12, 2008.

  1. #1
    Hello,

    Quick php question,, I want to redirect my browser with php instead of using a form with action="<? echo $PHP_SELF ?>?action=login"

    This is what I 've got but it does not work:
    header ("Location: ".$_SERVER['PHP_SELF']."?action=login");
     
    fex, Jul 12, 2008 IP
  2. fex

    fex Peon

    Messages:
    89
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Since this is still a forum, I'll answer how I solved this.

    First of all it couldn't work at all because the page you receive with $_SERVER['PHP_SELF'] is the php page which is redirecting itself (which in my case does not include any html), so not the page you desired. It is needed to pass the right page earlier. I did this by using a hidden field:
    <input type="hidden" value="<? echo $PHP_SELF ?>?action=login" name="url" />
    Meaning the value of this hidden field is the page where I need to be. Then you can easily call the value.

    In the php that's redirecting, included these lines:
    $url = $_REQUEST['url'];
    header ("Location: ".$url);

    That's it
     
    fex, Jul 12, 2008 IP