PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/root/mysql_server/checkuserlog.php

https://gitlab.com/JLHasson/Wordflow
PHP | 174 lines | 109 code | 50 blank | 15 comment | 11 complexity | a0ef00e35d49f829291433704d59bc87 MD5 | raw file
  1. <?php
  2. session_start(); // Start Session First Thing
  3. // Force script errors and warnings to show on page in case php.ini file is set to not display them
  4. error_reporting(E_ALL);
  5. ini_set('display_errors', 0);
  6. //-----------------------------------------------------------------------------------------------------------------------------------
  7. include_once "mysql_server/connect_to_mysql.php"; // Connect to the database
  8. /*
  9. * Facebook Variables
  10. */
  11. $app_id = '';
  12. $app_secret = '';
  13. $facebook_redirect = "";
  14. require 'functions/bootstrap.php';
  15. require 'config/config.php';
  16. $config = config::get_instance();
  17. $database = $config->get('use_database');
  18. require "databases/" . $database . ".php";
  19. require "databases/crud.php";
  20. $dyn_www = $_SERVER['HTTP_HOST']; // Dynamic www.domainName available now to you in all of your scripts that include this file
  21. //------ CHECK IF THE USER IS LOGGED IN OR NOT AND GIVE APPROPRIATE OUTPUT -------
  22. $logOptions = ''; // Initialize the logOptions variable that gets printed to the page
  23. // If the session variable and cookie variable are not set this code runs
  24. if (!isset($_SESSION['idx'])) {
  25. if (!isset($_COOKIE['idCookie'])) {
  26. $logOptions = '<ul class="headerRightList">
  27. <li>
  28. <a href="http://' . $dyn_www . '/register.php">Sign Up Today!</a>
  29. </li>
  30. &nbsp;&nbsp; | &nbsp;&nbsp;
  31. <li>
  32. <a href="http://' . $dyn_www . '/login.php">Log In</a>
  33. </li>
  34. </ul> ';
  35. }
  36. }
  37. // If session ID is set for logged in user without cookies remember me feature set
  38. if (isset($_SESSION['idx'])) {
  39. $decryptedID = base64_decode($_SESSION['idx']);
  40. $id_array = explode("p3h9xfn8sq03hs2234", $decryptedID);
  41. $logOptions_id = $id_array[1];
  42. // Check if this user has any new PMs and construct which envelope to show
  43. $sql_pm_check = mysql_query("SELECT id FROM messaging WHERE to_id='$logOptions_id' AND opened='0' LIMIT 1");
  44. $num_new_pm = mysql_num_rows($sql_pm_check);
  45. if ($num_new_pm > 0) {
  46. $PM_envelope = '('.$num_new_pm.')';
  47. $PM_envelope_header = '<a href="inbox.php"><img src="images/header/hover-inbox.png" height="40px" border="0"/></a>';
  48. } else {
  49. $PM_envelope = '('.$num_new_pm.')';
  50. $PM_envelope_header = '<a href="inbox.php" ><img src="images/header/normal-inbox.png" height="40px" border="0"/></a>';
  51. }
  52. // Ready the output for this logged in user
  53. $logOptions = ' <ul class="headerRightList">
  54. <li>
  55. <a class="headerHomeLink" href="home.php">Home</a>
  56. </li>
  57. &nbsp;&nbsp; | &nbsp;&nbsp;
  58. <li>
  59. <a href="http://' . $dyn_www . '/profile.php?id=' . $logOptions_id . '">Profile</a>
  60. </li>
  61. &nbsp;&nbsp; | &nbsp;&nbsp;
  62. <div class="dc">
  63. <a href="#" onclick="return false">Account &nbsp; <img src="images/darr.gif" width="10" height="5" alt="Account Options" border="0"/></a>
  64. <ul>
  65. <li><a href="http://' . $dyn_www . '/edit_profile.php">Account Options</a></li>
  66. <li><a href="http://' . $dyn_www . '/inbox.php">Inbox '.$PM_envelope.'</a></li>
  67. <li><a href="http://' . $dyn_www . '/help.php">Help</a></li>
  68. <li><a href="http://' . $dyn_www . '/logout.php">Log Out</a></li>
  69. </ul>
  70. </div>
  71. </ul> ';
  72. } else if (isset($_COOKIE['idCookie'])) {// If id cookie is set, but no session ID is set yet, we set it below and update stuff
  73. $decryptedID = base64_decode($_COOKIE['idCookie']);
  74. $id_array = explode("nm2c0c4y3dn3727553", $decryptedID);
  75. $userID = $id_array[1];
  76. $userPass = $_COOKIE['passCookie'];
  77. // Get their user first name to set into session var
  78. $sql_uname = mysql_query("SELECT * FROM myMembers WHERE id='$userID' AND password='$userPass' LIMIT 1");
  79. $numRows = mysql_num_rows($sql_uname);
  80. if ($numRows == 0) {
  81. // Kill their cookies and send them back to homepage if they have cookie set but are not a member any longer
  82. setcookie("idCookie", '', time()-42000, '/');
  83. setcookie("passCookie", '', time()-42000, '/');
  84. header("location: welcome.php"); // << makes the script send them to any page we set
  85. exit();
  86. }
  87. while($row = mysql_fetch_array($sql_uname)){
  88. if($row = mysql_fetch_array($sql_uname)){
  89. extract($sql_uname);
  90. } else
  91. ?><script>location.reload();</script><?php
  92. echo $sql_uname;
  93. header("refresh: 0;");
  94. }
  95. $_SESSION['id'] = $userID; // now add the value we need to the session variable
  96. $_SESSION['idx'] = base64_encode("g4p3h9xfn8sq03hs2234$userID");
  97. $_SESSION['firstname'] = $firstname;
  98. $_SESSION['lastname'] = $lastname;
  99. $_SESSION['email'] = $useremail;
  100. $_SESSION['password'] = $userpass;
  101. /////////// Update Last Login Date Field /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  102. mysql_query("UPDATE myMembers SET last_log_date=now() WHERE id='$logOptions_id'");
  103. // Ready the output for this logged in user
  104. // Ready the output for this logged in user
  105. $logOptions = '<ul class="headerRightList">
  106. <li>
  107. <a class="headerHomeLink" href="home.php">Home</a>
  108. </li>
  109. <li>
  110. <a href="http://' . $dyn_www . '/profile.php?id=' . $logOptions_id . '">Profile</a>
  111. </li>
  112. <div class="dc">
  113. <a href="#" onclick="return false">Account &nbsp; <img src="images/darr.gif" width="5" height="5" alt="Account Options" border="0"/></a>
  114. <ul>
  115. <li><a href="http://' . $dyn_www . '/edit_profile.php">Account Options</a></li>
  116. <li><a href="http://' . $dyn_www . '/inbox.php">Inbox '.$PM_envelope.'</a></li>
  117. <li><a href="http://' . $dyn_www . '/help.php">Help</a></li>
  118. <li><a href="http://' . $dyn_www . '/logout.php">Log Out</a></li>
  119. </ul>
  120. </div>
  121. </ul> ';
  122. }
  123. ?>