1. Home
  2. Computing & Technology
  3. PHP / MySQL

How To Redirect Users to Hidden Pages

By Angela Bradley, About.com

When I was younger the first "password protected" pages I had were basically just pages not linked from the home page, that you needed to know the name of to navigate to. While this is obviously not secure enough for businesses, for many personal home pages that don't want complicated logins this works just fine. In this tutorial I will show you how to make such a login.
Difficulty: Easy
Time Required: 5 mins

Here's How:

  1. <form action="go.php" method="post">
    <INPUT type="text" name="page">
    <input type="submit" value="Go">
    </form>
    This code puts a text box on your page that allows users to enter the page they want to be redirected to. If the user enters "cat.html" they will be taken to that file on your server. It will then send this information to go.php, which we will create next.
  2. <?php
    $page = $_POST["page"];
    header("Location: $page") ;
    ?>
    The above code goes in the file go.php. It simply takes the file you entered on the first page and redirects you to it. This is a very simple way of hiding a page. You need to remember however this is not a secure way of protecting files. Anyone can still navigate to your page, or in fact use your PHP script to redirect their own pages. This can be a nifty little script, but use it with caution.

Tips:

  1. While the code in step one can go anywhere you want, the code in step two cannot be anywhere but the very top of the go.php file.
  2. If you are worried about someone else using your PHP script, try checking the referrer before running the redirect.

What You Need:

  • A server that runs PHP
  • A secret page you want your users to be redirected to
More PHP / MySQL How To's

Explore PHP / MySQL

More from About.com

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Step By Steps
  5. Manual Redirect PHP - Simple Password PHP - Easy PHP Password

©2008 About.com, a part of The New York Times Company.

All rights reserved.