Advertisement
ShadyPL

Save IP in PHP (looks like kwejk, demotywatory etc.)

Jan 28th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 KB | None | 0 0
  1. <?php
  2. ////////////////////////////////////////////////////////////
  3. //////// script created by Shady on GNU/GPL license ////////
  4. ////////  gg 15530223 | mail izzypjchamp@gmail.com  ////////
  5. ////////////////////////////////////////////////////////////
  6.  
  7. /**************** DATABASE : idiots *****************
  8. field: id (int 11) auto_increment PRIMARY
  9. field: time (int 11)
  10. field: ip (varchar 18)
  11. field: agent (text)
  12. *****************************************************/
  13.  
  14. $title = 'Image title';
  15. $srcimg = 'http://site.com/image.png';
  16.  
  17. echo '
  18. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  19. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  20.     <head>
  21.         <title>'.$title.'</title>
  22.         <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  23.         <meta http-equiv="content-language" content="en" />
  24.         <meta name="description" content="Śmieszne obrazki i codzienna dawka humoru!" />
  25.         <meta name="keywords" content="kwejk, demotywatory, obrazki, memy" />
  26.         <meta http-equiv="pragma" content="no-cache" />
  27.         <meta name="robots" content="none" />
  28.     </head>
  29. <body>
  30. <img src="'.$srcimg.'" alt="'.$title.'" title="'.$title.'" />
  31. ';
  32.  
  33. function true_ip() {
  34.     if(isset($_SERVER['HTTP_CLIENT_IP'])) $ip = $_SERVER['HTTP_CLIENT_IP'];
  35.     elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  36.     else $ip = $_SERVER['REMOTE_ADDR'];
  37.  
  38.     return $ip;
  39. }
  40.  
  41. try {
  42.     $db = new PDO ('mysql:host=localhost;dbname=base_name;encoding=utf8', 'user', 'pass');
  43.     $db -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  44.  
  45.     $db -> exec("INSERT INTO idiots (time, ip, agent) VALUES ('".date('d.m.y H:i:s')."', '".true_ip()."', '".$_SERVER['HTTP_USER_AGENT']."')");
  46.     }
  47. catch(PDOException $error) {
  48.     exit('Error communicating with the database!<br/>'.$error);
  49.     }
  50. ?>
  51. </body>
  52. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement