Results 1 to 10 of 10

Thread: PHP Snippets

  1. #1
    Join Date
    May 2005
    Location
    Cornwall
    Posts
    3,590
    Tokens
    2,900
    Habbo
    Feyod

    Latest Awards:

    Default PHP Snippets

    Hello!

    this is a Simple guide and list of PHP snippets, Sorry if it has been Posted Before.

    Hit Counter:
    Create a file and name it count.dat, CHMOD it to 777
    <?php
    $counterfile = "count.dat";
    if(!($fp = fopen($counterfile,"r"))) die ("cannot open counter file");
    $count = (int) fread($fp, 20);
    fclose($fp);

    Display users IP address:
    <?php echo $_SERVER['REMOTE_ADDR']; ?>

    Lines in a file:
    <?php
    $filename = "yourfile.txt";
    $lines = file($filename);
    $count = count($lines);
    echo("There are $count lines in the file.");
    ?>

    Show referer:
    <?php echo $_SERVER['HTTP_REFERER']; ?>

    Server path:
    <?php echo getcwd(); ?>

    IP Logger:
    Create and upload a file called "ips.txt" CHMOD the file to 777
    <?php
    $v_ip = $REMOTE_ADDR;
    $v_date = date("l d F H:i:s");
    $fp = fopen("ips.txt", "a");
    fputs($fp, "IP: $v_ip - DATE: $v_date\n\n");
    fclose($fp);
    ?>

    24hr Clock:
    <?php echo date("H:i:s"); ?>

    Display page load time:
    <?
    function getmicrotime(){
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
    }
    $time_start = getmicrotime();
    for ($i=0; $i <1000; $i++){
    }
    $time_end = getmicrotime();
    $time = $time_end - $time_start;
    $time = round($time,4);
    echo "This page loaded in $time seconds.";
    ?>

    24Hr clock and Day:
    <?php echo date("l g:ia"); ?>

    Display users browser info:
    <?php echo $HTTP_USER_AGENT ?>

    Full date and time:
    <?php echo date("l d F Y"); ?>

    Multi ban IP Address's:
    <?php $ip = getenv('REMOTE_ADDR');
    $ip1 = "xxx.xxx.xxx";
    $ip2 = "xxx.xxx.xxx";
    if($ip == $ip1 || $ip == $ip2)
    {
    echo"You are banned from this site.";
    exit ();
    }
    ?>

    Page include:
    <?php include "PAGEHERE.php"; ?>

    I Hope this will help. Any Questions feel free to Post them here or PM Me.

    Sorry again if this has already been done.
    Last edited by Steven.; 05-06-2005 at 04:35 PM.

  2. #2
    Join Date
    Jul 2004
    Location
    Bournemouth. UK
    Posts
    3,638
    Tokens
    0

    Latest Awards:

    Default

    This is rather good. +Rep For You
    REMOVED

    Edited by jesus (Forum Super Moderator): Please do not have text in your signature which is over size 4.

  3. #3
    Join Date
    Nov 2004
    Location
    Daventry, Northants
    Posts
    1,510
    Tokens
    0

    Latest Awards:

    Default

    Pfft,
    Theyve just been copied + pasted off a site

  4. #4
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default

    Quote Originally Posted by Anderman
    Pfft,
    Theyve just been copied + pasted off a site
    oviosly. if he wrote them he may have noticed some of the ovios errors in some of the code?
    how is a counter supposed to count when it just reads the file? plus it doesnt even display the result "/

  5. #5
    Join Date
    May 2005
    Location
    Cornwall
    Posts
    3,590
    Tokens
    2,900
    Habbo
    Feyod

    Latest Awards:

    Default

    Thank's simplesimon12

    Mentor: This is just a general guide to the php script'ing language, if you didnt like it, maybe help me? im new to it myself, and that's what i have picked up, if you dont like the way i trained in it.. Fine.. couldnt affect me.

  6. #6
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default

    you didnt even close it ?> so its ovioly copy and paste becuse u missed half of it "/
    Copy and pasteing scripts is not what i call trained in somthing "/

    anyway a hit counter would look more like this
    PHP Code:
    <?php
    $document 
    = ("hitpage.txt");
    $hits file($document);
    $hits[0] ++;
    $fp fopen($document "w");
    fputs($fp "$hits[0]");
    fclose($fp);
    echo 
    $hits[0];
    ?>
    then hitpage or what evr u want to go there. woudl need to be chmoded to 777.
    a "working" flat file counter.

    (this is the perfect opitunity for me to have made a mistake in my codeing)

  7. #7
    Join Date
    Jul 2004
    Location
    Bournemouth. UK
    Posts
    3,638
    Tokens
    0

    Latest Awards:

    Default

    Rofl. Obviously he didn't write them :I
    REMOVED

    Edited by jesus (Forum Super Moderator): Please do not have text in your signature which is over size 4.

  8. #8
    Join Date
    Mar 2005
    Location
    Leeds
    Posts
    3,423
    Tokens
    0

    Latest Awards:

    Default

    I wouldnt try fight against Mentors php skills

  9. #9
    Join Date
    Jan 2005
    Location
    Kentucky Fried Chicken
    Posts
    4,610
    Tokens
    0

    Latest Awards:

    Default

    No-One In Thier Right Minds Would

  10. #10
    Join Date
    Nov 2004
    Location
    HabboWeb FM Offices
    Posts
    3,019
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by BlueTails
    No-One In Thier Right Minds Would
    In there right minds, but how about their lefts?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •