global_functions.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. //Functie om user variable te controlleren en te strippen
  3. function safeString($var){
  4. $TEMPSTRING = $var;
  5. $TEMPSTRING = strip_tags($TEMPSTRING);
  6. $TEMPSTRING = htmlspecialchars($TEMPSTRING);
  7. $TEMPSTRING = trim($TEMPSTRING);
  8. return $TEMPSTRING;
  9. }
  10. //Session management
  11. function destroySession(){
  12. setcookie('session', '', 0);
  13. }
  14. function setSession($session_id){
  15. setcookie('session', base64_encode($session_id), time()+60*60*24*365);
  16. }
  17. function getSession(){
  18. if(isset($_COOKIE['session'])){
  19. return base64_decode($_COOKIE['session']);
  20. }
  21. else{
  22. return false;
  23. }
  24. }
  25. function isSession(){
  26. return isset($_COOKIE['session']);
  27. }
  28. function reDirect($url){
  29. echo '<script type="text/javascript">window.location.href = \''.$url.'\';</script> ';
  30. }
  31. //Log out
  32. function logout($error){
  33. global $mysqli;
  34. if($error!='verify' && $error!='expired' && $error!='email' && $error!='nomail' && $error!='forgot'){
  35. if($error!='nosession'){
  36. $session_id = $_SESSION['id'];
  37. if(isset($session_id)){
  38. if($stmt1 = $mysqli -> prepare("UPDATE `login` SET `ip`=?, `session_id`=? WHERE `session_id`=? ")) {
  39. $stmt1 -> bind_param('sss', "", "", $session_id);
  40. $stmt1 -> execute();
  41. $stmt1 -> close();
  42. }
  43. }
  44. }
  45. destroySession();
  46. }
  47. $link = "login.php?" . $error;
  48. die(header("Location: $link"));
  49. }