daily pastebin goal
37%
SHARE
TWEET

Untitled

a guest Oct 17th, 2017 243 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /*
  4. In order for this script to work correctly, it
  5. must be named pm.php
  6.  
  7. Please note that in order to use this script, you
  8. will need a MySQL Database. To create the table,
  9. run this query on your database in phpMyAdmin.
  10.  
  11. CREATE TABLE `forum_question` (
  12. `id` int(4) NOT NULL auto_increment,
  13. `subject` varchar(255) NOT NULL default '',
  14. `message` longtext NOT NULL,
  15. `from` varchar(65) NOT NULL default '',
  16. `to` varchar(65) NOT NULL default '',
  17. `date` varchar(25) NOT NULL default '',
  18. PRIMARY KEY (`id`)
  19. ) TYPE=MyISAM AUTO_INCREMENT=1 ;
  20. */
  21.  
  22. // First retrieve the username
  23. session_start();
  24. $username = $_SESSION['myusername'];
  25.  
  26. // Check that the user is logged in. Customize the result as you please.
  27. if (!isset($_SESSION['myusername'])) {
  28.     die('Not Logged In');
  29. }
  30.  
  31. // Fill in the below variables with your MySQL info
  32. $db_host = 'localhost';
  33. $db_user = '';
  34. $db_pass = '';
  35. $db_name = '';
  36. $tbl_name = '';
  37.  
  38. // Make the database connection
  39. mysql_connect($db_host, $db_user, $db_pass) or die ('Cannot Connect To Database');
  40. mysql_select_db($db_name) or die ('Cannot Select Database');
  41.  
  42. // If a private message listing was requested
  43. if (!isset($_GET['act'])) {
  44.  
  45.     // Add a header. Customise as you please
  46.     echo "<h1>Private Messaging: Inbox</h1>";
  47.     echo "<a href=pm.php?act=compose>Compose</a><br>";
  48.  
  49.     // Begin the table. Customize as you please.
  50.     echo "<table width=100%><tr>";
  51.     echo "<td>Subject</td>";
  52.     echo "<td>From</td>";
  53.     echo "<td>Date</td>";
  54.     echo "</tr>";
  55.  
  56.     // Perform the listing query
  57.     $result = mysql_query("SELECT * FROM ".$tbl_name." WHERE to='".$username."';");
  58.  
  59.     // Start looping. You can customize the result as you please, but leave the $row intact
  60.     while($row = mysql_fetch_array($result)){
  61.         echo "<tr>";
  62.         echo "<td><a href=pm.php?act=read&id=".$row['id'].">".$row['subject']."</a></td>";
  63.         echo "<td>".$row['from']."</td>";
  64.         echo "<td>".$row['date']."</td>";
  65.         echo "</tr>";
  66.     }
  67.  
  68.     // End the table
  69.     echo "</table>";
  70.  
  71. // If the user requested to read a PM
  72. }elseif ($_GET['act'] == 'read') {
  73.  
  74.     // Add a header. Customise as you please
  75.     echo "<h1>Private Messaging: Read</h1>";
  76.     echo "<a href=pm.php>Back to Inbox</a><br>";
  77.  
  78.     // Begin the table. Customize as you please.
  79.     echo "<table width=100%>";
  80.  
  81.     // Perform the reading query
  82.     $result = mysql_query("SELECT * FROM ".$tbl_name." WHERE id='".$_GET['id']."';");
  83.  
  84.     // Start looping. You can customize the result as you please, but leave the $row intact
  85.     while($row = mysql_fetch_array($result)){
  86.         echo "<tr>";
  87.         echo "<td>From</td><td>".$row['from']."</td>";
  88.         echo "<td>Date</td><td>".$row['date']."</td>";
  89.         echo "<td>Subject</td><td><b>".$row['subject']."</b></td>";
  90.         echo "<td>Message</td><td>".$row['message']."</td>";
  91.         echo "</tr>";
  92.     }
  93.  
  94.     // End the table
  95.     echo "</table>";
  96.  
  97. // If the user requested to compose a PM
  98. }elseif ($_GET['act'] == 'compose') {
  99.  
  100.     // Add a header. Customise as you please
  101.     echo "<h1>Private Messaging: Compose</h1>";
  102.     echo "<a href=pm.php>Back to Inbox</a><br>";
  103.  
  104.     // Echo the form parts. Customize as you please.
  105.     echo "<form method=post action=pm.php?act=send>";
  106.     echo "Recipient: <input type=name name=to><br>";
  107.     echo "Subject: <input type=subject name=subject>";
  108.     echo "<p><textarea name=message></textarea></p>";
  109.     echo "</form>";
  110.  
  111. // If the user requested to send a PM
  112. }elseif ($_GET['act'] == 'send') {
  113.  
  114.     // Generate an ID
  115.     $id = date('mdHis');
  116.  
  117.     // Generate the date
  118.     $date = date('h:iA l jS F Y');
  119.  
  120.     // Perform the query
  121.     mysql_query("INSERT INTO `".$tbl_name."` VALUES (".$id.", '".$_POST['subject']."', '".$_POST
  122.  
  123. ['message']."', '".$username."', '".$_POST['to']."', '".$date."');") or die ('Could Not Send!');
  124.  
  125.     // Finished. Customize this as you please.
  126.     echo "Sent.";
  127.  
  128. }else{
  129.     die('Bad Request');
  130. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top