Hi, I'm pretty new to php and you guys may be able to help, what I am trying to do is create a php script that redirects a user to a specific page based on a username that they enter, no password needed. I am completely clueless when writing code such as this. e.g. user types name in html form such as "marc" the form references the php script which identifies "if marc" then redirects to page1.html , whereas "if dave" is entered it wouuld redirect to page2.html. is this possible? any suggestions or help would be greatfully recieved, thanks Marc
You can simply do like this <?php $name = $_POST['name']; if($name == "marc") { header('Location: http://www.yoursite.com/page1.html'); } elseif($name == "dave") { header('Location: http://www.yoursite.com/page2.html'); } else { header('Location: http://www.yoursite.com/nopage.html'); } ?> PHP: there are manyways but it's just a basic illustration for you hope it helps
Or like this: (just to let you know another possible way, if you have many such names you wouldn't want to write all those if elses) $destination = array('marc' => 'page1.html', 'dave' => 'page2.html'); if (isset($destination[$_POST['name'])) { header('Location: http://www.example.com/' . $destination[$_POST['name']]); } else { header('Location: http://www.example.com/default.html'); } die(); PHP:
Hey, There are couple of methods of do that. These methods depends upon the conditions your have. if you have lots of condition then you need to use switch case $name = $_POST['name']; switch($name) { case 'marc': header("Location: the address to redirect"); break; case 'dave': header("Location: the address to redirect"); break; case 'john': header("Location: the address to redirect"); break; } Now on the redirect thing you can use javascript redirect as well echo("<script>location.href='redirect location'</script>"); Hope this works: Regards, Stylesofts Developing Team