Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. <?php
  2. $dbusername="aaa";
  3. $dbpassword="aaa";
  4. $database="aaa";
  5.  
  6. try {
  7. $dbh = new PDO('mysql:host=localhost;dbname=aaa', $dbusername, $dbpassword);
  8. } catch (PDOException $e) {
  9. echo "connection failed: " . $e->getMessage();
  10. }
  11.  
  12. function log_event($data, $dbh) {
  13. $log = $dbh->prepare("INSERT INTO events (uid1, uid2, type) VALUES (?, ?, ?)");
  14. $log->execute($data);
  15. }
  16.  
  17. function isSetAndNonZero ($arg) {
  18. if (isset($arg) and is_numeric($arg) and $arg != 0) {
  19. return true;
  20. } else {
  21. return false;
  22. }
  23. }
  24.  
  25. function verifyGroup($dbh, $uid) {
  26. $g = $dbh->prepare("SELECT * FROM users WHERE uid = :uid LIMIT 1");
  27. $g->bindParam(':uid', $uid, PDO::PARAM_STR);
  28. if ($g->execute()) {
  29. $udata = $g->fetch();
  30. $_SESSION['usergroup'] = $udata['usergroup'];
  31. } else { echo "error"; }
  32. }
  33.  
  34. function getRealIpAddr()
  35. {
  36. if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
  37. {
  38. $ip=$_SERVER['HTTP_CLIENT_IP'];
  39. }
  40. elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
  41. {
  42. $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  43. }
  44. else
  45. {
  46. $ip=$_SERVER['REMOTE_ADDR'];
  47. }
  48. return $ip;
  49. }
  50.  
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement