• 0

PHP Password then Redirect


Question

I have a personal site with some pictures that I would like to allow only family to see. I'd like to password protect it with something like my dogs name and if the user gets it correct then redirect to the gallery page. Can anyone help me with something like this?

Link to comment
https://www.neowin.net/forum/topic/395011-php-password-then-redirect/
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Well, you can do something like this.

<?php

$password = 'dog'; // Set your password here
$pass = $HTTP_POST_VARS[pass]; // pass should be the name of the textfield.

if ($password = $pass) { 
   Header("Location: redirect.html"); 
}
   else {
      echo "Wrong password";
   }
?>

Hope that helps :)

  • 0

heres what i cam up with, although its probably a little buggy :p

<?php

if($password == "mydogsname") {

header("Location: secretpage.php");

} else {

echo "Wrong password";

?>

<html>
<head></head>
<body>
<form action="index.php" method="post">
<input type="text" name="password">
<input type="submit" value="enter">
</form>
</body>
</html>

name the file index.php to make sure the form data goes to the right place.

change "mydogsname" to whatever you want your password to be

Edited by Colin-uk
  • 0
  Subfusion said:
Well, you can do something like this.

<?php

$password = 'dog'; // Set your password here
$pass = $HTTP_POST_VARS[pass]; // pass should be the name of the textfield.

if ($password = $pass) { 
   Header("Location: redirect.html"); 
}
   else {
      echo "Wrong password";
   }
?>

Hope that helps :)

586779560[/snapback]

...

2 equal signs, not one, otherwise anyone will be able to get into the website. Got to be careful, you know. :whistle:

  • 0

You can use this if you want:

<?php
$user = "family";
$password = "pass";
$secretpage = "your/url/to/the/page/";

 if (!isset($_SERVER['PHP_AUTH_USER'])) {
   header('WWW-Authenticate: Basic realm="Family Gallery"');
   header('HTTP/1.0 401 Unauthorized');
   echo 'You must login to view this page...';
   exit;
 } else {
   if( ( $_SERVER['PHP_AUTH_USER'] == $user ) && ( $_SERVER['PHP_AUTH_PW'] == $password ) ) {
      header( "Location: $secretpage" );
      exit;
    }
 }
?>

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.