{$_COOKIE['LogIn']}\n"); fclose($fh); die("Success - check your other computer."); } if ($_GET['check']) { if (file_exists($db)) $sessions=file($db); else die(); foreach ($sessions as $k => $value) { $d=explode(">",$value); if ($d[0]==$_GET['check']) { setcookie('LogIn',$d[1],time()+24*60*60); //Delete the disposable key unset($sessions[$k]); $fh=fopen($db,"w"); foreach($sessions as $value) fwrite($fh,$value); fclose($fh); die("Success"); } } die(); } switch ($_GET['action']) { case "login": if ($_POST['username']) { setcookie('LogIn',htmlentities($_POST['username']),time()+24*60*60); die(""); } else echo "
Enter username:
"; break; case "qrlogin": $key=md5(time()); //Don't care about security for the sake of this proof-of-concept echo ""; google_qr($_SERVER['SCRIPT_URI']."?ns=".$key,200); ?>
window.location='?action='"); default: if ($_COOKIE['LogIn']) echo"You are logged in as {$_COOKIE['LogIn']}.

Note the log-in cookie expires after a day - on your average social networking site, people usually tick 'keep me logged in'.

Log out"; else echo "You are not logged in.

Log in via user name

Log in via QR code"; } function google_qr($url,$size ='150',$EC_level='L',$margin='0'){ $url = urlencode($url); echo 'QR code'; } ?>