简体   繁体   中英

How do I change get request url?

First and foremost, I am learning html and php for the first time and I wanted to understand how to convert a get request like:

example.com?query=test to something like example.com/test/

and does the same thing. I looked all over and maybe I am searching wrong, but any help is appreciated.

If you get that when submitting a form, change the method from get to post.

To collect the sent variable instead of using $_GET["varName"] use $_POST["varName"] or $_REQUEST["varName"]

For example:

<form action="/action_page.php" method="post">
  <label for="fname">First name:</label><br>
  <input type="text" id="fname" name="fname" value="John"><br>
  <label for="lname">Last name:</label><br>
  <input type="text" id="lname" name="lname" value="Doe"><br><br>
  <input type="submit" value="Submit">
</form> 

Collect values:

$fname=$_REQUEST["fname"];
$lname=$_POST["lname"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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