Source codes, small scripts...

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

  • GumSlone
    replied
    Get useragent eg googlebot, or NokiaN95 istead of mozilla or opera mini, this function i have developed with alesh's help

    PHP Code:
    function get_mob_browser($_mob_browser)
    {
    
    if(preg_match('/(google|bot)/i',strtolower($_mob_browser)))
    {
    $position = strpos(strtolower($_mob_browser),"bot");
    $_mob_browser = substr($_mob_browser, $position-30, $position+2);
    $_browser = explode (" ", $_mob_browser);
     $_browser = array_reverse($_browser); 
    }
    else if (isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA'])) 
    {
    $_mob_browser = $_SERVER['HTTP_X_OPERAMINI_PHONE_UA'];
    $_position=strpos(strtolower($_mob_browser),"nokia");
    if($_position)$_mob_browser = substr($_mob_browser, $_position,25);
    $_browser = explode ("/", $_mob_browser);
    }
    else 
    {
    $_position=strpos(strtolower($_mob_browser),"nokia");
    if($_position)$_mob_browser = substr($_mob_browser, $_position,25);
    $_browser = explode ("/", $_mob_browser);
    }
    
    return $_browser[0];
     } 
    
    Usage:
    Code:
    echo get_mob_browser($_SERVER['HTTP_USER_AGENT']);

    Leave a comment:


  • something else
    replied
    Fake referer
    PHP Code:
    <?php
    $host = 'www.mydomainname.com ';
    $service_uri = '/index.php';
    $vars ='additional_option1=yes&additional_option2=un';
    $header = "Host: $host\r\n";
    $header .= "Referer: http://www.xxxxx.com\r\n";
    $header .= "accept-language: en\r\n";
    $header .= "User-Agent: vvvvv\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: ".strlen($vars)."\r\n";
    $header .= "Connection: close\r\n\r\n";
    $fp = fsockopen("".$host,80, $errno, $errstr);
    if (!$fp) {
    $errstr ($errno);
    $fp;
    }
     else {
     fputs($fp, "POST $service_uri HTTP/1.1\r\n");
    fputs($fp, $header.$vars);
    fwrite($fp, $out);
    while (!feof($fp)) {
    fgets($fp, 12;
    }
    fclose($fp);
    }
     ?>

    Leave a comment:


  • djdeny
    replied
    create image via php, with referer, browser and ip info ;)
    PHP Code:
    <?php
    header("Content-type: image/png");
    
    $im = ImageCreateFromgif("default.gif");
    ImageString ($im, 2, 10, 36, i,2);
    imagepng($im);
    
    $ref = $_SERVER['HTTP_REFERER'];
    $ip = $_SERVER['REMOTE_ADDR'];
    $vrijeme = date("H:i:s d/m/Y");
    $browser = $_SERVER['HTTP_USER_AGENT'];
    $file = "info.txt";
    $fp = fopen($file, "a");
    
    
    $sve = "IP:$ip \r\n Bro: $browser \r\n Link: $ref \r\n Time: $vrijeme \r\n \r\n\r\n";
    fwrite($fp,$sve);
    fclose($fp);
    ?>

    Leave a comment:


  • GumSlone
    replied
    Change database collation.

    PHP Code:
    <?
    #########################################################################
    #########################################################################
    ##                                                                     ##
    ## Script coded by Eric Reiche                                         ##
    ##                                                                     ##
    ## Version: 0.2 / 2006-08-16 17:35 GMT + 100                           ##
    ## Version 0.2 contains bugfixes                                       ##
    ##                                                                     ##
    ## Inspired by serversupportforum.de user monotek                      ##
    ## ( [url="http://www.serversupportforum.de/forum/sql/"]http://www.serversupportforum.de/forum/sql/[/url]        \              ##
    ## 9279-kollation-von-tabellen-aendern.html#post67293 )                ##
    ## [Check link  for bashscript]                                        ##
    ##                                                                     ##
    ## Web: [url="http://www.ericreiche.net"]http://www.ericreiche.net[/url]  ||  Mail: [email]webmaster@ericreiche.net[/email]  ##
    ##                                                                     ##
    ## You can spread this script, until you don't touch this copymark     ##
    ##                                                                     ##
    #########################################################################
    #########################################################################
    
    
    //Config:
      $mysqlserver = 'localhost';    //Host
      $mysqluser = 'root';           //User [It's recomment to use root]
      $mysqlpw = 'passwort';                 //Password
      $mysqldb = 'datenbank';       //Database
      $stepping = 100;               //Queries per Page
      $tabletoskip = 'really_big_table'; //If you have a really big table, you can enter it here,
                                     //it will be skipped, to prevent a script abort
                                   
      $collation = 'latin1_german2_ci';
      $character_set = 'latin1';
    //End Config
    
    #######################################################################
    # Do not change anything from here, until you know what you're doing  #
    #######################################################################
      
    if(isset($_GET['start']) && is_numeric($_GET['start'])){
      $start = $_GET['start'];
      if($start > 0){
        $start = $start * $stepping;
      }
    }else{
      $start = 0;
    }
    //mysql connect
    @mysql_connect($mysqlserver, $mysqluser, $mysqlpw) OR die("No Conncection to Server. Report: :".mysql_error());
    mysql_select_db($mysqldb) OR die("couldn't select database, Report: ".mysql_error());
    unset($mysqlserver);
    unset($mysqluser);
    unset($mysqlpw);
    
    $i = 0;
    print('<pre>');
    if($start == 0){
      $sql = 'ALTER DATABASE '.$mysqldb.' DEFAULT CHARACTER SET '.$character_set.' COLLATE '.$collation.";\r\n";
      mysql_query($sql);
      print($sql);
    }
    
    $sql = 'Show tables;';
    $result1 = mysql_query($sql);
    while($tables = mysql_fetch_assoc($result1)){
        if($start == 0){
        $sql = 'ALTER TABLE '.$tables['Tables_in_'.$mysqldb].' DEFAULT CHARACTER SET '.$character_set.' COLLATE '.$collation.";\r\n";
        mysql_query($sql);
        print(''.$sql);
      }
      
      $sql = 'Show columns FROM '.$tables['Tables_in_'.$mysqldb];
      $result2 = mysql_query($sql);
      
      while($columns = mysql_fetch_assoc($result2)){
        
        if(substr_count($columns['Type'], 'varchar') || substr_count($columns['Type'], 'text')){
          $i++;
          if($i >= $start && $i < ($start + $stepping)){
            $sql = 'ALTER TABLE '.$tables['Tables_in_'.$mysqldb].' CHANGE '.$columns['Field'].' '.$columns['Field'].' '.$columns['Type'].' CHARACTER SET '.$character_set.' COLLATE '.$collation.';';
            if($tabletoskip != $tables['Tables_in_'.$mysqldb]){
              mysql_query($sql);
              print(''.$i.'. '.$sql."\r\n");
            }else{
              print(''.$i.'. SKIPPED: '.$sql."\r\n");
            }
          }
        }
      }
    
    }
    print('</pre>');
    
    
      print('<a href="'.$_SERVER['PHP_SELF'].'?start='.($_GET['start'] + 1).'">Weiter...</a>');
    
    ?>

    Leave a comment:


  • something else
    replied
    slight spelling errors in the strings names:
    Code:
    function GetCountry($IpAddr){
    change to:
    Code:
    function GetCountry($$IpAdds){
    It is a long way to go about getting countrys lol
    but if anyones intrested in doing it this way heres some country codes:
    Code:
    AD   Andorra
    AE   United Arab Emirates
    AF   Afghanistan
    AG   Antigua and Barbuda
    AI   Anguilla
    AL   Albania
    AM   Armenia
    AN   Netherlands Antilles
    AO   Angola
    AQ   Antarctica
    AR   Argentina
    AS   American Samoa
    AT   Austria
    AU   Australia
    AW   Aruba
    AZ   Azerbaijan
    BA   Bosnia and Herzegovina
    BB   Barbados
    BD   Bangladesh
    BE   Belgium
    BF   Burkina Faso
    BG   Bulgaria
    BH   Bahrain
    BI   Burundi
    BJ   Benin
    BM   Bermuda
    BN   Brunei Darussalam
    BO   Bolivia
    BR   Brazil
    BS   Bahamas
    BT   Bhutan
    BV   Bouvet Island
    BW   Botswana
    BY   Belarus
    BZ   Belize
    CA   Canada
    CC   Cocos (Keeling) Islands
    CF   Central African Republic
    CG   Congo
    CH   Switzerland
    CI   Cote D'Ivoire (Ivory Coast)
    CK   Cook Islands
    CL   Chile
    CM   Cameroon
    CN   China
    CO   Colombia
    CR   Costa Rica
    CS   Czechoslovakia (former)
    CU   Cuba
    CV   Cape Verde
    CX   Christmas Island
    CY   Cyprus
    CZ   Czech Republic
    DE   Germany
    DJ   Djibouti
    DK   Denmark
    DM   Dominica
    DO   Dominican Republic
    DZ   Algeria
    EC   Ecuador
    EE   Estonia
    EG   Egypt
    EH   Western Sahara
    ER   Eritrea
    ES   Spain
    ET   Ethiopia
    FI   Finland
    FJ   Fiji
    FK   Falkland Islands (Malvinas)
    FM   Micronesia
    FO   Faroe Islands
    FR   France
    FX   France, Metropolitan
    GA   Gabon
    GB   Great Britain (UK)
    GD   Grenada
    GE   Georgia
    GF   French Guiana
    GH   Ghana
    GI   Gibraltar
    GL   Greenland
    GM   Gambia
    GN   Guinea
    GP   Guadeloupe
    GQ   Equatorial Guinea
    GR   Greece
    GS   S. Georgia and S. Sandwich Isls.
    GT   Guatemala
    GU   Guam
    GW   Guinea-Bissau
    GY   Guyana
    HK   Hong Kong
    HM   Heard and McDonald Islands
    HN   Honduras
    HR   Croatia (Hrvatska)
    HT   Haiti
    HU   Hungary
    ID   Indonesia
    IE   Ireland
    IL   Israel
    IN   India
    IO   British Indian Ocean Territory
    IQ   Iraq
    IR   Iran
    IS   Iceland
    IT   Italy
    JM   Jamaica
    JO   Jordan
    JP   Japan
    KE   Kenya
    KG   Kyrgyzstan
    KH   Cambodia
    KI   Kiribati
    KM   Comoros
    KN   Saint Kitts and Nevis
    KP   Korea (North)
    KR   Korea (South)
    KW   Kuwait
    KY   Cayman Islands
    KZ   Kazakhstan
    LA   Laos
    LB   Lebanon
    LC   Saint Lucia
    LI   Liechtenstein
    LK   Sri Lanka
    LR   Liberia
    LS   Lesotho
    LT   Lithuania
    LU   Luxembourg
    LV   Latvia
    LY   Libya
    MA   Morocco
    MC   Monaco
    MD   Moldova
    MG   Madagascar
    MH   Marshall Islands
    MK   Macedonia
    ML   Mali
    MM   Myanmar
    MN   Mongolia
    MO   Macau
    MP   Northern Mariana Islands
    MQ   Martinique
    MR   Mauritania
    MS   Montserrat
    MT   Malta
    MU   Mauritius
    MV   Maldives
    MW   Malawi
    MX   Mexico
    MY   Malaysia
    MZ   Mozambique
    NA   Namibia
    NC   New Caledonia
    NE   Niger
    NF   Norfolk Island
    NG   Nigeria
    NI   Nicaragua
    NL   Netherlands
    NO   Norway
    NP   Nepal
    NR   Nauru
    NT   Neutral Zone
    NU   Niue
    NZ   New Zealand (Aotearoa)
    OM   Oman
    PA   Panama
    PE   Peru
    PF   French Polynesia
    PG   Papua New Guinea
    PH   Philippines
    PK   Pakistan
    PL   Poland
    PM   St. Pierre and Miquelon
    PN   Pitcairn
    PR   Puerto Rico
    PT   Portugal
    PW   Palau
    PY   Paraguay
    QA   Qatar
    RE   Reunion
    RO   Romania
    RU   Russian Federation
    RW   Rwanda
    SA   Saudi Arabia
    Sb   Solomon Islands
    SC   Seychelles
    SD   Sudan
    SE   Sweden
    SG   Singapore
    SH   St. Helena
    SI   Slovenia
    SJ   Svalbard and Jan Mayen Islands
    SK   Slovak Republic
    SL   Sierra Leone
    SM   San Marino
    SN   Senegal
    SO   Somalia
    SR   Suriname
    ST   Sao Tome and Principe
    SU   USSR (former)
    SV   El Salvador
    SY   Syria
    SZ   Swaziland
    TC   Turks and Caicos Islands
    TD   Chad
    TF   French Southern Territories
    TG   Togo
    TH   Thailand
    TJ   Tajikistan
    TK   Tokelau
    TM   Turkmenistan
    TN   Tunisia
    TO   Tonga
    TP   East Timor
    TR   Turkey
    TT   Trinidad and Tobago
    TV   Tuvalu
    TW   Taiwan
    TZ   Tanzania
    UA   Ukraine
    UG   Uganda
    UK   United Kingdom
    UM   US Minor Outlying Islands
    US   United States
    UY   Uruguay
    UZ   Uzbekistan
    VA   Vatican City State (Holy See)
    VC   Saint Vincent and the Grenadines
    VE   Venezuela
    VG   Virgin Islands (British)
    VI   Virgin Islands (U.S.)
    VN   Viet Nam
    VU   Vanuatu
    WF   Wallis and Futuna Islands
    WS   Samoa
    YE   Yemen
    YT   Mayotte
    YU   Yugoslavia
    ZA   South Africa
    ZM   Zambia
    ZR   Zaire
    ZW   Zimbabwe

    Leave a comment:


  • Guest
    Guest replied
    get country by ip address, you need url_fopen enabled

    PHP Code:
    <?php
    
    /**
     * @author Milomir
     * @copyright 2008
     */
    
    function GetCountry($IpAddr){
    $APIUrl = "http://api.hostip.info/country.php?ip=" . $IpAdds . "";
    $GetCID = fopen($APIUrl, "r");
    while($CIData = fread($GetCID, 1024)){
    **$ReadCID .= $CIData;
    }
    if(($ReadCID == "YU") or ($ReadCID == "RS")){
    **$Country = "Serbia";
    } elseif($ReadCID == "US"){
    **$Country = "United States";
    } else {
    **$Country = "Unknown";
    }
    fclose($GetCID);
    
    return $Country;
    }
    
    ?>
    usage
    PHP Code:
    <?php
    echo "Ip: " . $_SERVER["REMOTE_ADDR"] . " 
    \n";
    echo "Country: " . GetCountry($_SERVER["REMOTE_ADDR"]) . "\n";
    ?>
    i have added only two countrys to this, you need to add others by yourself, follow my example..

    Leave a comment:


  • WhiteWarrior
    replied
    Siple WML guestbook
    Create a WML Form to Collect user's comments, name and email address. Save following code as Guestbook.wml

    PHP Code:
    <?xml version="1.0"?>
        <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd" >
        <wml>
        <card>
        <p align="center">Guest Book!</p>
    
        Your Name : <input type="text" name="user_name"/>
    
        Your Email: <input type="text" name="user_email"/>
    
        Your Comments : <input type="text" name="user_comments"/>
    
        <anchor>
        <go href="save_comments.php" method="post">
        <postfield name="user_name" value="$user_name"/>
        <postfield name="user_email" value="$user_email"/>
        <postfield name="user_commetns" value="$user_comments"/>
        </go>
        Please Click Here To SEND
        </anchor>
        </card>
        </wml> 
        </FONT> And now create an-other file. This file contains PHP code to Create text file (user_comments.txt) in C:\. User_comments.txt file will hold all data submit by Users. 
         (Note : Save following file as save_comments.php and don't forget to save this both files in same directory) 
          
        <FONT FACE="Courier New" COLOR="#008000"> /* Before Commercial use don't forget to ask me [email]yadish_sahar@hotmail.com[/email]</FONT><FONT FACE="Courier New" COLOR="#008000"> */ 
        <? header("Content-type:text/vnd.wap.wml"); 
        if (isset($user_name) and isset($user_email) 
        and isset($user_comments) and ($user_name and $user_email and $user_comments != "")) 
        { 
        $file_name="c:\user_comments.txt"; 
        $file_data = fopen($file_name ,"a"); 
        $data_to_write = "User Name is :".$user_name."\n". 
        "Email Address is :".$user_email."\n". 
        "He/She Submit this Comments :".$user_comments."\n". 
        "*************************\n\n"; 
        fwrite($file_data,$data_to_write); 
        fclose($file_data); 
        echo "<?xml version=\"1.0\"?> 
        <!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.3//EN\" \"http://www.wapforum.org/DTD/wml13.dtd\" > 
        <wml> 
        <card> 
        <p align=\"center\">Thank You!</p>
     
        Your Comments is Saved. Thank you very much again 
        </card></wml>"; 
        } 
        else 
        { 
        Echo "<?xml version=\"1.0\"?> 
        <!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.3//EN\" \"http://www.wapforum.org/DTD/wml13.dtd\" > 
        <wml> 
        <card> 
        
    
    Some thing is Wrong with Your Form Submission!  
        </p> 
        </card></wml>"; 
        } 
        ?>

    Leave a comment:


  • Anshul
    replied
    Code:
    $start = microtime(true);
    sleep(1);
    $end = microtime(true);
    printf("Time spent: %f", ($end - $start));

    Leave a comment:


  • rukiya
    replied
    Unique Hitcounter
    PHP Code:
    <?php
    
      $ip=$_SERVER[REMOTE_ADDR];
    
      $file=file_get_contents("ipLog.txt");
    
      if(substr_count($file, $ip)==0) {
    
      $file.="\n" . $ip;
    
      }
    
      file_put_contents("ipLog.txt", $file);
    
      $total=substr_count($file, "\n");
    echo "$total";
    
    ?>
    make a ipLog.txt in the same directory and chmod777

    Leave a comment:


  • GumSlone
    replied
    Ban IP range:

    PHP Code:
    $getip = $_SERVER["REMOTE_ADDR"];
    $banned_ip = array();
    $banned_ip[] = '194.9.94.*';
    $banned_ip[] = '77.105.2.*';
    
    
    foreach($banned_ip as $banned)
    {
    $blacked=str_replace('*', '', $banned);
    $len=strlen($blacked);
    if ($ip==$blacked || substr($getip, 0, $len)==$blacked)
    {
    echo 'You are banned!';
    exit;
    }
    } 
    

    Leave a comment:


  • adeii
    replied
    Near begining of index.php find $brws line and change to this

    PHP Code:
    $brws = explode(" ",$_SERVER['HTTP_USER_AGENT']);
    $ubr = $brws[0];
    $uip = getip();
    $action = $_GET["action"];
    $sid = $_GET["sid"];
    $page = $_GET["page"];
    $who = $_GET["who"]; 
    
    It works at my place and detect Opera,Nokia,Samsung ... and their versions too (:

    Leave a comment:


  • GumSlone
    replied
    Detect mobile os:


    PHP Code:
    function detect_os ($ua) {
            if (preg_match('#PalmOS#i', $ua)) {
                    $os_name = "Palm OS";
                    $os_code = "palm";
            } elseif (preg_match('#Windows CE#i', $ua)) {
                    $os_name = "Windows CE";
                    $os_code = "windows";
            } elseif (preg_match('#QtEmbedded#i', $ua)) {
                    $os_name = "Qtopia";
                    $os_code = "linux";
            } elseif (preg_match('#Zaurus#i', $ua)) {
                    $os_name = "Linux";
                    $os_code = "linux";
            } elseif (preg_match('#Symbian#i', $ua)) {
                    $os_name = "Symbian OS";
                    $os_code = "symbian";
            }
    
            if (preg_match('#PalmOS/sony/model#i', $ua)) {
                    $pda_name = "Sony Clie";
                    $pda_code = "sony";
            } elseif (preg_match('#Zaurus ([a-zA-Z0-9.]+)#i', $ua, $matches)) {
                    $pda_name = "Sharp Zaurus " . $matches[1];
                    $pda_code = "zaurus";
                    $pda_ver = $matches[1];
            } elseif (preg_match('#Series ([0-9]+)#i', $ua, $matches)) {
                    $pda_name = "Series";
                    $pda_code = "nokia";
                    $pda_ver = $matches[1];
            } elseif (preg_match('#Nokia ([0-9]+)#i', $ua, $matches)) {
                    $pda_name = "Nokia";
                    $pda_code = "nokia";
                    $pda_ver = $matches[1];
            } elseif (preg_match('#SIE-([a-zA-Z0-9]+)#i', $ua, $matches)) {
                    $pda_name = "Siemens";
                    $pda_code = "siemens";
                    $pda_ver = $matches[1];
            } elseif (preg_match('#dopod([a-zA-Z0-9]+)#i', $ua, $matches)) {
                    $pda_name = "Dopod";
                    $pda_code = "dopod";
                    $pda_ver = $matches[1];
            } elseif (preg_match('#o2 xda ([a-zA-Z0-9 ]+);#i', $ua, $matches)) {
                    $pda_name = "O2 XDA";
                    $pda_code = "o2";
                    $pda_ver = $matches[1];
            } elseif (preg_match('#SEC-([a-zA-Z0-9]+)#i', $ua, $matches)) {
                    $pda_name = "Samsung";
                    $pda_code = "samsung";
                    $pda_ver = $matches[1];
            } elseif (preg_match('#SonyEricsson ?([a-zA-Z0-9]+)#i', $ua, $matches)) {
                    $pda_name = "SonyEricsson";
                    $pda_code = "sonyericsson";
                    $pda_ver = $matches[1];
            } elseif (preg_match('#Wii#i', $ua, $matches)) {
                    $pda_name = "Nintendo Wii";
                    $pda_code = "wii";
            }
            return array($os_name, $os_code, $os_ver, $pda_name, $pda_code, $pda_ver);
    } 
    
    usage:

    PHP Code:
    $info=detect_os ($_SERVER['HTTP_USER_AGENT']);
    echo 'OS name: '.$info[0].'
    ';
    echo 'OS code: '.$info[1].'
    ';
    echo 'OS version: '.$info[2].'
    ';
    echo 'Brand: '.$info[3].'
    ';
    //echo 'Phone code: '.$info[4].'
    ';
    echo 'Model: '.$info[5].'
    '; 
    
    this function I took from counterize mod for wordpress (_http://wordpress.org/extend/plugins/counterizeii/) but its also useful for your mobile sites

    Leave a comment:


  • rukiya
    replied
    A simple form mail PHP script that displays a contact form to allow visitors to your site to send you a message via email. Built in security prevents spammers hijacking it from another domain.
    PHP Code:
    <?php 
    
    /** 
     * Change the email address to your own. 
     * 
     * $empty_fields_message and $thankyou_message can be changed 
     * if you wish. 
     */ 
    
    // Change to your own email address 
    $your_email = "you@example.com"; 
    
    // This is what is displayed in the email subject line 
    // Change it if you want 
    $subject = "Message via your contact form"; 
    
    // This is displayed if all the fields are not filled in 
    $empty_fields_message = "
    
    Please go back and complete all the fields in the form.</p>"; 
    
    // This is displayed when the email has been sent 
    $thankyou_message = "
    
    Thankyou. Your message has been sent.</p>"; 
    
    // You do not need to edit below this line 
    
    $name = stripslashes($_POST['txtName']); 
    $email = stripslashes($_POST['txtEmail']); 
    $message = stripslashes($_POST['txtMessage']); 
    
    if (!isset($_POST['txtName'])) { 
    
    ?> 
    
    <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="txtEmail">Email:</label>
     
        <input type="text" title="Enter your email address" name="txtEmail" /></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 
    
    } 
    
    elseif (empty($name) || empty($email) || empty($message)) { 
    
        echo $empty_fields_message; 
    
    } 
    
    else { 
    
        // Stop the form being used from an external URL 
        // Get the referring URL 
        $referer = $_SERVER['HTTP_REFERER']; 
        // Get the URL of this page 
        $this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"]; 
        // If the referring URL and the URL of this page don't match then 
        // display a message and don't send the email. 
        if ($referer != $this_url) { 
            echo "You do not have permission to use this script from another URL."; 
            exit; 
        } 
    
        // The URLs matched so send the email 
        mail($your_email, $subject, $message, "From: $name <$email>"); 
    
        // Display the thankyou message 
        echo $thankyou_message; 
         
    } 
    
    ?>

    Leave a comment:


  • rukiya
    replied
    It displays a hyperlinked list of all the files contained in a specified folder. A really simple way to have your own directory browser, just drop the file in the folder and it will show an index of all files in the directory on your webspace.
    PHP Code:
    <? 
    
    /** 
     * Change the path to your folder. 
     * 
     * This must be the full path from the root of your 
     * web space. If you're not sure what it is, ask your host. 
     * 
     * Name this file index.php and place in the directory. 
     */ 
    
        // Define the full path to your folder from root 
        $path = "/home/user/public/foldername/"; 
    
        // Open the folder 
        $dir_handle = @opendir($path) or die("Unable to open $path"); 
    
        // Loop through the files 
        while ($file = readdir($dir_handle)) { 
    
        if($file == "." || $file == ".." || $file == "index.php" ) 
    
            continue; 
            echo "<a href=\"$file\">$file</a>
    "; 
    
        } 
    
        // Close 
        closedir($dir_handle); 
    
    ?>

    Leave a comment:


  • rukiya
    replied
    hit counter
    PHP Code:
    <?php 
    
    /** 
     * Create an empty text file called counterlog.txt ,Chmod 777 it and**
     * upload to the same directory as the page you want to**
     * count hits for. 
     ***
     * Add this line of code on your page: 
     * <?php include "text_file_hit_counter.php"; ?> 
     */ 
    
    // Open the file for reading 
    $fp = fopen("counterlog.txt", "r"); 
    
    // Get the existing count 
    $count = fread($fp, 1024); 
    
    // Close the file 
    fclose($fp); 
    
    // Add 1 to the existing count 
    $count = $count + 1; 
    
    // Display the number of hits 
    // If you don't want to display it, comment out this line 
    echo "
    
    Page views:" . $count . "</p>"; 
    
    // Reopen the file and erase the contents 
    $fp = fopen("counterlog.txt", "w"); 
    
    // Write the new count to the file 
    fwrite($fp, $count); 
    
    // Close the file 
    fclose($fp); 
    
    ?>

    Leave a comment:

Working...
X