• 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.
  • Posts

    • Same is happening with our team out in the field with Startlinks on their pickup trucks...
    • Another fraudulent promise, just like the others that were supposed to bring prosperity to the US. Won't happen as long as Donald is president, along with his JDV partner.
    • And it's bloody annoying, overwrote a block of code I was working on cause I thought I had it turned off but just as I hit tab it nixed the intelisense with a block of its own -.-'
    • The "elephant in the room" was MS's philosophy decades ago to no longer support an OS designed for businesses and serious consumer; instead deciding to pander to the gaming set with its attendant complexity. Clearly forgetting that needless complexity (bloat?) creates needless problems and the resulting instability.
    • Elon Musk's Starlink loses all links as it goes down with a global outage by Sayan Sen Image via StarlinkIf you are using Starlink services in your home and are having trouble accessing their services, you are definitely not alone. Several thousand users online are reporting that they are noticing the same issue. The first reports started emerging on Reddit where a Redditor noticed that Starlink was already aware of the situation. On the front page of the official Starlink website, a message had been posted that read "Starlink is currently experiencing a service outage. Our team is investigating." Unfortunately, we could not access Starlink's own website to verify it, as it is leading to a "Error 503 Request timed out" and "Error 54113" messages, likely because the server is loaded with user visits as they are trying to find out what is going on. We will update the story once more details are available. Thanks for the tip MrElectrifyer!!!!
  • Recent Achievements

    • One Month Later
      Devesh Beri earned a badge
      One Month Later
    • Week One Done
      Harold57 earned a badge
      Week One Done
    • Rookie
      Brett76 went up a rank
      Rookie
    • One Month Later
      Brett76 earned a badge
      One Month Later
    • Apprentice
      Snake Doc went up a rank
      Apprentice
  • Popular Contributors

    1. 1
      +primortal
      588
    2. 2
      ATLien_0
      236
    3. 3
      Xenon
      148
    4. 4
      Michael Scrip
      139
    5. 5
      +FloatingFatMan
      118
  • Tell a friend

    Love Neowin? Tell a friend!