Advertisement
Null_Cat

Pastebin.php

Nov 21st, 2018
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.24 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <!-- An open-source example of using the Pastebin API in PHP and HTML5.
  5. This is the main homepage, allowing users to login and create posts. If they are logged in, they have access to private posts and get a list of their own posts.
  6. This will be connected to other PHP files, listed below when they are posted:
  7. formUserId.php: https://pastebin.com/Y0ZAtddd
  8. removeCookie.php: https://pastebin.com/yTES7RYs
  9. Testing.php: https://pastebin.com/iZUEDFfX
  10. -->
  11.  
  12.   <head>
  13.     <title>Pastebin Test</title>
  14.     <meta charset="UTF-8">
  15.   </head>
  16.   <body>
  17. <h1>
  18.   Pastebin.com API
  19.     </h1>
  20.     <h2>
  21.       Login with your account here
  22.     </h2>
  23.     <form id="loginform" action="formUserId.php" method="post">
  24.       Username:<input type="text" name="user" id="user" required><br>
  25.       Password:<input type="password" name="pass" id="pass" required><br>
  26.       <input type="submit" value="Log-In">
  27.     </form>
  28.     <p>
  29.       <strong>Note:</strong>
  30.       By logging in, a cookie will be set using PHP called "userid", which will hold the User ID being used.
  31.       This cookie will expire in 1 hour.
  32.     </p>
  33.     <?php
  34.     if(!isset($_COOKIE["userid"])) {
  35.       echo "<p>There is no current cookie.</p>";
  36.     } else {
  37.       echo ("<p>The currently stored userid is: " . $_COOKIE["userid"] . "</p>");
  38.       echo "\n<p>If you would like to delete this cookie, please click <a href='/removecookie.php'>here</a>.</p>";
  39.       $api_dev_key      = '';
  40. $api_user_key       = $_COOKIE["userid"];
  41. $url            = 'https://pastebin.com/api/api_post.php';
  42. $ch             = curl_init($url);
  43.  
  44. curl_setopt($ch, CURLOPT_POST, true);
  45. curl_setopt($ch, CURLOPT_POSTFIELDS, 'api_option=userdetails&api_user_key='.$api_user_key.'&api_dev_key='.$api_dev_key.'');
  46. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  47. curl_setopt($ch, CURLOPT_VERBOSE, 1);
  48. curl_setopt($ch, CURLOPT_NOBODY, 0);
  49.  
  50. $response       = curl_exec($ch);
  51.      
  52. preg_match_all('/<user_avatar_url>(.*?)<\/user_avatar_url>/s', $response, $matches);
  53. $imgMatch = implode("",$matches[1]);
  54.       echo "<img src='$imgMatch'>";
  55.      
  56.       preg_match_all('/<user_name>(.*?)<\/user_name>/s', $response, $matches);
  57. $nameMatch = implode("",$matches[1]);
  58.       echo "<p><b>$nameMatch</b></p>";
  59.      
  60.     }
  61.     ?>
  62.    
  63.     <p>
  64.       If you want to sign-up, click <a href="https://pastebin.com/signup" target="_blank">here</a>.</p>
  65.     <h2>
  66.       Form a Paste Below
  67.     </h2>
  68.     <form action="Testing.php" method="post">
  69.      
  70. Paste Name: <input type="text" name="name" value="untitled" required><br>
  71.      
  72. Exposure:<select name="exposure" required>
  73.       <option value="0" selected>Public</option>
  74.       <option value="1">Unlisted</option>
  75.       <option value="2"
  76.               <?php
  77.               if (!isset($_COOKIE["userid"])) {
  78.                 echo "disabled>Private (Users Only)";
  79.               } else {
  80.                 echo ">Private";
  81.               }
  82.               ?>
  83.               </option>
  84.       </select><br>
  85.      
  86. Expiration:<select name="expire">
  87.       <option value="N" selected>Never</option>
  88.       <option value="10M">10 Minutes</option>
  89.       <option value="1H">1 Hour</option>
  90.       <option value="1D">1 Day</option>
  91.       <option value="1W">1 Week</option>
  92.       <option value="2W">2 Weeks</option>
  93.       <option value="1M">1 Month</option>
  94.       <option value="6M">6 Months</option>
  95.       <option value="1Y">1 Year</option>
  96.       </select><br>
  97.      
  98.       <?php
  99.               if (isset($_COOKIE["userid"])) {
  100.                 echo "Post as Guest: <select name='anon'>\n<option value='no' selected>No</option>\n<option value='yes'>Yes</option>\n</select><br>";
  101.               }
  102.               ?>
  103.      
  104. Type (text for none):<input type="text" name="file" value="text" required>(Info <a href="https://pastebin.com/api#5" target="_blank">here</a>.)<br>
  105.      
  106. Paste:<br>
  107.       <textarea name="paste" rows="10" cols="50" required></textarea><br>
  108. <input type="submit" value="Submit Paste">
  109. </form>
  110.     <?php
  111.     if (isset($_COOKIE["userid"])) {
  112.       $api_dev_key      = '';
  113. $api_user_key       = $_COOKIE["userid"];
  114. $api_results_limit  = '100';
  115. $url            = 'https://pastebin.com/api/api_post.php';
  116. $ch             = curl_init($url);
  117.  
  118. curl_setopt($ch, CURLOPT_POST, true);
  119. curl_setopt($ch, CURLOPT_POSTFIELDS, 'api_option=list&api_user_key='.$api_user_key.'&api_dev_key='.$api_dev_key.'&api_results_limit='.$api_results_limit.'');
  120. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  121. curl_setopt($ch, CURLOPT_VERBOSE, 1);
  122. curl_setopt($ch, CURLOPT_NOBODY, 0);
  123.  
  124. $responsetwo = curl_exec($ch);
  125.       $pastecount = substr_count($responsetwo,"<paste>");
  126.     echo "
  127.    <h1>\n
  128.      User's Pastes\n
  129.    </h1>\n
  130.    <style>\n
  131.    table, th, td {\n
  132.    border: 1px solid black;\n
  133.    border-collapse: collapse;\n
  134. }\n
  135.    </style>\n
  136.    
  137.    <table style='width:100%'>\n
  138.      <tr>\n
  139.        <th>Paste Name</th>\n
  140.        <th>Paste Format</th>\n
  141.        <th>Paste URL</th>\n
  142.      </tr>\n";
  143.       $pastesleft = $pastecount - 1;
  144.       while ($pastesleft != -1) {
  145.         $responsetwo = $GLOBALS["responsetwo"];
  146.        
  147.         preg_match_all('/<paste_title>(.*?)<\/paste_title>/s', $responsetwo, $matchestitle);
  148. $pastetitle = $matchestitle[1][$pastesleft];
  149.        
  150.         preg_match_all('/<paste_private>(.*?)<\/paste_private>/s', $responsetwo, $matchesexposure);
  151. $pasteexpose = $matchesexposure[1][$pastesleft];
  152.        
  153.         if ($pasteexpose == 0) {
  154.           $pasteexpose = "<span style='color:green'>Public</span>";
  155.         } elseif ($pasteexpose == 1) {
  156.           $pasteexpose = "<span style='color:yellow'>Unlisted";
  157.         } else {
  158.           $pasteexpose = "<span style='color:red'>Private</span>";
  159.         }
  160.         preg_match_all('/<paste_format_long>(.*?)<\/paste_format_long>/s', $responsetwo, $matchesformat);
  161. $pasteformat = $matchesformat[1][$pastesleft];
  162.         preg_match_all('/<paste_url>(.*?)<\/paste_url>/s', $responsetwo, $matchesurl);
  163. $pasteurl = $matchesurl[1][$pastesleft];
  164.        
  165.         echo "<tr>\n
  166.        <td>$pastetitle</td>\n
  167.        <td>$pasteformat</td>\n
  168.        <td>$pasteexpose</td>\n
  169.        <td><a href='$pasteurl' target='_blank'>pastebin.com</a></td>\n";
  170.         $pastesleft--;
  171.     }
  172.     echo"</table>";
  173.     }
  174.     ?>
  175.   </body>
  176. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement