简体   繁体   中英

How to get user input and apped to the URL in PHP?

I want to create a simple PHP website were user should enter any string in text box and click submit then that string should be placed in the URL

For example:

If user entered "Java" as their input then after clicking submit, the URL should change to:

example.com/Java

How it's possible any example or a sample program if possible

Well, taking your question literally, this should work

<?php
    if(isset($_POST['submit'])){
        $userInput = $_POST['userInput'];
        header('Location:example.com/'.$userInput);
    }
?>
<form action="" method="POST">
    <input type="text" name="userInput"/>
    <input type="submit" name="submit" value="Send"/>
</form>

Of course, depending on your codes, this might be used to tamper or do something bad to your codes.

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