简体   繁体   English

如何在url中传递参数?

[英]how to pass parameter in a url?

actually i want to pass a parameter in my url and retrieve it in the destination php page.实际上我想在我的 url 中传递一个参数并在目标 php 页面中检索它。 how can i do this?我怎样才能做到这一点? below is my code:下面是我的代码:

 if($result){ header("Location:view.php",TRUE,$search); } else{ echo "not found"; }

is it the correct way to write it?这是正确的写法吗? also how can i retrieve the parameter in the destination page that is "view.php"还有我如何检索目标页面中的参数“view.php”

You can pass a variable via the GET method:您可以通过GET方法传递变量:

if($result) {
  header("Location: view.php?search={$search}"); 
} else {
  echo "not found"; 
}

And then in your destination view.php you can access it like this:然后在您的目标view.php您可以像这样访问它:

$search = $_GET['search'];

You have to write ?你要写? after view.php and then the parameters like this view.php?parameter1=value .view.php之后,然后是像这样的参数view.php?parameter1=value

To access to those parameters in your destination page you have to use this command $_GET["parameter1"]要访问目标页面中的这些参数,您必须使用此命令$_GET["parameter1"]

The GET method sends the encoded user information appended to the page request. GET 方法发送附加到页面请求的编码用户信息。 The page and the encoded information are separated by the ?页面和编码信息由 ? 分隔。 character.特点。

  • http://www.test.com/index.htm?name1=value1&name2=value2 The GET method produces a long string that appears in your server logs, in the browser's Location: box. http://www.test.com/index.htm?name1=value1&name2=value2 GET 方法生成一个长字符串,该字符串出现在您的服务器日志中,在浏览器的位置:框中。

  • The GET method is restricted to send upto 1024 characters only. GET 方法仅限于发送最多 1024 个字符。

  • Never use GET method if you have password or other sensitive information to be sent to the server.如果您有密码或其他敏感信息要发送到服务器,请不要使用 GET 方法。

  • GET can't be used to send binary data, like images or word documents, to the server. GET 不能用于向服务器发送二进制数据,如图像或 Word 文档。

  • The data sent by GET method can be accessed using QUERY_STRING environment variable.可以使用 QUERY_STRING 环境变量访问 GET 方法发送的数据。

  • The PHP provides $_GET associative array to access all the sent information using GET method. PHP 提供了 $_GET 关联数组来使用 GET 方法访问所有发送的信息。

This website might be useful for you: GET&POST methods There are some examples you can see to improve your skills.该网站可能对您有用: GET&POST 方法您可以查看一些示例来提高您的技能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM