php

Hello, pls can you help me with a php code that can restrict access to various pages with the using of certain numbers? example 1234 takes you to service.php, 1235 takes you to the aboutus.php etc. in php.
I wrote this code but it wasn’t right. Thanks

<?php if(isset($_POST['submit'])) { $name = $_POST['name']; echo $name; if ($name==1234) { header("Location:service.php"); echo "ok"; } elseif ($name== 1235) { header("Location:aboutus.php"); } else { echo "No input"; } } ?>

First of all the header needs to be the first thing else you will get an error. So it should be above the form without any echo’s or even enters! (your redirecting so they will not see the echo’s anything) second you named the input field “n”, but used $_POST[‘name’] to fetch it and third you had $_POST[‘submit’] yet you named it Submit with a capital S (it is case sensative).

Note I removed target="_blank", but add it again offcourse if you need it.

demo: http://www.kledinggericht.nl/tester/

only 1234 works there

[php]<?php
if(isset($_POST[‘Submit’]))
{
$name = $_POST[‘n’];
if ($name==1234)
{
header(“Location:service.php”);
} elseif ($name== 1235) {
header(“Location:aboutus.php”);
}
else
{
echo “No input”;
}

}

?>

[/php]

hello Jkwakkel,
I am Roland. thanks for the help. i am still having a little problem with the code. please can i get the files of http://www.kledinggericht.nl/tester/. thanks a lot

Sponsor our Newsletter | Privacy Policy | Terms of Service