Guest

PHP Help!

Recommended Posts

Guest

So I need a script/code that asks a question and then puts it in the url.

For example, the user is asked a question like "Which directory would you like to go now?" and lets say they put /index, then in the url it takes them to /index as they previously stated they wanted to go to /index.

If this is possible which I know it is, please help me!

Share this post


Link to post
Share on other sites

You have to use a submit button and take the value from it on the process url. Then you can build the url based on the value and send out a new header with the new url.

If you don't like this procedure you have to use java script.

But I am not really smart with php. So good luck. xD

Share this post


Link to post
Share on other sites

 
<form class="directory" action="" method="post">
	<input type="text" name="example" >
	<input type="submit" name="submit" value="Search" class="button">
</form>
<?php
$goodinput = array("Which directory would you like to go now?");

if(!empty($_POST['example'])){

    if (in_array($_POST['example'],$goodinput)){ //checks if user input is a  good input

       header('Location: http://www.example.com/directory.php');
       exit();

    } else {

       header('Location: http://www.example.com/404.php');
       exit();

    }
}

Is this what you mean?

Edited by Hazard

Share this post


Link to post
Share on other sites
Guest
On ‎25‎/‎08‎/‎2016 at 8:47 PM, Hazard said:


 

<form class="directory" action="" method="post">
	<input type="text" name="example" >
	<input type="submit" name="submit" value="Search" class="button">
</form>

<?php
$goodinput = array("Which directory would you like to go now?");

if(!empty($_POST['example'])){

    if (in_array($_POST['example'],$goodinput)){ //checks if user input is a  good input

       header('Location: http://www.example.com/directory.php');
       exit();

    } else {

       header('Location: http://www.example.com/404.php');
       exit();

    }
}

Is this what you mean?

 

Ah yes, thank you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now