Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function assign_rand_value($num)
- {
- // accepts 1 - 36
- switch($num)
- {
- case "1":
- $rand_value = "a";
- break;
- case "2":
- $rand_value = "b";
- break;
- case "3":
- $rand_value = "c";
- break;
- case "4":
- $rand_value = "d";
- break;
- case "5":
- $rand_value = "e";
- break;
- case "6":
- $rand_value = "f";
- break;
- case "7":
- $rand_value = "g";
- break;
- case "8":
- $rand_value = "h";
- break;
- case "9":
- $rand_value = "i";
- break;
- case "10":
- $rand_value = "j";
- break;
- case "11":
- $rand_value = "k";
- break;
- case "12":
- $rand_value = "l";
- break;
- case "13":
- $rand_value = "m";
- break;
- case "14":
- $rand_value = "n";
- break;
- case "15":
- $rand_value = "o";
- break;
- case "16":
- $rand_value = "p";
- break;
- case "17":
- $rand_value = "q";
- break;
- case "18":
- $rand_value = "r";
- break;
- case "19":
- $rand_value = "s";
- break;
- case "20":
- $rand_value = "t";
- break;
- case "21":
- $rand_value = "u";
- break;
- case "22":
- $rand_value = "v";
- break;
- case "23":
- $rand_value = "w";
- break;
- case "24":
- $rand_value = "x";
- break;
- case "25":
- $rand_value = "y";
- break;
- case "26":
- $rand_value = "z";
- break;
- case "27":
- $rand_value = "0";
- break;
- case "28":
- $rand_value = "1";
- break;
- case "29":
- $rand_value = "2";
- break;
- case "30":
- $rand_value = "3";
- break;
- case "31":
- $rand_value = "4";
- break;
- case "32":
- $rand_value = "5";
- break;
- case "33":
- $rand_value = "6";
- break;
- case "34":
- $rand_value = "7";
- break;
- case "35":
- $rand_value = "8";
- break;
- case "36":
- $rand_value = "9";
- break;
- }
- return $rand_value;
- }
- function get_rand_id($length)
- {
- if($length>0)
- {
- $rand_id="";
- for($i=1; $i<=$length; $i++)
- {
- mt_srand((double)microtime() * 1000000);
- $num = mt_rand(1,36);
- $rand_id .= assign_rand_value($num);
- }
- }
- return $rand_id;
- }
- session_start();
- if(isset($_POST['submit'])) {
- include("db.php");
- $ime = mysql_real_escape_string($_POST['ime']);
- $geslo = mysql_real_escape_string($_POST['geslo']);
- if(strlen($ime) == 0 || strlen($geslo) == 0) {
- echo '<script type="text/javascript">alert(1);window.location.href="Log.php";</script>';
- die("No action Jackson :P");
- }
- else {
- $geslornd = '';
- if(isset($_COOKIE['g'])) {
- $geslornd = ' value="******"';
- $rand = mysql_real_escape_string($_COOKIE['g']);
- $sql = "SELECT `ime` FROM `uporabniki` WHERE `ime` LIKE '$ime' AND `rand` LIKE '$rand'";
- $q = mysql_query($sql) or die('<script type="text/javascript">alert(2);window.location.href="Log.php";</script>');
- if(mysql_num_rows($q) == 0) {
- echo '<script type="text/javascript">alert(\'Napačno geslo/uporabniško ime\');window.location.href="Log.php";</script>';
- die("No action Jackson :P");
- }
- else {
- $myrow = mysql_fetch_array($q);
- $_SESSION['ime'] = $myrow['ime'];
- }
- }
- else {
- $sql = "SELECT `ime` FROM `uporabniki` WHERE `ime` LIKE '$ime' AND `geslo` LIKE '$geslo'";
- $q = mysql_query($sql) or die('<script type="text/javascript">alert(4);window.location.href="Log.php";</script>');
- if(mysql_num_rows($q) == 0) {
- echo '<script type="text/javascript">alert(\'Napačno geslo/uporabniško ime\');window.location.href="Log.php";</script>';
- die("No action Jackson :P");
- }
- else {
- $myrow = mysql_fetch_array($q);
- $_SESSION['ime'] = $myrow['ime'];
- }
- if(isset($_POST['z'])) {
- $rand = get_rand_id(10);
- $sql = "UPDATE `uporabniki` SET `rand`='$rand' WHERE `ime` LIKE '$ime'";
- $z = mysql_query($sql) or die();
- setcookie('g',$rand,time()+60*60*24*30);
- }
- }
- }
- }
- if(isset($_COOKIE['g'])) {
- $geslornd = ' value="******"';
- }
- if(isset($_POST['suxit'])) {
- session_unset();
- session_destroy();
- }
- ?>
- <script>
- function getCookie(name) {
- var dc = document.cookie;
- var prefix = name + "=";
- var begin = dc.indexOf("; " + prefix);
- if (begin == -1) {
- begin = dc.indexOf(prefix);
- if (begin != 0) return null;
- } else
- begin += 2;
- var end = document.cookie.indexOf(";", begin);
- if (end == -1)
- end = dc.length;
- return unescape(dc.substring(begin + prefix.length, end));
- }
- function deleteCookie(name, path, domain) {
- if (getCookie(name)) {
- document.cookie = name + "=" +
- ((path) ? "; path=" + path : "") +
- ((domain) ? "; domain=" + domain : "") +
- "; expires=Thu, 01-Jan-70 00:00:01 GMT";
- }
- }
- </script>
- <?php
- if(!isset($_SESSION['ime'])) {
- echo '<form action="Log.php" method="post">';
- echo 'Ime: <input name="ime" type="text" size="40"><br>';
- echo 'Geslo: <input name="geslo" type="password" size="40"'.$geslornd.'><br>';
- echo 'Zapomni: <input type="checkbox" checked name="z">';
- echo '<input type="submit" name="submit" value="Login"> | <input type="button" value="Registriraj" onclick="document.location.href=\'Reg.php\'"> | <input type="button" value="Briši cookie" onclick="deleteCookie(\'g\');document.location.href=\'Log.php\'">';
- echo '</form>';
- }
- else {
- echo '<form action="Log.php" method="post">';
- echo 'Registriran kot ' . $_SESSION['ime'];
- echo '<input type="submit" name="suxit" value="Logout"> | <input type="button" value="Briši cookie" onclick="deleteCookie(\'g\')">';
- echo '</form>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement