turt2live

Untitled

Sep 3rd, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. <?php
  2. // MAKE SURE YOU HAVE A CONNECTION TO MYSQL... Or comment line 12 (and don't insert anything into your DB)
  3. function valid($input){
  4.     $input = trim($input);
  5.     return isset($input) && $input!=null && $input!="";
  6. }
  7.  
  8. function clean($input){
  9.     if(get_magic_quotes_gpc()){
  10.         $input = stripslashes($input);
  11.     }
  12.     $input = mysql_real_escape_string($input);
  13.     $input = htmlentities($input, ENT_COMPAT, "UTF-8");
  14.     return $input;
  15. }
  16.  
  17. function done($msg){
  18.     echo json_encode(array("message"=>$msg));
  19. }
  20.  
  21. if(valid($_POST['message']) && valid($_POST['token'])){
  22.     $msg = clean($_POST['message']);
  23.     $token = clean($_POST['token']);
  24.     if($token == "YourTokenHere"){ // This really should not be hardcoded
  25.         // Post $msg to your site
  26.         // Post $msg to Twitter
  27.         done("Posted!");
  28.     }else{
  29.         done("Invalid Token");
  30.     }
  31. }else{
  32.     done("Unclean Variables");
  33. }
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment