Vi capita mai di voler proteggere/condividere un url con password e non saper mai bene come fare?
Beh, è capitato anche a me, e per farlo ho realizzato un piccolo script – ottimizzato per mobile e con tanto di grafica integrata su singolo file – che mi manda a destinazione solo dopo aver digitato la password corretta nell’apposito form.
Il mio era più semplice, e con grafica diversa.
Questo l’ho “migliorato” un po’, aggiungendo un mini setup nel caso in cui la password non sia configurata ed ho aggiunto una grafica un po’ nerd 😆
Bozza dei sorgenti: qualunquenome.php
<?php /* Author Salvatore Noschese: https://www.laltroweb.it */ // Set Password $setpwd = ''; $md5_id = ''; $sha1_id = ''; $location = ''; // Default template $templatestart = "<!DOCTYPE html> <html lang='it-IT' dir='ltr'> <head> <meta charset='utf-8'> <meta name='viewport' content='width=device-width, initial-scale=1'> <link rel='icon' type='image/png' href='...' sizes='16x16'> <meta name='robots' content='noindex,nofollow,noodp,noydir'> <meta name='author' content='Salvatore Noschese - L’AltroWeb'> <title>Private Pages's - Welcome ?</title> <style> body { text-align: center; background: url('...') repeat fixed center; } #page { background: rgba(255, 255, 255, 0.95); border: 1px dotted #cdcdcd; margin: 20px auto; padding: 10px; width: auto; max-width: 600px; } form * { text-align: center; font-size: 18px; } #password { display: block; line-height: 1.5; margin: 2px auto; padding: 2px; } #submit { padding: 0 5px; } #reload { padding: 5px; font-size: 14px; } h1 { color: #619B30; font-size: 24px; } h2 { font-size: 18px; color: #3399FF; } #bad-password { color: #E52512; } .green { color: green; } .blue { color: blue; } .red { color: red; } #second_step { text-align: left; } </style> </head> <body> <div id='page'>"; $templateend = " </div> </body> </html>"; // Strong encoded password if(!isset($setpwd) || empty($setpwd)) { echo $templatestart; if(isset($_POST['setpwd']) && !empty($_POST['setpwd']) && isset($_POST['location']) && !empty($_POST['location'])) { $md5_id = substr(md5(uniqid()),0,7); $sha1_id = substr(sha1(uniqid()),0,7); $setpwd = md5($md5_id.sha1($sha1_id.$_POST['setpwd'])); $location = base64_encode($_POST['location']); echo " <div id='second_step'> <p>Second step: Copy Password!<br>Copy this values in script and save!</p> <span class='green'>// Set Password</span> <br> <span class='blue'>\$setpwd</span> = <span class='red'><b>'".$setpwd."';</b></span> <br> <span class='blue'>\$md5_id</span> = <span class='red'><b>'".$md5_id."';</b></span> <span class='blue'>\$sha1_id</span> = <span class='red'><b>'".$sha1_id."';</b></span> <br> <span class='blue'>\$location</span> = <span class='red'><b>'".$location."';</b></span> <p>Don't worry... you can continue to use clean-uncrypted password for login!</p> </div> <hr> After copy, click here: <input id='reload' type='reset' onclick='window.location=self.location+\"?".time()."\";' value='Reload' name='reload'>"; } else { echo " <p>First step: Password setup!<br>Put your password here, and run this form!</p> <form method='post' action='".$_SERVER['PHP_SELF']."' autocomplete='off'> <p><input type='password' id='setpwd' name='setpwd' value='' autocomplete='off' placeholder='password here...' required></p> <p><input type='url' id='url' name='location' value='' autocomplete='off' placeholder='url here...' required></p> <input type='submit' value='Go'> </form>"; } echo $templateend; exit; } // set default/no-warning var $form = ''; $badpassword = ""; $alert = "\n\t<h2>Se ti trovi qui e non sai di cosa si tratta, sei pregato di uscire!</h2>"; if(isset($_POST['password']) && md5($md5_id.sha1($sha1_id.$_POST['password'])) == $setpwd) { // = if password is set and is valid, go to location header('Location: '.base64_decode($location).''); } elseif(!isset($_POST['password'])) { // = if password not set show password form $form = " <h1>Questa è una pagina riservata e protetta con password ?</h1> <form method='post' action='".$_SERVER['PHP_SELF']."'> <input id='password' type='password' name='password' placeholder='Password qui...' required> <input id='submit' type='submit' value='Invia ?'> </form>"; } else { // = if password is set and isn't valid, not show form and show warning! $badpassword = " <h1 id='bad-password'>Hai sbagliato la password!!! ?</h1> <button id='reload' onclick='window.location=self.location+\"?".time()."\";' title='...o esci!'>Riprova</button>"; } echo $templatestart.$form.$badpassword.$alert.$templateend; ?>
Demo “non settato”: https://www.laltroweb.it/_script/demo_pvt/pvt_unset.php
Demo “settato”: https://www.laltroweb.it/_script/demo_pvt/pvt_set.php
Spero possa tornare utile 🙂
PS: per errore ho pubblicato lo screen del file “set” (configurato) 😀
Chi sarà tanto bravo da riuscire a capire la password usata e quindi l’url protetto? 😛