Guest User

Untitled

a guest
Oct 31st, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.62 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. echo  $_SESSION['password'];
  5. echo  $_SESSION['username'];
  6.  
  7.  
  8. include_once "/scripts/connect_to_mysql.php"; // Connect to the database
  9. // Check the HTTP_REFERER for light level security
  10. $ref = parse_url($_SERVER['HTTP_REFERER']);
  11. $host = $ref["host"];
  12. if ($host != "localhost") {
  13.     echo "This is some screwed up error even the web developer of this site doesnt understand :(";
  14.     exit();
  15. }
  16. // Be sure the user session vars are all set
  17. if(!isset($_SESSION['username']) || !isset($_SESSION['password'])) {
  18.     echo "Your session has timed out.";
  19.     exit(); // This you will want to handle more smoothly
  20. }
  21. // Be sure all form variables are present to proceed
  22. if (!isset($_POST['post_type']) || !isset($_POST['post_body']) || !isset($_POST['fsID']) || !isset($_POST['fsTitle']) || !isset($_POST['uid']) || !isset($_POST['upass'])) {
  23.     echo "Important variables from the form are missing,reloading the page will help :D";
  24.     exit();
  25. }
  26. // Filter all of the common variables
  27. $post_type = $_POST['post_type'];
  28. $post_body = $_POST['post_body'];
  29. $post_body = nl2br(htmlspecialchars($post_body));
  30. $post_body = mysql_real_escape_string($post_body);
  31. $forum_section_id = preg_replace('#[^0-9]#i', '', $_POST['fsID']);
  32. $forum_section_title = preg_replace('#[^A-Za-z 0-9]#i', '', $_POST['fsTitle']);
  33. $member_id = preg_replace('#[^0-9]#i', '', $_POST['uid']);
  34. $post_author = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION['username']);
  35. $member_password = mysql_real_escape_string($_POST['upass']);
  36. // Be sure the posted variables match the user's session variables
  37. if ($_SESSION['id'] != $member_id || $_SESSION['password'] != $member_password) {
  38.  
  39. echo $_SESSION['id'];
  40. echo $_member_id;
  41. echo $_SESSION['password'];
  42. echo $member_password
  43. echo $_POST['uid'];
  44. echo $_POST['upass'];
  45.  
  46.     echo "Your id and/or password is a mismatch weenis";
  47.     exit();
  48. }
  49. // Check the database to be sure that their ID, password, and email session variables all match in the database
  50. $u_name = mysql_real_escape_string($_SESSION['username']);
  51. $u_pass = mysql_real_escape_string($_SESSION['password']);
  52. $sql = mysql_query("SELECT * FROM users WHERE id='$id' AND username='$username' AND email='$email' AND password='$password'");
  53. $numRows = mysql_num_rows($sql);
  54. if ($numRows < 0) {
  55.         echo "ERROR: You do not exist in the system weenis";
  56.         exit();
  57. }
  58. // Check the database to be sure that this forum section exists
  59. $sql = mysql_query("SELECT * FROM forum_sections WHERE id='$forum_section_id' AND title='$forum_section_title'");
  60. $numRows = mysql_num_rows($sql);
  61. if ($numRows < 0) {
  62.         echo "ERROR: That forum section deos not exist lol";
  63.         exit();
  64. }
  65. // Prevent this member from posting more than 30 times in one day
  66. $sql = mysql_query("SELECT id FROM forum_posts WHERE post_author_id='$member_id' AND DATE(date_time) = DATE(NOW()) LIMIT 32");
  67. $numRows = mysql_num_rows($sql);
  68. if ($numRows > 30) {
  69.     echo "ERROR: You can post only 30 times per day. Your maximum has been reached.";
  70.     exit();
  71. }
  72. // Add this post to the database now. The query depends on the "post_type" value
  73. // Only if the post_type is "a" ///////////////////////////////////////////////////////////////////////////////////
  74. if ($post_type == "a") {
  75.     $post_title = preg_replace('#[^A-za-z0-9 ?!.,]#i', '', $_POST['post_title']);  
  76.     if ($post_title == "") { echo "The Topic Title is missing weenis"; exit(); }
  77.     if (strlen($post_title) < 10) { echo "Your Topic Title is less than 10 characters"; exit(); }
  78.     $sql = mysql_query("INSERT INTO forum_posts (post_author, post_author_id, date_time, type, section_title, section_id, thread_title, post_body)
  79.     VALUES('$post_author','$member_id',now(),'a','$forum_section_title','$forum_section_id','$post_title','$post_body')") or die (mysql_error());
  80.     $this_id = mysql_insert_id();
  81.     //$sql = mysql_query("UPDATE forum_posts SET otid='$this_id' WHERE id='$this_id'");
  82.     header("location: view_thread.php?id=$this_id");
  83.     exit();
  84. }
  85. // Only if the post_type is "b" ////////////////////////////////////////////////////////////////////////////////////
  86. if ($post_type == "b") {
  87.     $this_id = preg_replace('#[^0-9]#i', '', $_POST['tid']);
  88.     if ($this_id == "") { echo "The thread ID is missing weenis"; exit(); }
  89.     $sql = mysql_query("INSERT INTO forum_posts (post_author, post_author_id, otid, date_time, type, post_body) VALUES('$post_author','$member_id','$this_id',now(),'b','$post_body')") or die (mysql_error());
  90.     $post_body = stripslashes($post_body);
  91.     echo $post_body;
  92.     // YOU CAN CHOOSE TO EMAIL ALERT ALL OF THE PEOPLE THAT ARE PART OF THIS THREAD
  93.     // AT THIS POINT. (JUST BE SURE YOU DO NOT EMAIL THE PERSON WHO JUST LEFT THE RESPONSE)
  94. }
  95. ?>
Add Comment
Please, Sign In to add comment