Advertisement
Guest User

R33D3M33R

a guest
Oct 14th, 2008
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.46 KB | None | 0 0
  1. <?php
  2. function assign_rand_value($num)
  3. {
  4. // accepts 1 - 36
  5.   switch($num)
  6.   {
  7.     case "1":
  8.      $rand_value = "a";
  9.     break;
  10.     case "2":
  11.      $rand_value = "b";
  12.     break;
  13.     case "3":
  14.      $rand_value = "c";
  15.     break;
  16.     case "4":
  17.      $rand_value = "d";
  18.     break;
  19.     case "5":
  20.      $rand_value = "e";
  21.     break;
  22.     case "6":
  23.      $rand_value = "f";
  24.     break;
  25.     case "7":
  26.      $rand_value = "g";
  27.     break;
  28.     case "8":
  29.      $rand_value = "h";
  30.     break;
  31.     case "9":
  32.      $rand_value = "i";
  33.     break;
  34.     case "10":
  35.      $rand_value = "j";
  36.     break;
  37.     case "11":
  38.      $rand_value = "k";
  39.     break;
  40.     case "12":
  41.      $rand_value = "l";
  42.     break;
  43.     case "13":
  44.      $rand_value = "m";
  45.     break;
  46.     case "14":
  47.      $rand_value = "n";
  48.     break;
  49.     case "15":
  50.      $rand_value = "o";
  51.     break;
  52.     case "16":
  53.      $rand_value = "p";
  54.     break;
  55.     case "17":
  56.      $rand_value = "q";
  57.     break;
  58.     case "18":
  59.      $rand_value = "r";
  60.     break;
  61.     case "19":
  62.      $rand_value = "s";
  63.     break;
  64.     case "20":
  65.      $rand_value = "t";
  66.     break;
  67.     case "21":
  68.      $rand_value = "u";
  69.     break;
  70.     case "22":
  71.      $rand_value = "v";
  72.     break;
  73.     case "23":
  74.      $rand_value = "w";
  75.     break;
  76.     case "24":
  77.      $rand_value = "x";
  78.     break;
  79.     case "25":
  80.      $rand_value = "y";
  81.     break;
  82.     case "26":
  83.      $rand_value = "z";
  84.     break;
  85.     case "27":
  86.      $rand_value = "0";
  87.     break;
  88.     case "28":
  89.      $rand_value = "1";
  90.     break;
  91.     case "29":
  92.      $rand_value = "2";
  93.     break;
  94.     case "30":
  95.      $rand_value = "3";
  96.     break;
  97.     case "31":
  98.      $rand_value = "4";
  99.     break;
  100.     case "32":
  101.      $rand_value = "5";
  102.     break;
  103.     case "33":
  104.      $rand_value = "6";
  105.     break;
  106.     case "34":
  107.      $rand_value = "7";
  108.     break;
  109.     case "35":
  110.      $rand_value = "8";
  111.     break;
  112.     case "36":
  113.      $rand_value = "9";
  114.     break;
  115.   }
  116. return $rand_value;
  117. }
  118.  
  119. function get_rand_id($length)
  120. {
  121.   if($length>0)
  122.   {
  123.   $rand_id="";
  124.    for($i=1; $i<=$length; $i++)
  125.    {
  126.    mt_srand((double)microtime() * 1000000);
  127.    $num = mt_rand(1,36);
  128.    $rand_id .= assign_rand_value($num);
  129.    }
  130.   }
  131. return $rand_id;
  132. }
  133.  
  134.  
  135.  
  136. session_start();
  137. if(isset($_POST['submit'])) {
  138. include("db.php");
  139. $ime = mysql_real_escape_string($_POST['ime']);
  140. $geslo = mysql_real_escape_string($_POST['geslo']);
  141. if(strlen($ime) == 0 || strlen($geslo) == 0) {
  142. echo '<script type="text/javascript">alert(1);window.location.href="Log.php";</script>';
  143. die("No action Jackson :P");
  144. }
  145. else {
  146. $geslornd = '';
  147. if(isset($_COOKIE['g'])) {
  148. $geslornd = ' value="******"';
  149. $rand = mysql_real_escape_string($_COOKIE['g']);
  150. $sql = "SELECT `ime` FROM `uporabniki` WHERE `ime` LIKE '$ime' AND `rand` LIKE '$rand'";
  151. $q = mysql_query($sql) or die('<script type="text/javascript">alert(2);window.location.href="Log.php";</script>');
  152. if(mysql_num_rows($q) == 0) {
  153. echo '<script type="text/javascript">alert(\'Napa&#269;no geslo/uporabni&#353;ko ime\');window.location.href="Log.php";</script>';
  154. die("No action Jackson :P");
  155. }
  156. else {
  157. $myrow = mysql_fetch_array($q);
  158. $_SESSION['ime'] = $myrow['ime'];
  159. }
  160. }
  161. else {
  162. $sql = "SELECT `ime` FROM `uporabniki` WHERE `ime` LIKE '$ime' AND `geslo` LIKE '$geslo'";
  163. $q = mysql_query($sql) or die('<script type="text/javascript">alert(4);window.location.href="Log.php";</script>');
  164. if(mysql_num_rows($q) == 0) {
  165. echo '<script type="text/javascript">alert(\'Napa&#269;no geslo/uporabni&#353;ko ime\');window.location.href="Log.php";</script>';
  166. die("No action Jackson :P");
  167. }
  168. else {
  169. $myrow = mysql_fetch_array($q);
  170. $_SESSION['ime'] = $myrow['ime'];
  171. }
  172. if(isset($_POST['z'])) {
  173. $rand = get_rand_id(10);
  174. $sql = "UPDATE `uporabniki` SET `rand`='$rand' WHERE `ime` LIKE '$ime'";
  175. $z = mysql_query($sql) or die();
  176. setcookie('g',$rand,time()+60*60*24*30);
  177. }
  178. }
  179. }
  180. }
  181.  
  182. if(isset($_COOKIE['g'])) {
  183. $geslornd = ' value="******"';
  184. }
  185.  
  186. if(isset($_POST['suxit'])) {
  187. session_unset();
  188. session_destroy();
  189. }
  190. ?>
  191. <script>
  192. function getCookie(name) {
  193.          var dc = document.cookie;
  194.          var prefix = name + "=";
  195.          var begin = dc.indexOf("; " + prefix);
  196.          if (begin == -1) {
  197.          begin = dc.indexOf(prefix);
  198.          if (begin != 0) return null;
  199.          } else
  200.          begin += 2;
  201.          var end = document.cookie.indexOf(";", begin);
  202.          if (end == -1)
  203.          end = dc.length;
  204.          return unescape(dc.substring(begin + prefix.length, end));
  205.          }
  206. function deleteCookie(name, path, domain) {
  207.          if (getCookie(name)) {
  208.          document.cookie = name + "=" +
  209.          ((path) ? "; path=" + path : "") +
  210.          ((domain) ? "; domain=" + domain : "") +
  211.          "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  212.          }
  213. }
  214. </script>
  215. <?php
  216.  
  217. if(!isset($_SESSION['ime'])) {
  218. echo '<form action="Log.php" method="post">';
  219. echo 'Ime: <input name="ime" type="text" size="40"><br>';
  220. echo 'Geslo: <input name="geslo" type="password" size="40"'.$geslornd.'><br>';
  221. echo 'Zapomni: <input type="checkbox" checked name="z">';
  222. echo '<input type="submit" name="submit" value="Login"> | <input type="button" value="Registriraj" onclick="document.location.href=\'Reg.php\'">  | <input type="button" value="Bri&#353;i cookie" onclick="deleteCookie(\'g\');document.location.href=\'Log.php\'">';
  223. echo '</form>';
  224. }
  225. else {
  226. echo '<form action="Log.php" method="post">';
  227. echo 'Registriran kot ' . $_SESSION['ime'];
  228. echo '<input type="submit" name="suxit" value="Logout"> | <input type="button" value="Bri&#353;i cookie" onclick="deleteCookie(\'g\')">';
  229. echo '</form>';
  230. }
  231. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement