在同一个头函数中传递一个动作参数和变量参数[关闭]

I am trying to pass an action parameter and a variable parameter in the same header function.

Here is the code that I have written so far:

header('Location: .?action=show_edit_form, word=$word');

When I use the action parameter alone, it goes to the next page, but when I try to pass a variable along with the action parameter, it does not work.

Please advise.

  1. Query string parameters in URLs are separated by & not by ,
  2. PHP doesn't interpolate variables inside strings quoted with ', you need "
  3. Although most browsers will silently error correct, the Location header requires an absolute URI

Thus:

header("Location: http://example.com/foo.php?action=show_edit_form&word=$word");

Unless you are certain your variable won't have special characters in it, you should make sure it is properly encoded for putting in a URL too.

header("Location: http://example.com/foo.php?action=show_edit_form&word=" . urlencode($word));

What you are doing with the header is just referring the user to another page that conforms to a normal url.

Header('Location: .?action=show_edit_form& word='.$word);

On that page you can call $_GET['word']. You may also want to urlencode your values to prevent any unforseen problems with invalid characters. Look carefully at you quotation marks inside the header function.

For Example,

    Here i am trying to send the parameter id & message for the purpose of deleting record,So you  
    use the following code,

             $Params="?action=delete&id=".$id."&mess=Deleted Sucessfully"; 

             header("Location:company.php".$Params);

    So , in the next page you will get the parameter variable as,

             $action=$_GET['action'];

             $id=$_GET['id'];

             $message=$_GET['mess'];


    Above is the format of passing multiple parameters.Hope it works...