Last active
April 9, 2016 00:25
-
-
Save pixelbart/28bc7361f0d74007e683a2c015c980ff to your computer and use it in GitHub Desktop.
HideMyMessage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RewriteEngine On | |
RewriteRule ^([A-Za-z0-9-]+)/?$ /index.php?key=$1 [NC,L] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Simple system to share hidden messages | |
* @author 834rd | |
* @version 1.0 | |
*/ | |
class HideMyMessage | |
{ | |
protected $filePath = "messages/"; | |
/** | |
* Render the message form to create hidden messages | |
*/ | |
public function renderForm() | |
{ | |
?> | |
<script> | |
function pressed(e) { | |
if ( (window.event ? event.keyCode : e.which) == 13) { | |
document.forms[0].submit(); | |
} | |
} | |
</script> | |
<form method="POST"> | |
<textarea name="hide_me" placeholder="Your message..." onkeydown="pressed(event)"></textarea> | |
<input type="submit" style="left: -9999; position: fixed; overflow: hidden;" /> | |
</form> | |
<?php | |
} | |
/** | |
* Submit the form | |
*/ | |
public function submitForm() | |
{ | |
// Clear php errors and put post content to $message for better use | |
if(isset($_POST['hide_me'])) $message = $_POST['hide_me']; | |
// If form is the submit and message is not empty | |
if($message) { | |
// Create the file and get the unique key | |
$key = $this->createMessage($message); | |
// Return the unique key | |
return $key; | |
} | |
} | |
/** | |
* Create a message from | |
*/ | |
public function createMessage($message) | |
{ | |
// Create a unique key as message id and file name | |
$key = md5(microtime().rand()); | |
// File path | |
$file = $this->filePath.$key.".txt"; | |
// Put the $message as content to file $file | |
file_put_contents($file, $message); | |
return $key; | |
} | |
public function viewMessage() | |
{ | |
if(isset($_GET["key"]) && !empty($_GET["key"]) && $_GET["key"] && $_GET["key"] != null) { | |
$key = $_GET["key"]; | |
// Check if file with the name $key exists | |
if(file_exists($this->filePath.$key.".txt")) : | |
// Get the content from file with the name $key | |
$message = file_get_contents($this->filePath.$key.".txt", FILE_USE_INCLUDE_PATH); | |
// Return file content as $message | |
return $message; | |
else : | |
// If file not exists render form | |
$this->renderForm(); | |
endif; | |
} else { | |
$this->renderForm(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once("functions.php"); | |
$hmm = new HideMyMessage(); | |
$key = $hmm->submitForm(); | |
$message = $hmm->viewMessage(); | |
echo (empty($key) ? $key : "<a href=\"?key=$key\">$key</a>"); echo $message; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment