Jump to content

Sho6tyBby

Members
  • Posts

    2
  • Joined

  • Last visited

Sho6tyBby's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you, really useful! (: But I have a few more questions i: (: The variable $redircet. I don't understand what ?urldecode ($ _GET ['return']): '. /' exactly do? Also i don't understand the variable $expire what it exactly do? What do you mean by "supports a custom expiration time"? And i don't understand ($ _GET ['x']), what is x? And is_numeric, and the rest of the variable? And what do ($ expire == -1) and if ($ expire == 0)? And how long is mktime (0, 0, 0, 01, 01, date ("Y") + 30));? And why is cookie set twice? And what do you mean by "regular expiration time"? And at the function verified script. What do $ expires = - 1;? And why after the session_start (); are $ validated = false;? And at the different cases to check if cookie for verified is there, can you just delete the others and keep one of them?
  2. I have found an age verification code on the web. I would like to know if someone will help me to say what exact happens in the code? I'm kind a newbie to this and would like to know how it all works before I use it. Here comes the code. verify.php (page that will serve as the yes / no to the user) <?php session_start(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['YES'])) { $redirect = isset($_GET['return']) ? urldecode($_GET['return']) : './'; $expire = isset($_GET['x']) && is_numeric($_GET['x']) ? intval($_GET['x']) : -1; if ($expire == - 1) { $_SESSION['verified'] = "yes"; header("location: " . $redirect); exit(0); } if ($expire == 0) { setcookie("verified", "yes", mktime(0, 0, 0, 01, 01, date("Y") + 30)); $_SESSION['verified'] = "yes"; header("location: " . $redirect); exit(0); } setcookie("verified", "yes", (time() + $expire)); $_SESSION['verified'] = "yes"; header("location: " . $redirect); exit(0); } else { header("location: http://www.youtube.com/watch?v=gppbrYIcR80"); exit(0); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> Alcohol Age Verification Example Page </title> <link href="style.css" type="text/css" rel="stylesheet" /> </head> <body> <form action="" method="POST"> <p id="textVerify"> PLEASE VERIFY THAT YOU ARE OVER AGE 21 BEFORE ENTERING THIS SITE </p> <input name="NO" id="no" type="Submit" value="NO - Leave" /> <input name="YES" id="yes" type="Submit" value="Yes - Enter" /> </form> </body> </html> add to existing pages (at the top of each .html or .php page in your site,) <?php function verified(){ $redirect_url = 'http://www.YOURSITEROOT.com/verify.php'; $expires = - 1; session_start(); $validated = false; if (!empty($_COOKIE["verified"])) { $validated = true; } if (!$validated && isset($_SESSION['verified'])) { $validated = true; } if (is_numeric($expires) && $expires == - 1 && !isset($_SESSION['verified'])) { $validated = false; } if ($validated) { return; } else { $redirect_url = $redirect_url . "?return=" . $_SERVER['REQUEST_URI'] . "&x=" . $expires; Header('Location: ' . $redirect_url); exit(0); } } verified(); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.