Advertisement
Guest User

Untitled

a guest
Apr 18th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. <?PHP
  2. //Retrieves the sessions variables.
  3. session_start();
  4.  
  5. //Allows the page to utilise code and variables within "processerror.php".
  6. //Overrides error handler.
  7. include 'processerror.php';
  8. set_error_handler("logmyerror");
  9.  
  10. //collect stat data
  11. $page = $_SERVER['PHP_SELF'];
  12. $ip = $_SERVER['REMOTE_ADDR'];
  13. $user = "";
  14. logstats($page, $ip, $username);
  15.  
  16. // set database server access variables:
  17. $host = "localhost";
  18. $user = "root";
  19. $pass = "09k6CcsGxBq7p";
  20. $db = "wssbulletinboarddatabase";
  21.  
  22. // open connection
  23. $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
  24.  
  25. //Select the database stored in teh variable "$db". If this fails then end the script and dispaly the text "Unable to select database!".
  26. mysql_select_db($db) or die ("Unable to select database!");
  27.  
  28. //This creates a MySQL query and stores the query into the veriable "$query".
  29. //This query selects all the records from the table "users" within the database "wssbulletinboarddatabase" where the value of the data in the coulmn "UserName" is the same as the valued stored in the session variable "user".
  30. $query = "SELECT * FROM `wssbulletinboarddatabase`.`users` WHERE UserName='" . $_SESSION["user"] . "'";
  31.  
  32. //This executes the query and stores the data into the $results varible. If the query was not executed then the script is stopped and an error occurs.
  33. $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
  34.  
  35. //This if statement checks to see if the number of rows retreived from the query is the same as 1.
  36. if (mysql_num_rows($result) == 1){
  37. //If true then store the record into the variable $newpwd
  38. $newpwd = mysql_fetch_row($result);
  39. //This if statement checks to see if the value stored in the third column of teh record is the same as the valued stored in te post variable "txtOldPassword".
  40. if ($newpwd[2] == $_POST["txtOldPassword"])
  41. {
  42. //If true then nothing happens and the rest of the script continues to run.
  43. }
  44. else{
  45. //If false then trigger an error saying the old password does not match and redirect the user top the page "changepassword.php".
  46. trigger_error("Old password does not match.",1024);
  47. header("Location: changepassword.php");
  48. }
  49. }
  50. else { //If no rows were returned, then trigger an error and redirect the user to the page "changepassword.php".
  51. trigger_error("Could not find user in records.",1024);
  52. header("Location: changepassword.php");
  53. }
  54.  
  55. //This creates a MySQL query and stores the query into the veriable "$query2".
  56. //This query updates data that is stored within the table "users" within the database "wssbulletinboarddatabase". This query sets the value of the data within the "Password" column to the value that is stored within the post variable "$_POST["txtNewPassword"]". This will be set on the record where the value within the column "UserName" of that record is the same as the value of the "$_SESSION["user"]" session variable.
  57. $query2 = "UPDATE `wssbulletinboarddatabase`.`users` SET Password='" . $_POST["txtNewPassword"] . "' WHERE UserName='" . $_SESSION["user"] . "'";
  58.  
  59. // execute query
  60. if (mysql_query($query2)){
  61. //if the query is executed then redirect the user to the page "index.php".
  62. header("Location:index.php");
  63. }
  64. else {
  65. //If the query fails then store error information into the session variable "$_SESSION["usrerrmsg"]" and redirect the user to the page "changepassword.php".
  66. $_SESSION["usrerrmsg"] = mysql_error();
  67. header("Location: changepassword.php");
  68. }
  69.  
  70. //This clears the values stored within the variable "$result".
  71. mysql_free_result($result);
  72.  
  73. // close connection
  74. mysql_close($connection);
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement