Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <!-- An open-source example of using the Pastebin API in PHP and HTML5.
- 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.
- This will be connected to other PHP files, listed below when they are posted:
- formUserId.php: https://pastebin.com/Y0ZAtddd
- removeCookie.php: https://pastebin.com/yTES7RYs
- Testing.php: https://pastebin.com/iZUEDFfX
- -->
- <head>
- <title>Pastebin Test</title>
- <meta charset="UTF-8">
- </head>
- <body>
- <h1>
- Pastebin.com API
- </h1>
- <h2>
- Login with your account here
- </h2>
- <form id="loginform" action="formUserId.php" method="post">
- Username:<input type="text" name="user" id="user" required><br>
- Password:<input type="password" name="pass" id="pass" required><br>
- <input type="submit" value="Log-In">
- </form>
- <p>
- <strong>Note:</strong>
- By logging in, a cookie will be set using PHP called "userid", which will hold the User ID being used.
- This cookie will expire in 1 hour.
- </p>
- <?php
- if(!isset($_COOKIE["userid"])) {
- echo "<p>There is no current cookie.</p>";
- } else {
- echo ("<p>The currently stored userid is: " . $_COOKIE["userid"] . "</p>");
- echo "\n<p>If you would like to delete this cookie, please click <a href='/removecookie.php'>here</a>.</p>";
- $api_dev_key = '';
- $api_user_key = $_COOKIE["userid"];
- $url = 'https://pastebin.com/api/api_post.php';
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, 'api_option=userdetails&api_user_key='.$api_user_key.'&api_dev_key='.$api_dev_key.'');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_VERBOSE, 1);
- curl_setopt($ch, CURLOPT_NOBODY, 0);
- $response = curl_exec($ch);
- preg_match_all('/<user_avatar_url>(.*?)<\/user_avatar_url>/s', $response, $matches);
- $imgMatch = implode("",$matches[1]);
- echo "<img src='$imgMatch'>";
- preg_match_all('/<user_name>(.*?)<\/user_name>/s', $response, $matches);
- $nameMatch = implode("",$matches[1]);
- echo "<p><b>$nameMatch</b></p>";
- }
- ?>
- <p>
- If you want to sign-up, click <a href="https://pastebin.com/signup" target="_blank">here</a>.</p>
- <h2>
- Form a Paste Below
- </h2>
- <form action="Testing.php" method="post">
- Paste Name: <input type="text" name="name" value="untitled" required><br>
- Exposure:<select name="exposure" required>
- <option value="0" selected>Public</option>
- <option value="1">Unlisted</option>
- <option value="2"
- <?php
- if (!isset($_COOKIE["userid"])) {
- echo "disabled>Private (Users Only)";
- } else {
- echo ">Private";
- }
- ?>
- </option>
- </select><br>
- Expiration:<select name="expire">
- <option value="N" selected>Never</option>
- <option value="10M">10 Minutes</option>
- <option value="1H">1 Hour</option>
- <option value="1D">1 Day</option>
- <option value="1W">1 Week</option>
- <option value="2W">2 Weeks</option>
- <option value="1M">1 Month</option>
- <option value="6M">6 Months</option>
- <option value="1Y">1 Year</option>
- </select><br>
- <?php
- if (isset($_COOKIE["userid"])) {
- echo "Post as Guest: <select name='anon'>\n<option value='no' selected>No</option>\n<option value='yes'>Yes</option>\n</select><br>";
- }
- ?>
- 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>
- Paste:<br>
- <textarea name="paste" rows="10" cols="50" required></textarea><br>
- <input type="submit" value="Submit Paste">
- </form>
- <?php
- if (isset($_COOKIE["userid"])) {
- $api_dev_key = '';
- $api_user_key = $_COOKIE["userid"];
- $api_results_limit = '100';
- $url = 'https://pastebin.com/api/api_post.php';
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_POST, true);
- 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.'');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_VERBOSE, 1);
- curl_setopt($ch, CURLOPT_NOBODY, 0);
- $responsetwo = curl_exec($ch);
- $pastecount = substr_count($responsetwo,"<paste>");
- echo "
- <h1>\n
- User's Pastes\n
- </h1>\n
- <style>\n
- table, th, td {\n
- border: 1px solid black;\n
- border-collapse: collapse;\n
- }\n
- </style>\n
- <table style='width:100%'>\n
- <tr>\n
- <th>Paste Name</th>\n
- <th>Paste Format</th>\n
- <th>Paste URL</th>\n
- </tr>\n";
- $pastesleft = $pastecount - 1;
- while ($pastesleft != -1) {
- $responsetwo = $GLOBALS["responsetwo"];
- preg_match_all('/<paste_title>(.*?)<\/paste_title>/s', $responsetwo, $matchestitle);
- $pastetitle = $matchestitle[1][$pastesleft];
- preg_match_all('/<paste_private>(.*?)<\/paste_private>/s', $responsetwo, $matchesexposure);
- $pasteexpose = $matchesexposure[1][$pastesleft];
- if ($pasteexpose == 0) {
- $pasteexpose = "<span style='color:green'>Public</span>";
- } elseif ($pasteexpose == 1) {
- $pasteexpose = "<span style='color:yellow'>Unlisted";
- } else {
- $pasteexpose = "<span style='color:red'>Private</span>";
- }
- preg_match_all('/<paste_format_long>(.*?)<\/paste_format_long>/s', $responsetwo, $matchesformat);
- $pasteformat = $matchesformat[1][$pastesleft];
- preg_match_all('/<paste_url>(.*?)<\/paste_url>/s', $responsetwo, $matchesurl);
- $pasteurl = $matchesurl[1][$pastesleft];
- echo "<tr>\n
- <td>$pastetitle</td>\n
- <td>$pasteformat</td>\n
- <td>$pasteexpose</td>\n
- <td><a href='$pasteurl' target='_blank'>pastebin.com</a></td>\n";
- $pastesleft--;
- }
- echo"</table>";
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement