• 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

    • Vivaldi 7.4.3684.50 by Razvan Serea Vivaldi is a cross-platform web browser built for – and with – the web. A browser based on the Blink engine (same in Chrome and Chromium) that is fast, but also a browser that is rich in functionality, highly flexible and puts the user first. A browser that is made for you. Vivaldi is produced with love by a founding team of browser pioneers, including former CEO Jon Stephenson von Tetzchner, who co-founded and led Opera Software. Vivaldi’s interface is very customizable. Vivaldi combines simplicity and fashion to create a basic, highly customizable interface that provides everything a internet user could need. The browser allows users to customize the appearance of UI elements such as background color, overall theme, address bar and tab positioning, and start pages. Vivaldi features the ability to "stack" and "tile" tabs, annotate web pages, add notes to bookmarks and much more. Vivaldi 7.4.3684.50 changelog: [Chromium] Update to 136.0.7103.170 [Crash][Mail][JSError] RangeError: Maximum call stack size exceeded (VB-115288) Download: Vivaldi 64-bit | 125.0 MB (Freeware) Download: Vivaldi 32-bit | ARM64 View: Vivaldi Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • I must be doing something right because I feel like I don’t really come across that many cheaters. I’m not saying you don’t, I just must be really lucky.
    • That’s a real shame, he’ll be greatly missed.
    • Supply and demand. Competition is a good thing.
  • Recent Achievements

    • Apprentice
      Adrian Williams went up a rank
      Apprentice
    • Reacting Well
      BashOrgRu earned a badge
      Reacting Well
    • Collaborator
      CHUNWEI earned a badge
      Collaborator
    • Apprentice
      Cole Multipass went up a rank
      Apprentice
    • Posting Machine
      David Uzondu earned a badge
      Posting Machine
  • Popular Contributors

    1. 1
      +primortal
      538
    2. 2
      ATLien_0
      264
    3. 3
      +Edouard
      192
    4. 4
      +FloatingFatMan
      182
    5. 5
      snowy owl
      135
  • Tell a friend

    Love Neowin? Tell a friend!