Source codes, small scripts...

Collapse
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • rukiya
    replied
    It allows visitors to your site to read your guestbook entries and post a message of their own. Very simple setup, only requires you to change 4 settings. Uses MySQL to store the entries.
    PHP Code:
    <?php 
    
    /** 
     * Create the table in your MySQL database: 
     *  
     * CREATE TABLE guests ( 
     *   id int(10) NOT NULL auto_increment, 
     *   name varchar(50) NOT NULL, 
     *   message varchar(255) NOT NULL, 
     *   date timestamp(14) NOT NULL, 
     *   PRIMARY KEY (id) 
     * ) 
     *  
     * Change the database login settings to your own 
     *  
     * The script is now ready to run 
     */ 
    
    // Change these to your own database settings 
    $host = "localhost"; 
    $user = "username"; 
    $pass = "password"; 
    $db = "database"; 
    
    mysql_connect($host, $user, $pass) OR die ("Could not connect to the server."); 
    mysql_select_db($db) OR die("Could not connect to the database."); 
           
    $name = stripslashes($_POST['txtName']); 
    $message = stripslashes($_POST['txtMessage']); 
    
    if (!isset($_POST['txtName'])) { 
    
        $query = "SELECT id, name, message, DATE_FORMAT(date, '%D %M, %Y @ %H:%i') as newdate FROM guests ORDER BY id DESC"; 
        $result = mysql_query($query); 
         
        while ($row = mysql_fetch_object($result)) { 
    
    ?> 
    
    
    
    <?php echo $row->message; ?> 
    
    Posted by <?php echo $row->name; ?> on <?php echo $row->newdate; ?></p> 
    
    <?php 
             
        } 
         
    ?> 
    
    
    
    Post a message</p> 
    
    <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> 
    
        
    
    <label for="txtName">Name:</label>
     
        <input type="text" title="Enter your name" name="txtName" /></p> 
    
        
    
    <label for="txtMessage">Your message:</label>
     
        <textarea title="Enter your message" name="txtMessage"></textarea></p> 
         
        
    
    <label title="Send your message"> 
        <input type="submit" value="Send" /></label></p> 
         
    </form> 
    
    <?php 
    
    } 
    
    else { 
    
        // Adds the new entry to the database 
        $query = "INSERT INTO guests SET message='$message', name='$name', date=NOW()"; 
        $result = mysql_query($query); 
    
        // Takes us back to the entries 
        $ref = $_SERVER['HTTP_REFERER']; 
        header ("Location: $ref"); 
    } 
    
    ?>

    Leave a comment:


  • rukiya
    replied
    It displays a random quote on a web page. Quotes are picked from a list that you define.
    PHP Code:
    <?php 
    
    /** 
     * Add this line of code in your page: 
     * <?php include "random_quote.php"; ?> 
     */ 
    
    $quotes[] = "This is a quote"; 
    $quotes[] = "This is another"; 
    $quotes[] = "quote 3"; 
    $quotes[] = "quote 4"; 
    $quotes[] = "quote 5"; 
    $quotes[] = "quote 6"; 
    
    srand ((double) microtime() * 1000000); 
    $randomquote = rand(0,count($quotes)-1); 
    
    echo "
    
    " . $quotes[$randomquote] . "</p>"; 
    
    ?>

    Leave a comment:


  • GumSlone
    replied
    Function to cut html tags from a text, can be used to remove html tags from rss news

    PHP Code:
    function theRealStripTags($string)
    {
        //while there are tags left to remove
        while(strstr($string, '>'))
        {
            //find position of first carrot
            $currentBeg = strpos($string, '<');
    
            //find position of end carrot
            $currentEnd = strpos($string, '>');
    
            //find out if there is string before first carrot
            //if so save it in $tmpstring
            $tmpStringBeg = @substr($string, 0, $currentBeg);
    
            //find out if there is string after last carrot
            //if so save it in $tmpStringEnd
            $tmpStringEnd = @substr($string, $currentEnd + 1, strlen($string));
    
            //cut the tag from the string
            $string = $tmpStringBeg.$tmpStringEnd;
        }
    
        return $string;
    } 
    

    Leave a comment:


  • GumSlone
    replied
    function to get members age :

    PHP Code:
    ////////////////////////////GET USERS AGE//////////////////////////////////
    function getage($birthdate)
    {
       list($day, $month, $year) = split('-',  $birthdate);
                  $tmonth = date('n');
                  $tday = date('j');
                  $tyear = date('Y');
                  $years = $tyear - $year;
                  if ($tmonth <= $month)
                  {
                  if ($month == $tmonth)
                  {
                  if ($day > $tday)$years--;
                   }
                   else $years--;
                   }
    
               return $years;
    } 
    
    usage

    Code:
    echo getage("30-05-1982");

    Leave a comment:


  • GumSlone
    replied
    bb code function:

    PHP Code:
    function bbcode($text)
    {
    // global $smilies;
             $text=htmlspecialchars($text);
             $text=preg_replace("/\[b\]\[big\](.*?)\[\/b\]\[\/big\]/i","[b]<big>\\1</big>[/b]", $text);
             $text=preg_replace("/\[big\]\[b\](.*?)\[\/big\]\[\/b\]/i","[b]<big>\\1</big>[/b]", $text);
             $text=preg_replace("/\[u\]\[big\](.*?)\[\/u\]\[\/big\]/i","[u]<big>\\1</big>[/u]", $text);
             $text=preg_replace("/\[big\]\[u\](.*?)\[\/big\]\[\/u\]/i","[u]<big>\\1</big>[/u]", $text);
             $text=preg_replace("/\[b\]\[u\](.*?)\[\/b\]\[\/u\]/i","[b][u]\\1[/u][/b]", $text);
             $text=preg_replace("/\[u\]\[b\](.*?)\[\/u\]\[\/b\]/i","[b][u]\\1[/u][/b]", $text);
             $text=preg_replace("/\[b\]\[i\](.*?)\[\/b\]\[\/i\]/i","[b][i]\\1[/i][/b]", $text);
             $text=preg_replace("/\[i\]\[b\](.*?)\[\/i\]\[\/b\]/i","[b][i]\\1[/i][/b]", $text);
             $text=preg_replace("/\[b\]\[u\](.*?)\[\/b\]\[\/u\]/i","[b][u]\\1[/u][/b]", $text);
             $text=preg_replace("/\[u\]\[b\](.*?)\[\/u\]\[\/b\]/i","[b][u]\\1[/u][/b]", $text);
             $text=preg_replace("/\[b\]\[small\](.*?)\[\/b\]\[\/small\]/i","[size="1"][b]\\1[/b][/size]", $text);
             $text=preg_replace("/\[small\]\[b\](.*?)\[\/small\]\[\/b\]/i","[size="1"][b]\\1[/b][/size]", $text);
             $text=preg_replace("/\[i\]\[small\](.*?)\[\/i\]\[\/small\]/i","[size="1"][i]\\1[/i][/size]", $text);
             $text=preg_replace("/\[small\]\[i\](.*?)\[\/small\]\[\/i\]/i","[size="1"][i]\\1[/i][/size]", $text);
             $text=preg_replace("/\[u\]\[small\](.*?)\[\/u\]\[\/small\]/i","[size="1"][u]\\1[/u][/size]", $text);
             $text=preg_replace("/\[small\]\[u\](.*?)\[\/small\]\[\/u\]/i","[size="1"][u]\\1[/u][/size]", $text);
             $text=preg_replace("/\[b\]\[big\](.*?)\[\/b\]\[\/big\]/i","<big>[b]\\1[/b]</big>", $text);
             $text=preg_replace("/\[big\]\[b\](.*?)\[\/big\]\[\/b\]/i","<big>[b]\\1[/b]</big>", $text);
             $text=preg_replace("/\[i\]\[big\](.*?)\[\/i\]\[\/big\]/i","<big>[i]\\1[/i]</big>", $text);
             $text=preg_replace("/\[big\]\[i\](.*?)\[\/big\]\[\/i\]/i","<big>[i]\\1[/i]</big>", $text);
             $text=preg_replace("/\[u\]\[big\](.*?)\[\/u\]\[\/big\]/i","<big>[u]\\1[/u]</big>", $text);
             $text=preg_replace("/\[big\]\[u\](.*?)\[\/big\]\[\/u\]/i","<big>[u]\\1[/u]</big>", $text);
             $text=preg_replace("/\[b\](.*?)\[\/b\]/i","[b]\\1[/b]", $text);
             $text=preg_replace("/\[u\](.*?)\[\/u\]/i","[u]\\1[/u]", $text);
             $text=preg_replace("/\[i\](.*?)\[\/i\]/i","[i]\\1[/i]", $text);
             $text=preg_replace("/\[big\](.*?)\[\/big\]/i","<big>\\1</big>", $text);
             $text=preg_replace("/\[small\](.*?)\[\/small\]/i","[size="1"]\\1[/size]", $text);
             $text=preg_replace("/\[br\/\]/i","
    ", $text);
             $text=preg_replace("/\[url\](.*?)\[\/url\]/i","<a href=\"\\1\">\\1</a>", $text);
             $text=preg_replace("/\[link\=(.*?)\](.*?)\[\/link\]/i","<a href=\"\\1\">\\2</a>", $text);
             $text=preg_replace("/\[img\=((.*?)(.jpg|jpeg))\]/i","<a href=\"\\1\"><img src=\"\\1\" alt=\"***\"/></a>", $text);
             $text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})','[email="\\1"]\\1[/email]', $text);
    } 
    

    Leave a comment:


  • GumSlone
    replied
    generate a random password, eg if you want to send it by email to a user:

    PHP Code:
    $password = substr(preg_replace('/\W/', '', md5(rand())), 0, 8); 
    

    Leave a comment:


  • Guest
    Guest replied
    none of shown source code viewers work, so i create my own, here it is,
    Code:
    <?include("header.php");?>
    <?
    if(isset($_GET['go']) && $_GET['go'] == 'view')
    ** {
    ?>
    
    <wml>
    <card id="rezultat" title="Source Viewer">
    <p align="center">
    
    Source Sajta: [url="$(url)"]$(url)[/url]
    
    
    
    
    <? $url = $_POST['url']; $ff= @htmlspecialchars(file_get_contents($url)); if(!$ff) {?>
    
    Greska: Sajt ne postoji!
    
    <anchor><prev/>Nazad</anchor>
    -----
    
    
    
    <?} if(ereg("http://",$url)) { echo"$ff"; } else { ?>
    
    Greska: Adresa sajta nije validna!
    
    <anchor><prev/>Nazad</anchor>
    
    
    
    <? } ?>
    
    
    
    
    -----
    
    <anchor><prev/>Nazad</anchor>
    
    [url="http://coding-talk.com/f14/?go=main"]Glavna[/url]
    
    
    </p>
    </card>
    </wml>
    <?
    exit;
    }
    ?>
    
    <wml>
    <card id="index" title="Source Viewer">
    <p align="center">
    
    
    Unesite URL:
    
    
    <input type="text" name="url" maxlength="30" emptyok="false" value="http://"/>
    
    <anchor>Ok<go href="<?echo $PHP_SELF;?>?go=view" method="post">
    <postfield name="url" value="$(url)"/></go></anchor>
    
    
    
    -----
    
    [url="http://coding-talk.com/f14/?go=main"]Glavna[/url]
    
    </p>
    </card></wml>
    it is good looking script and it works 100%, on every hosting...
    o yes, here is the header.php
    Code:
    <?
    
    header("Content-type: text/vnd.wap.wml");
    header("Cache-control: no-store,no-cache,must-revalidate");
    print '<?xml version="1.0" encoding="utf-8"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">';
    
    ?>

    Leave a comment:


  • GumSlone
    replied
    If you use the explode user agent to get the mobile phone model, you will find out that on most new nokia phones you will get Mozilla instaed of NokiaN95 etc, here is a small function which helps to get the phone model from useragent.

    PHP Code:
    function mobile_phone($_mob_ua)
    {
          $_position=strpos($_mob_ua,"Nokia");
           if($_position)$_mob_ua = substr($_mob_ua, $_position,25);
           else $_mob_ua=$_mob_ua;
          $phone = explode ('/', $_mob_ua); 
          return $phone[0];
    } 
    
    usage :
    Code:
    echo 'Best for '.mobile_phone($_SERVER['HTTP_USER_AGENT']).'
    ';

    Leave a comment:


  • GumSlone
    replied
    Function to get the real ip, eg if someony is using proxy server.

    PHP Code:
    function getRemoteInfo () {
        $proxy="";
        $IP = "";
        if (isSet($_SERVER)) {
            if (isSet($_SERVER["HTTP_X_FORWARDED_FOR"])) {
                $IP = $_SERVER["HTTP_X_FORWARDED_FOR"];
                $proxy  = $_SERVER["REMOTE_ADDR"];
            } elseif (isSet($_SERVER["HTTP_CLIENT_IP"])) {
                $IP = $_SERVER["HTTP_CLIENT_IP"];
            } else {
                $IP = $_SERVER["REMOTE_ADDR"];
            }
        } else {
            if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) {
                $IP = getenv( 'HTTP_X_FORWARDED_FOR' );
                $proxy = getenv( 'REMOTE_ADDR' );
            } elseif ( getenv( 'HTTP_CLIENT_IP' ) ) {
                $IP = getenv( 'HTTP_CLIENT_IP' );
            } else {
                $IP = getenv( 'REMOTE_ADDR' );
            }
        }
        if (strstr($IP, ',')) {
            $ips = explode(',', $IP);
            $IP = $ips[0];
        }
        $RemoteInfo[0]=$IP;
        $RemoteInfo[1]=@GetHostByAddr($IP);
        $RemoteInfo[2]=$proxy;
        return $RemoteInfo;
    } 
    
    from http://de3.php.net/gethostbyaddr

    Leave a comment:


  • WhiteWarrior
    replied
    randomize banners

    <script language="JavaScript">
    <!--
    function adArray() {
    for (i=0; i*2<adArray.arguments.length; i++) {
    this[i] = new Object();
    this[i].src = adArray.arguments[i*2];
    this[i].href = adArray.arguments[i*2+1];
    }
    this.length = i;
    }
    function getAdNum() {
    dat = new Date();
    dat = (dat.getTime()+"").charAt(;
    if (dat.length == 1)
    ad_num = dat%ads.length;
    else
    ad_num = 0;
    return ad_num;
    }


    var ads = new adArray(
    "http://www.simpleplan-il.com/ps/pro-sky.jpg","http://www.simpleplan-il.com",
    "http://www.simpleplan-il.com/templates/AA.gif","http://www.simpleplan-il.com",
    "http://www.simpleplan-il.com/templates/ab.gif","http://www.simpleplan-il.com");

    var ad_num = getAdNum(); // don&#39;t change this line

    document.write(&#39;&#39;
    +&#39;The script by&#39;
    +&#39;Alon Askalsky
    &#39;
    +&#39;<A HREF="&#39;+ads[ad_num].href+&#39;">[img]&#39;+ads[ad_num].src+&#39;[/img]&#39;);

    // ****** YOU NEED NOT MODIFY ANYTHING THAT IS NOT IN BETWEEN THESE TWO COMMENTS ****

    link_num = document.links.length-1;

    function rotateSponsor() {
    if (document.images) {
    ad_num = (ad_num+1)%ads.length;
    document.js_ad.src = ads[ad_num].src;
    document.links[link_num].href = ads[ad_num].href;
    setTimeout("rotateSponsor()",45000);
    }
    }
    setTimeout("rotateSponsor()",45000);

    // -->
    </script>

    Leave a comment:


  • subzero
    replied
    function spammers mail if you have a web site that sends email there you go

    soon making lavalair function so users dont get hit

    Code:
    function is_email_valid($email) { 
    if(eregi("^([_a-z0-9-]+)(\.[_a-z0-9-]+)@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) return TRUE; 
    else return FALSE; 
    } 
    ?> 
     <?php 
    if (is_email_valid($email)){ 
     $mailok = ""; 
    }else{ 
     $mailok = "Unfortunately Your E-Mail is [b]Not A Valid Address[/b], Please Use Your Browsers Back Button And Re-Complete The Form"; 
     } 
    
    echo "Thank you [b]$_POST[name][/b], for your message! $mailok</p>"; 
    echo "E-mail Address Entered Was: [b]$_POST[email][/b]</p>"; 
    echo "Shop Name: [b]$_POST[shop][/b]"; 
    echo "Street Address: [b]$_POST[street][/b]"; 
    echo "Suburb: [b]$_POST[suburb][/b]"; 
    echo "State: [b]$_POST[state][/b]"; 
    echo "PostCode: [b]$_POST[pcode][/b]"; 
    echo "Country: [b]$_POST[country][/b]";
    
    echo "ABN: [b]$_POST[abn][/b]"; 
    //start building the mail string 
    $msg  = "Name: $_POST[name]\n"; 
    $msg .= "E-Mail: $_POST[email]\n"; 
    $msg .= "Shop Name: $_POST[shop]\n"; 
    $msg .= "Street: $_POST[street]\n"; 
    $msg .= "Suburb: $_POST[suburb]\n"; 
    $msg .= "State: $_POST[state]\n"; 
    $msg .= "Post Code: $_POST[pcode]\n"; 
    $msg .= "Country: $_POST[country]\n"; 
    $msg .= "ABN: $_POST[abn]\n"; 
    //set up the mail 
    $recipient = "support@oz-au.net"; 
    $subject = "New Registration Request From oz-au.net"; 
    $mailheaders = "From: My Web Site <www.oz-au.net> \n"; 
    $mailheaders .= "Reply-To: $_POST[email]"; 
    
    //send the mail 
    mail($recipient, $subject, $msg, $mailheaders); 
    
    ?>
    Last edited by subzero; 20.04.09, 11:59.

    Leave a comment:


  • GumSlone
    replied
    Example PHP File Upload Script

    Below shows a PHP file upload script that is written to handle the form data submitted from the earlier XHTML MP document. The PHP script prints out the information obtained from the HTTP request and saves the uploaded file to the "/file_uploads" directory of the WAP server.

    Code:
    <?php header(&#39;Content-type: application/vnd.wap.xhtml+xml&#39;); ?>
    <?php echo &#39;<?xml version="1.0"?&#39; . &#39;>&#39;; ?>
    <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title>File Upload Example</title>
      </head>
    
      <body>
        <h1>Data Received at the Server</h1>
        <hr/>
        
    
    
    
    <?php
    foreach ($_POST as $key => $value){
    ?>
    
    [b]Name-value Pair Info:[/b]
    
    Field name: <?php echo $key; ?>
    
    Field value: <?php echo $value; ?>
    
    
    
    <?php
    }
    
    $optionalFileName = $_POST[&#39;filename&#39;];
    
    if ($_FILES[&#39;myFile&#39;][&#39;error&#39;] == UPLOAD_ERR_OK){
      $fileName = $_FILES[&#39;myFile&#39;][&#39;name&#39;];
    ?>
    
    [b]Uploaded File Info:[/b]
    
    Content type: <?php echo $_FILES[&#39;myFile&#39;][&#39;type&#39;]; ?>
    
    Field name: myFile
    
    File name: <?php echo $fileName; ?>
    
    File size: <?php echo $_FILES[&#39;myFile&#39;][&#39;size&#39;]; ?>
    
    
    
    <?php
      /* Save the uploaded file if its size is greater than 0. */
      if ($_FILES[&#39;myFile&#39;][&#39;size&#39;] > 0){
        if ($optionalFileName == "")
          $fileName = basename($fileName);
        else
          $fileName = $optionalFileName;
    
        $dirName = &#39;/file_uploads/&#39;;
    
        if (move_uploaded_file($_FILES[&#39;myFile&#39;][&#39;tmp_name&#39;], $dirName . $fileName)){
    ?>
    
    [b]The uploaded file has been saved successfully.[/b]
    
    <?php
        }
        else{
    ?>
    
    [b]An error occurred when we tried to save the uploaded file.[/b]
    
    <?php
        }
      }
    }
    ?>
    
        </p>
      </body>
    </html>
    script from : http://www.developershome.com/wap/wapUploa...d.asp?page=php5

    Leave a comment:


  • GumSlone
    replied
    Image resizer code, resizes images to max height / width
    PHP Code:
    <?php
    // The file
    $filename = 'test.jpg';
    
    // Set a maximum height and width
    $width = 200;
    $height = 200;
    
    // Content type
    header('Content-type: image/jpeg');
    
    // Get new dimensions
    list($width_orig, $height_orig) = getimagesize($filename);
    
    $ratio_orig = $width_orig/$height_orig;
    
    if ($width/$height > $ratio_orig) {
       $width = $height*$ratio_orig;
    } else {
       $height = $width/$ratio_orig;
    }
    
    // Resample
    $image_p = imagecreatetruecolor($width, $height);
    $image = imagecreatefromjpeg($filename);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
    
    // Output
    imagejpeg($image_p, null, 100);
    ?>

    Leave a comment:


  • GumSlone
    replied
    Search file in the directory function:

    PHP Code:
    <?
    function search($target, $directory){
    
       if(is_dir($directory)){
           $direc = opendir($directory);
           while(false !== ($file = readdir($direc))){
    
               if($file !="." && $file != ".."){
    
                   if(is_file($directory."/".$file)){
                       if(preg_match("/$target/i", $file)){
                                               echo "<a href=\"$directory/$file\">$file</a>
    ";
                                           }
                   }else if(is_dir($directory."/".$file)){
                       search($target,$directory."/".$file);
    
                   }
    
               }
           }
           closedir($direc);
       }
    
       return;
    }
    ?>

    Leave a comment:


  • kiss
    replied
    or maybe wants that query tools
    PHP Code:
    <?
    #Until I rewrite my scripts, this will suffice for compatibility
    if(phpversion() >= "4.2.0"){
       extract($_POST);
       extract($_GET);
       extract($_SERVER);
       extract($_ENV);
    }
    
    ?>
    <html>
    <head>
    <title>QUERY TOOLS</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script>
    function m(el) {
      if (el.defaultValue==el.value) el.value = ""
    }
    </script>
    </head>
    
    <body bgcolor="#FFFFFF">
    <div align="center"> 
      <h2>WEB/NETWORK INFO</h2>
      <form method="post" action="<? echo $PHP_SELF; ?>">
        <table width="60%" border="0" cellspacing="0" cellpadding="1">
          <tr bgcolor="#9999FF"> 
            <td width="50%" bgcolor="#6666FF"><font size="2" face="Verdana,
    Arial, Helvetica, sans-serif" color="#FFFFFF">[b]Host 
              Information [/b]</font><font size="1" color="#6666ff">NQT20030507 
    </font></td>
            <td bgcolor="#6666FF"><font size="2" face="Verdana, Arial,
    Helvetica, sans-serif" color="#FFFFFF">[b]Host 
              Connectivity[/b]</font></td>
          </tr>
          <tr valign="top" bgcolor="#CCCCFF"> 
            <td> 
              
    
    <font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
                <input type="radio" name="queryType" value="lookup">
                Resolve/Reverse Lookup
    
                <input type="radio" name="queryType" value="dig">
                Get DNS Records
    
                <input type="radio" name="queryType" value="wwwhois">
                Whois (Web)
    
                <input type="radio" name="queryType" value="arin">
                Whois (IP owner)</font></p>
            </td>
            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
              <input type="radio" name="queryType" value="checkp">
              Check port: 
              <input
    type="text" name="portNum" size="5" maxlength="5" value="80">
              
    
              <input type="radio" name="queryType" value="p">
              Ping host
    
              <input type="radio" name="queryType" value="tr">
              Traceroute to host
    
              <input type="radio" name="queryType" value="all" checked>
              Do it all</font></td>
          </tr>
          
          </table>
      <table width="60%" border="0" cellspacing="0" cellpadding="1"><tr
    bgcolor="#9999FF"> 
            <td colspan="2">
              <div align="center">
                <input type="text" name="target" 
    value="Enter host or IP" onFocus="m(this)">
                <input type="submit" name="Submit" value="Do It">
              </div>
            </td>
          </tr>
        </table>
      </form>
    </div>
    <?
    
    #Global kludge for new gethostbyaddr() behavior in PHP 4.1x
    $ntarget = "";
    
    #Some functions
    
    function message($msg){
    echo "<font face=\"verdana,arial\" size=2>$msg</font>";
    flush();
    }
    
    function lookup($target){
    global $ntarget;
    $msg = "$target resolved to ";
    if( eregi("[a-zA-Z]", $target) )
      $ntarget = gethostbyname($target);
    else
      $ntarget = gethostbyaddr($target);
    $msg .= $ntarget;
    message($msg);
    }
    
    function dig($target){
    global $ntarget;
    message("
    
    [b]DNS Query Results:[/b]<blockquote>");
    #$target = gethostbyaddr($target);
    #if (! eregi("[a-zA-Z]", ($target = gethostbyaddr($target))) )
    if( (!eregi("[a-zA-Z]", $target) && (!eregi("[a-zA-Z]", $ntarget))))
      $msg .= "Can't do a DNS query without a hostname.";
    else{
      if(!eregi("[a-zA-Z]", $target)) $target = $ntarget;
      if (! $msg .= trim(nl2br(`dig any '$target'`))) #bugfix
        $msg .= "The [i]dig[/i] command is not working on your system.";
      }
    #TODO: Clean up output, remove;;'s and DiG headers
    $msg .= "</blockquote></p>";
    message($msg);
    }
    
    function wwwhois($target){
    global $ntarget;
    $server = "whois.crsnic.net";
    message("
    
    [b]WWWhois Results:[/b]<blockquote>");
    #Determine which WHOIS server to use for the supplied TLD
    if((eregi("\.com\$|\.net\$|\.edu\$", $target)) || (eregi("\.com\$|\.net\$|\.edu\$", $ntarget)))
      $server = "whois.crsnic.net";
    else if((eregi("\.info\$", $target)) || (eregi("\.info\$", $ntarget)))
      $server = "whois.afilias.net";
    else if((eregi("\.org\$", $target)) || (eregi("\.org\$", $ntarget)))
      $server = "whois.corenic.net";
    else if((eregi("\.name\$", $target)) || (eregi("\.name\$", $ntarget)))
      $server = "whois.nic.name";
    else if((eregi("\.biz\$", $target)) || (eregi("\.biz\$", $ntarget)))
      $server = "whois.nic.biz";
    else if((eregi("\.us\$", $target)) || (eregi("\.us\$", $ntarget)))
      $server = "whois.nic.us";
    else if((eregi("\.cc\$", $target)) || (eregi("\.cc\$", $ntarget)))
      $server = "whois.enicregistrar.com";
    else if((eregi("\.ws\$", $target)) || (eregi("\.ws\$", $ntarget)))
      $server = "whois.nic.ws";
    else if((eregi("\.it\$", $target)) || (eregi("\.it\$", $ntarget)))
      $server = "whois.nic.it";
    else{
      $msg .= "I only support .com, .net, .org, .edu, .info, .name, .us, .cc, .ws, and .biz.</blockquote>";
      message($msg);
      return;
    }
    
    message("Connecting to $server...
    
    ");
    if (! $sock = fsockopen($server, 43, $num, $error, 10)){
      unset($sock);
      $msg .= "Timed-out connecting to $server (port 43)";
    }
    else{
      fputs($sock, "$target\n");
      while (!feof($sock))
        $buffer .= fgets($sock, 10240); 
    }
     fclose($sock);
     if(! eregi("Whois Server:", $buffer)){
       if(eregi("no match", $buffer))
         message("NOT FOUND: No match for $target
    ");
       else
         message("Ambiguous query, multiple matches for $target:
    ");
     }
     else{
       $buffer = split("\n", $buffer);
       for ($i=0; $i<sizeof($buffer); $i++){
         if (eregi("Whois Server:", $buffer[$i]))
           $buffer = $buffer[$i];
       }
       $nextServer = substr($buffer, 17, (strlen($buffer)-17));
       $nextServer = str_replace("1:Whois Server:", "", trim(rtrim($nextServer)));
       $buffer = "";
       message("Deferred to specific whois server: $nextServer...
    
    ");
       if(! $sock = fsockopen($nextServer, 43, $num, $error, 10)){
         unset($sock);
         $msg .= "Timed-out connecting to $nextServer (port 43)";
       }
       else{
         fputs($sock, "$target\n");
         while (!feof($sock))
           $buffer .= fgets($sock, 10240);
         fclose($sock);
       }
    }
    $msg .= nl2br($buffer);
    $msg .= "</blockquote></p>";
    message($msg);
    }
    
    function arin($target){
    $server = "whois.arin.net";
    message("
    
    [b]IP Whois Results:[/b]<blockquote>");
    if (!$target = gethostbyname($target))
      $msg .= "Can't IP Whois without an IP address.";
    else{
      message("Connecting to $server...
    
    ");
      if (! $sock = fsockopen($server, 43, $num, $error, 20)){
        unset($sock);
        $msg .= "Timed-out connecting to $server (port 43)";
        }
      else{
        fputs($sock, "$target\n");
        while (!feof($sock))
          $buffer .= fgets($sock, 10240); 
        fclose($sock);
        }
       if (eregi("RIPE.NET", $buffer))
         $nextServer = "whois.ripe.net";
       else if (eregi("whois.apnic.net", $buffer))
         $nextServer = "whois.apnic.net";
       else if (eregi("nic.ad.jp", $buffer)){
         $nextServer = "whois.nic.ad.jp";
         #/e suppresses Japanese character output from JPNIC
         $extra = "/e";
         }
       else if (eregi("whois.registro.br", $buffer))
         $nextServer = "whois.registro.br";
       if($nextServer){
         $buffer = "";
         message("Deferred to specific whois server: $nextServer...
    
    ");
         if(! $sock = fsockopen($nextServer, 43, $num, $error, 10)){
           unset($sock);
           $msg .= "Timed-out connecting to $nextServer (port 43)";
           }
         else{
           fputs($sock, "$target$extra\n");
           while (!feof($sock))
             $buffer .= fgets($sock, 10240);
           fclose($sock);
           }
         }
      $buffer = str_replace(" ", "", $buffer);
      $msg .= nl2br($buffer);
      }
    $msg .= "</blockquote></p>";
    message($msg);
    }
    
    function checkp($target,$portNum){
    message("
    
    [b]Checking Port $portNum[/b]...<blockquote>");
    if (! $sock = fsockopen($target, $portNum, $num, $error, 5))
      $msg .= "Port $portNum does not appear to be open.";
    else{
      $msg .= "Port $portNum is open and accepting connections.";
      fclose($sock);
      }
    $msg .= "</blockquote></p>";
    message($msg);
    }
    
    function p($target){
    message("
    
    [b]Ping Results:[/b]<blockquote>");
    if (! $msg .= trim(nl2br(`ping -c5 '$target'`))) #bugfix
      $msg .= "Ping failed. Host may not be active.";
    $msg .= "</blockquote></p>";
    message($msg);
    }
    
    function tr($target){
    message("
    
    [b]Traceroute Results:[/b]<blockquote>");
    if (! $msg .= trim(nl2br(`/usr/sbin/traceroute '$target'`))) #bugfix
      $msg .= "Traceroute failed. Host may not be active.";
    $msg .= "</blockquote></p>";
    message($msg);
    }
    
    
    #If the form has been posted, process the query, otherwise there's 
    #nothing to do yet
    
    if(!$queryType)
      exit;
    
    #Make sure the target appears valid
    
    if( (!$target) || (!preg_match("/^[\w\d\.\-]+\.[\w\d]{1,4}$/i",$target)) ){ #bugfix
      message("Error: You did not specify a valid target host or IP.");
      exit;
      }
    
    #Figure out which tasks to perform, and do them
    
    if( ($queryType=="all") || ($queryType=="lookup") )
      lookup($target);
    if( ($queryType=="all") || ($queryType=="dig") )
      dig($target);
    if( ($queryType=="all") || ($queryType=="wwwhois") )
      wwwhois($target);
    if( ($queryType=="all") || ($queryType=="arin") )
      arin($target);
    if( ($queryType=="all") || ($queryType=="checkp") )
      checkp($target,$portNum);
    if( ($queryType=="all") || ($queryType=="p") )
      p($target);
    if( ($queryType=="all") || ($queryType=="tr") )
      tr($target);
    
    ?>
    
    <hr>
    <p align="right"><font face="verdana,arial" size=1 color="#ffffff">NQT20050219 <font color="#cccccc">hifi-project.net
    &copy; kiss <?php echo date('Y');?></font></p>

    Leave a comment:

Working...
X