I need to create a form on my site where users enter a code and based on that code they're redirected to another page. Doing it through a database would be more secure but I wouldn't mind if the logic was handled on the form itself.
So, here's an example of what I mean:
Enter Code: (Box here)
Form searches through list of potential answers( s5d11, wy4sd, lk123, etc.), if it finds a match it redirects to a specific page for each code, if not it gives an error message that the code entered was wrong.
This is an example with two files, one html and one php file. The html-page submits the contents of your input to a php-page, which redirects the browser to an URL based on the input.
HTML, index.html:
<form action="redirect.php" method="get">
<input name="mytext" />
<input type="submit" />
</form>
PHP, redirect.php:
<?
switch($_GET['mytext'])
{
case 's5d11':
header('Location: http://somepage.com/');
break;
case 'qy4sd':
header('Location: http://someotherpage.com/');
break;
default:
print "<p>Wrong code. Try again</p>";
include('index.html');
break;
}
?>
Try this. I just whipped this up. You have a code and a path to redirect to for each code. You'll need to apply your own sanitation of course and any other standards. I put them all uppercase...
<?php
$_POST['CODE'] = 'CODE'; // Simulate post data...
$array_of_codes = array('CODE' => 'pathtoredirect');
$get_code = addslashes(strtoupper($_POST['CODE']));
if(array_key_exists($get_code, $array_of_codes))
{
header("Location:".$array_of_codes[$get_code]."");
}else
{
echo "Error: Code not in array.";
}
?>