• 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

    • iPadOS 26 is now official with improved windowing, menu bar, 'Liquid Glass' redesign, more by Taras Buria As expected, today, at WWDC 2025, Apple announced iOS 26 and other operating systems that now carry the 26 version number (for simplicity). iPadOS is also part of the big redesign, and it is now official with the new Liquid Glass design, improved window controls, a Mac-like menu bar, file management enhancements, and more. In addition to the general Liquid Glass redesign, which is now present across all of Apple's operating systems, iPadOS 26 received several iPad-exclusive upgrades. It now has a reworked windowing system that helps you organize and switch between apps. You can finally place and resize apps exactly how you want. Plus, iPadOS now has familiar window controls: three buttons for closing, minimizing, and resizing your app. Straight from macOS. Apps can now remember their previous size and position, and Expose can show you all open windows. Finally, iPadOS now has a menu bar, which is another thing that comes from macOS. It gives access to common actions, commands, and features. Developers can customize the menu bar in their apps and specify what features are available there. Apple is also upgrading the Files app with a reworked List view, which now shows more details about your files and the ability to expand or collapse folders. Plus, you can customize folders with colors and emojis, pin folders to the dock, and set default apps for file types. When working with long-running processes, background tasks show up as live activities, so that you can track Final Cut exports or the Files app moving stuff around. Other changes in iPadOS 26 include improved audio controls and the ability to select audio input source and record audio with voice isolation. The Journal app is now available on the iPad, Notes received markdown support, and Calculator now supports 3D graphing capabilities. You can learn more about iPadOS 26 in the official announcement post here.
    • That same Brave that tried to insert their own ads instead of blocked ones?
    • lol more spy centers - great work tiny hat gov. The surveillance state is licking it's chops so Palantir can know your every thought and move. 1984 is already here folks. Maybe start fighting it instead of contributing to it? Here is a good start - stop putting your entire life on a computer. Walk outside and see real life.
    • How long until Microsoft, Google, and others go (back) to this design trend?
  • Recent Achievements

    • Rookie
      CHUNWEI went up a rank
      Rookie
    • Enthusiast
      the420kid went up a rank
      Enthusiast
    • Conversation Starter
      NeoToad777 earned a badge
      Conversation Starter
    • Week One Done
      VicByrd earned a badge
      Week One Done
    • Reacting Well
      NeoToad777 earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      476
    2. 2
      +FloatingFatMan
      279
    3. 3
      ATLien_0
      255
    4. 4
      Edouard
      204
    5. 5
      snowy owl
      200
  • Tell a friend

    Love Neowin? Tell a friend!