1

So I'm currently stuck on a little idea I'm trying out. Currently I have a 'GET form' with PHP running on my site. What I'd like to do is when the get form is submitted, it'll be pointed to a page where an IF ELSE script will be waiting (No idea if it's called IF ELSE with PHP functions)

Now, what I'd like this script to do is to read the GET Form value from the URL. If it matches to a specific few keywords, it'll redirect to a specific page. If it doesn't match any of the words, it'll be pointed to another.

Hopefully something like this will be simple to you guys, as I'm currently completely lost on making this work. Any help is appreciated, thanks a lot in advance!

1
  • 1
    @jondavidjohn I know but clearly a noob so cutting him some slack. When comparing to myself and how I learned things I wonder how some people ever do get their careers kicked off. Commented Apr 13, 2011 at 4:07

3 Answers 3

5
if($_GET['var1'] == "valueyouwant" || $_GET['var1'] == "another_acceptable_value"){
  header("Location: redirect_to_me.php");
} else {
  header("Location: redirect_to_another_page.php");
}

exit();

or a little refactored:

$redirect_page = "redirect_to_another_page.php";

if(in_array($_GET['var1'], array('acceptable_answer1', 'accetable_answer2')){
 $redirect_page = "success_page.php";
}

header("Location: " . $redirect_page);
exit();

I put the exit() call because it is general practice to exit the script after sending headers.

Sign up to request clarification or add additional context in comments.

2 Comments

Oo that looks perfect! Thanks for the quick reply! And it's possible to add multiple values to the "valueyouwant" field?
yes, you can just have AND(&&) or OR(||) conditions, such as the updated answer.
0

You should look at the following in the php manual for information on how to do redirects:

header function

Comments

0

I strongly suggest you read a PHP tutorial, or perhaps better yet a book. There are several good tutorials out there and what you're asking is very simple -- you can combine it with the other answer's suggestions but you should start from scratch nonetheless.

PHP.net Tutorial
W3C Tutorial

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.