• 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

    • tvOS 26 arrives with karaoke mode, updated profile switcher, Liquid Glass, and more by Aditya Tiwari WWDC 2025 is now live, and Apple has finally renamed all of its operating systems to version 26. This year, we have tvOS 26 for the Apple TV, featuring the freshly-baked Liquid Glass software design. Apple explained that Liquid Glass brings a fresh and vibrant look to Apple TV, "delivering a fresh and expressive design that beautifully reflects and refracts its surroundings using real-time rendering." Content is the primary focus of the experience when you fast-forward, rewind, or change a setting from the Control Center. The redesigned Apple TV app now features new poster art for movies and TV shows, with a touch of Liquid Glass. Users can now choose whether to display the profile switcher UI when their Apple TV wakes up, allowing them to quickly access their Watchlist and recommendations in the TV app, as well as playlists in Apple Music. Speaking of Apple Music, your iPhone can now double as a handheld microphone for Apple TV. The new karaoke mode allows multiple users to queue up songs from their iPhones and sing along, with support for lyrics translation and pronunciation. Apple has updated the FaceTime experience to make it consistent with iPhone. Contact Posters introduced with iOS 17 are now available on Apple TV, which display a contact's customized photo and name when starting a FaceTime call. Live Captions support on FaceTime now includes French, German, Japanese, Korean, Mandarin, and Spanish. FaceTime on Apple TV has been updated to display phone and voice call notifications for active profiles. Users can use their connected HomePod speakers or iPhone to answer them. Apart from that, tvOS 26 also brings new Aerial screen savers, featuring India's Goa and Kerala. Users can also personalize their screensaver experience and designate any AirPlay-enabled speaker as the permanent speaker for Apple TV. tvOS 26 has also made the sign-in experience a bit easier for users. Developers can link app logins to an Apple account, making it quicker for users to access their apps and content when setting up a new device. The new tvOS update is now available for testing through the Apple Developer Program, supported on Apple TV 4K (2nd generation and later). Meanwhile, the updated sing-along feature is available on iPhone 11 and later with Apple TV 4K (3rd generation).
    • Yup, a bit slow on some PCs at the time, but absolutely gorgeous.
    • That's essentially what I've been running on KDE
    • For some of us, we've never left! A lot of customization tools have allowed us to adopt a non-native glassy design.
    • 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.
  • 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
      478
    2. 2
      +FloatingFatMan
      278
    3. 3
      ATLien_0
      257
    4. 4
      Edouard
      205
    5. 5
      snowy owl
      200
  • Tell a friend

    Love Neowin? Tell a friend!