Share Pastebin
Guest
Public paste!

vigge_sWe

By: a guest | Mar 15th, 2010 | Syntax: PHP | Size: 1.36 KB | Hits: 29 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. <?php
  2.         include("includes/config.php");
  3.  
  4.         $add = new AddSite;
  5.         class AddSite {
  6.                
  7.                 public function __construct() {
  8.                        
  9.  
  10.                         if($this->formSubmitted()) {                                                     
  11.                                 $this->addSite($_POST['name'], $_POST['url'], $_POST['ports'], isset($_POST['email']));
  12.                         } else {
  13.                                 echo "Please submit the form first";
  14.                         }
  15.                 }
  16.                
  17.                 public function formSubmitted(){
  18.                         if(!isset($_POST['submit'])||empty($_POST['name'])||empty($_POST['url'])||empty($_POST['ports'])){
  19.                                 return false;
  20.                         }
  21.                         return true;
  22.                 }
  23.                
  24.                 public function addSite($name, $url, $ports, $email) {
  25.                        
  26.                         global $host, $username, $password, $database;
  27.                         if($mysqli = new mysqli($host,$username,$password,$database)){
  28.                                
  29.                                
  30.                                 $nameSanitized = $mysqli->real_escape_string($name);
  31.                                 $urlSanitized = $mysqli->real_escape_string($url);
  32.                                 $portsSanitized = $mysqli->real_escape_string($ports);
  33.                                 $emailSanitized = $mysqli->real_escape_string($email);
  34.                                
  35.                                 $port = explode('|', $ports);
  36.                                
  37.                                 $count = count($port);
  38.                                 $status = "";
  39.  
  40.                                 foreach($port as $p){
  41.                                        
  42.                                         @$fp = fsockopen($url,$p, $errno, $errstr, 5);
  43.                                        
  44.                                         if($fp){
  45.                                                
  46.                                                 $status += "up|";
  47.                                                
  48.                                         } else {
  49.                                        
  50.                                                 $status += "down|";
  51.                                                
  52.                                         }
  53.                                        
  54.                                 }
  55.                                
  56.                                 echo $status;
  57.                                
  58.                         } else {
  59.                                 echo "There was an error connecting to the DB";
  60.                         }
  61.                 }
  62.         }
  63. ?>