vladgen

Untitled

Nov 14th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4.  
  5.  
  6. </head>
  7. <body>
  8.  
  9. <?php
  10. /* В базе new данных куда устанавливаете скрипт создаем таблицу short вида - CREATE TABLE IF NOT EXISTS short
  11. ( id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  12. url TEXT NOT NULL,
  13. short_key TEXT NOT NULL,
  14. PRIMARY KEY (id),
  15. KEY short_key (short_key)
  16. )
  17. ENGINE=InnoDB;*/
  18.  
  19. $url = htmlspecialchars($_POST['url']);
  20. if(empty($_POST['url'])){}
  21. if(empty($_POST['upload'])){}
  22. else {
  23. $con= mysql_connect('127.0.0.1','root','') or die ('error');
  24. if(!($con))
  25. echo ("Server Not connect");
  26. $db= mysql_select_db("new", $con)or die ('error');
  27. if(!($db))
  28. echo ("Database Not Select");
  29. @$first = mysql_fetch_assoc(mysql_query("SELECT * FROM short WHERE 'url' = '".$url."' "));
  30. if($first)
  31. {
  32. $second=[
  33. 'url'=>$first['url'],
  34. 'key'=>$first['short_key'],
  35. '$link'=>
  36. 'http://'.$_SERVER['HTTP_HOST'].'/'.$first['short_key']
  37. ];
  38.  
  39. }
  40. else{
  41.  
  42. /*Генерация адреса*/
  43.  
  44. function generate_name($length){
  45. $code = '';
  46. $symbols = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  47. for( $i = 0; $i < (int)$length; $i++ )
  48. {
  49. $num = rand(1, strlen($symbols));
  50. $code .= substr( $symbols, $num-1, 1 );
  51. }
  52. return $code;
  53. }
  54. $rand=rand(5, 25);
  55. $res=generate_name(6);
  56.  
  57. $con= mysql_connect('127.0.0.1','root','') or die ('error');
  58. if(!($con))
  59. echo ("Server Not connect");
  60. $db= mysql_select_db("new", $con)or die ('error');
  61. if(!($db))
  62. echo ("Database Not Select");
  63. mysql_query("INSERT INTO short(id,url,short_key) VALUES (NULL,'".$url."','".$rand.$res."')",$con);
  64. @$select= mysql_fetch_assoc(mysql_query("SELECT * FROM short WHERE url = '$url' "));
  65. $third=[
  66. 'url'=>$select['url'],
  67. 'key'=>$select['short_key'],
  68. '$link'=>'http://'.$_SERVER['HTTP_HOST'].'/'.$select['short_key']
  69. ];
  70.  
  71. echo "КОРОТКАЯ ССЫЛКА<br>";
  72. print_r($third['$link']);
  73.  
  74. echo "<br>";
  75. } //echo $result;
  76. echo "<br>";
  77. echo $url;
  78.  
  79. }
  80.  
  81.  
  82. ?>
  83.  
  84. <form enctype="multipart/form-data" action="" method="post" id="ajax_form" >
  85.  
  86. <font style="font-size: 150%;">Введите полный адрес:</font><br>
  87. <input type="text" name="url"><br>
  88. <input type="submit" name="upload" id="btn" value="Преобразовать"/>
  89. </form>
  90.  
  91.  
  92. <br>
  93.  
  94. <div id="result_form"></div>
  95. <!--<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
  96. <script type="text/javascript" src="ajax.js" >
  97. </script>-->
  98. </body>
  99. </html>
Add Comment
Please, Sign In to add comment