Nov 6, 2009

Visitors Online - With PHP (no MySQL is needed)

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > PHP Programming

Visitors Online - With PHP (no MySQL is needed)

FaLgoR
Another script, which shows the visitors onlineat the moment in your site. This script was not made by me, I just think it will be very usefull to u.

CODE

<?
$timeout = 15; // change it. It is the timer which will delete the member of  online list (in minutes)
if (!$datei) $datei = dirname(__FILE__)."/online.txt";
$time = @time();
$ip = $REMOTE_ADDR;
$string = "$ip|$time\n";
$a = fopen("online.txt", "a+");
fputs($a, $string);
fclose($a);
$timeout = time()-(60*$timeout);
$all = "";
$i = 0;
$datei = file("online.txt");
for ($num = 0; $num < count($datei); $num++) {
$pieces = explode("|",$datei[$num]);

 if ($pieces[1] > $timeout) {
  $all .= $pieces[0];
  $all .= ",";
 }
$i++;
}

$all = substr($all,0,strlen($all)-1);
$arraypieces = explode(",",$all);
$useronline = count(array_flip(array_flip($arraypieces)));

echo $useronline;

$dell = "";
for ($numm = 0; $numm < count($datei); $numm++) {
$tiles = explode("|",$datei[$numm]);
 if ($tiles[1] > $timeout) {
  $dell .= "$tiles[0]|$tiles[1]";
 }
}
if (!$datei) $datei = dirname(__FILE__)."/online.txt";
$time = @time();
$ip = $REMOTE_ADDR;
$string = "$dell";
$a = fopen("online.txt", "w+");
fputs($a, $string);
fclose($a);
?>


Now, just make an blank file called online.txt. That's all! I hope I've helped you wink.gif

 

 

 


Comment/Reply (w/o sign-up)

no9t9
great script. works like a charm. The only thing I did to it was add a "Most users ever online"

O, and I guess I'll give you rep for it.. you seem to have been very helpful with php for many other users.

Comment/Reply (w/o sign-up)

FaLgoR
Thank you =]
I don't know why I'm tryn to get reputation points, but I like to collect them, just for fun =P

Comment/Reply (w/o sign-up)

nancmu
I think i used to see the script at hotscripts.com but that's so good when you brought it here.
Anyways on the code "$ip = $REMOTE_ADDR;" wasn't included for share internet but if you want to check for share ip...
Try this...

if ($_SERVER['HTTP_CLIENT_IP']) {
$ip $_SERVER['HTTP_CLIENT_IP'];
} elseif (ereg("[0-9]",$_SERVER["HTTP_X_FORWARDED_FOR"] )) {
$ip $_SERVER["HTTP_X_FORWARDED_FOR"];
} else {
$ip $_SERVER["REMOTE_ADDR"];
}

smile.gif laugh.gif

Comment/Reply (w/o sign-up)

no9t9
what about detecting if they are on something like AOL proxy?

Comment/Reply (w/o sign-up)

nancmu
QUOTE
what about detecting if they are on something like AOL proxy?

detecting huh.gif did you mean that code?
OK, guy. i will tell you..

if you use "$ip = $REMOTE_ADDR;" code then go to internet cafe and open your website from 2 computers in there, your web will show only 1 number of user online unsure.gif . But if you use my code the number are 2 online users wink.gif .

Comment/Reply (w/o sign-up)

NotoriousZach
Hey thanks that works great, remember you may want to chmod the online.txt page to read and write I believe that is 666 if my memory serves me right. Also another helpful tip. Instead of putting all that in your page use the include funtion.

<? Include("filename.php") ?> Just put that in your main site and save the large piece of coding into filename.php.......

Comment/Reply (w/o sign-up)

alexia
@time= show time
$REMOTE_ADDR = show visitor IP
$string = have $REMOTE_ADDR and @time
$a = fopen("online.txt", "a+"); = open flat file
fputs($a, $string); = write $a and $string string at file
fclose($a); = close file
nice script
really nice
i write this post for help to learn php
but i know very low about php blink.gif

Comment/Reply (w/o sign-up)

HmmZ
no9t9

Could you share the code for "most users ever online" here? smile.gif

and yea, simplicity is the key here, love the script!

Comment/Reply (w/o sign-up)

mobious
i just wanna remind everyone that using this script (which uses a flat file) is not recommended if your site has a high overhead. as it will have undesirable effects. your script may not open a file pointer since it is already opened by another. and will render the script useless. if your site has a high overhead, i suggest to migrate to sql.

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : visitors, online, php, mysql, needed

  1. Gallery Help Needed
    errors help help (10)
  2. Php Guest Online Script
    (3)
    make an index.php copy and paste this code CODE $db_host = "localhost"; $db_user = "root";
    $db_pass = ""; $db_name = "test"; $dbc = mysql_connect($db_host, $db_user, $db_pass); $dbs =
    mysql_select_db($db_name); $tm = time(); $timeout = $tm - (30*60); if($_SERVER ){$ip=$_SERVER ;}
    else{$ip=$_SERVER ;} $brws = explode("(",$_SERVER ); $browser = $brws ; mysql_query("DELETE FROM
    guest WHERE actvtime mysql_query("INSERT INTO guest SET  time='".$tm."',
    ip='".$ip."', browser='".$browser."'"); $count =
    mysql_fetch_array(mysql_query("SELECT COUNT(*)....
  3. Create Table - Mysql Code - Help
    (1)
    I need your feedback about setting the database issues. Please, review them and correct some entries
    in the code if they got some mistakes. This is the code itself: SQL CREATE TABLE `news` (
    `id` int(250) NOT NULL auto_increment, `title` varchar(255) NOT NULL default '',
    `text` text NOT NULL, `author` varchar(255) NOT NULL default '', `valid` varchar(255)
    NOT NULL default '', `date` varchar(255) NOT NULL default '', PRIMARY KEY
    (`id`) ) ENGINE = MyISAM ; ....
  4. Mysql Error
    (3)
    ok i need some more help from the wonderful coders here at Trap. I'm almost done with my CMS
    script, but i'm having a problem with the installer.php file, when it trys to inseret the user
    data into the database i keep getting the following error: CODE mySQL Error: You have an error
    in your SQL syntax; check the manual that corresponds to your MySQL server version for the right
    syntax to use near ';INSERT INTO `members` (`id`, `name`, `username`, `password`, `email`,
    `title`) ' at line 1 the code that is being excuted by the php file is this: C....
  5. Html Form!
    Using MySQL?! (4)
    Hey, I need your help again! I need some good working tutorial how I can update my SQL through HTML
    form. I did use some tutorials online found with the help of google; but they do not work properly;
    I mean there are still small mistakes. I need to have a good tutorial to follow. It should be
    based on security and more things. It has to be done in proper way.......
  6. Tutorial Needed?!
    PHP+Ajax (12)
    I need many tutorials based on PHP programming language and AJAX technology. Those tutorials might
    be of any kind. Please post only the links to the trusted and working tutorials!....
  7. Best Php And Mysql Editor For Noobs
    anyone any php or mysql editor that is good for noob (11)
    hi there guys, from my previous posting, i am a noob in php and mysql programming. I want to know
    if there are any php and mysql editors which are best for me as a noob. i appreciate your kindness
    ....
  8. Php And Mysql Programming
    anyone knows a code for mysql and php (2)
    hi everyone! I am making a program using php and mysql...I am a noob on this so i need your help
    guys...I want to make a simple program that will some values and then store them on a database and
    then retrieve them...uhmm let me give an example out put of what i need. This is the example say..:
    Enter First Name: Enter Last Name:
    Enter Age: Enter Address: ..those are the
    data needed for input values...my question now is how can I make a database whi....
  9. Admin Page
    Tutorial Needed? (4)
    I need to look at a nice tutorial how do you create an admin access page with many functions as many
    as possible.....
  10. Best Sites For Learning Php-mysql
    (4)
    Hi I was reminded of this earlier by a post in a topic, meant to post it but forgot and the topic on
    php books reminded me. Well anyway there is tyhschools for learning php (unless someone else knows
    a better 1) but I wan't to know what is the best site for using php with mysql (using
    phpmyadmin) also whats the difference between postgresql and mysql? though I must admit the
    postgresql version of phpmyadmin whatever it's called looks better (visually)!....
  11. Tools Needed!
    PHP & MySQL (9)
    Hello, everyone! I need some tools for those two things to test PHP scripts coming together with
    database on my laptop, instead checking them on a web-server which takes time.....
  12. Php Code Needed Iii
    (10)
    Hello, everyone. I need your help again! Who might create the PHP code, the picture is above
    this text. Basically, I want when the user fill in all the information in this form, it
    automatically was sent to my email. And, then, the dialog box appears or on the same window, it was
    said that your request has been sent. Moreover, if the user did not fill the entire information,
    the dialog box appears stating that you did not fill some field. Thanks, for help. You always do
    that.....
  13. Looking For Command Line Based Sql Modification
    Program Needed For SQL? (1)
    How I use Windows command prompt client and do modifications to my SQL database. If yes, please
    write the commads I should know for that. If no, please get me the software with which I can do it.
    Topic title modified. Proper English is always required when posting in our forum. ....
  14. Php Code Needed
    Working Together? (5)
    Hello, everyone. I need your help again. This forum is quite good for it. Well, I need create a
    registration form for my web-site using PHP and SQL. The information it should contain: 1) User
    Name 2) First Name 3) Last Name 4) Password 5) e-mail Address 6) Security Image: that images helps
    to protect a random registration, for instance, 56+2=where user have to type an answer in order to
    finish registration. That's all for today. Anymore things, I will post another post over here.
    ....
  15. Php Code
    Needed?! (15)
    Well, I am a novice in PHP programming, so there is a script which I wanna get: 1. You go the
    web-site 2. On the main screen, there is a some kind of field windows, the one you get used to type
    in, when you go to google, for instance. 3. He or she types her email address and it's going to
    be saved in my SQL database. 4. That's it. Help me if you can.....
  16. Mysql Won't Update
    (5)
    Ok, so I'm making some arcade administration software so I don't have to add games the hard
    way, well anyway, one of the features I have is that on the homepage is a featured author and as
    such I just have it so it updates one line in the mySQL. Well, the page with the form passes on the
    varibles fine and the updating page recieves them because I echoed everything, then I build the
    query and I even echo the query and it comes out exactly how I want it to, but for some reason, the
    database itself won't update even though all the varibles are there. Here's....
  17. Html Code Tester. Online Script
    (15)
    Yes, yes. I have another script that I have written and I am distributing. I am not entirely sure if
    this works. I have not tested it yet, but I will later and post back with a demo and fix it up.
    Current script: CODE //Save this as something like htmltest.php function CheckForm() {
    $html_unsafe=$_POST ; //Gives us our user input $html_safe=str_replace(" //Starts security measures
    $html_safe=str_replace("?>"," ",$html_safe); //User input now secure server side //Still security
    issues client side echo $html_safe; //echos our statement } //End function //Main script....
  18. Very Simple Online Now Script
    This is a very simple online now script. (4)
    Hi all, Its Aldo. anyways, I wont be using the method of pagination, i will just tell you how to
    make a basic online now script. When someone logs in, now take into consideration that the name of
    the username input is username ( First ,create a table in your database saying online now and add 2
    fields to it. id and username CODE id type=integer(INT) , auto increment, length =255 and
    username = VARCHAR length=the limit a username should be in your site now from there we take off
    : CODE //logged.php //authentication script //connection script //if connectio....
  19. Creatting A Playlist Through Php
    script help needed (5)
    Hi I am trying to make a script so that i can insert songs into a playlist, but i need a script in
    which it opens the playlist file and removes the closing tag at the end, so before i can add more
    entrys. e.g CODE Location 5 Location 4 Location 3 Location 2 Location 1 But to
    add more entrys i would have to get rid of the atx, then use the fputs to place the new entry into
    the file. code tags added Topic title modified. ....
  20. Creating Profiles In Php/mysql ?
    (7)
    i've started to learn php..im familiar to basics of php and mysql now.Now for example i want
    that some user can register to my website , and after that he can Login and log out , and he can see
    his profile.is there any tutorial about this ? or any helping url .. or any helping answer please
    /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />....
  21. Subquery In Mysql
    (8)
    Is there anyway to make subqueries work in MySQL? I'm pretty certain someone out there knows
    how. /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> Can anyone help?
    CODE Select * from ITEMS where ID="Select Max(ID) from ORDERS"; This works for MSAccess and
    SQL Server but why not in MySQL? I'll be writing some reports and I've shifted database
    from MSAccess to MySQL. Help! Thanks.....
  22. Can You Add Images Into A Mysql Database?
    Using Php? (23)
    I'm learning php in class right now, but I'm still not that good at it, what I'm
    wondering is when I write the php so that it can connect with a database, can I at the same time
    have it that it is able to display back images that I choose. Like, I want a search feature, where
    you can search for a keyword, and it will bring back a list of all the possible entries with that
    keyword, but each of these entries will have a photo associated with it. Now, do I put these image
    files directly into the database, or do I write the code to link them from my files to th....
  23. Increment A Mysql Column
    how to increment a MySQL column one unit (8)
    Hi, I have a column in a MySQL table which contains a counter of the views of the object described
    by this table. I would like to increment this value by one everytime the object is viewed. Obviously
    came into my mind the possibility of retrieving the value of this field, store it in a variable
    increment this value by one and perform an UPDATE query again with this new value. My question is if
    there is a MySQL option to update the field with its actual value plus an unit increment. I hope you
    understand the issue.....
  24. Php News Script
    how to make news script that uses MySQL writen in PHP (20)
    How to make a News script with PHP + MySQL So..in this tutorial i will explain how to create PHP
    news script. first we have to create the table in My SQL.. with the code below you will do this (
    you have to enter it into SQL field ..in PHPmyADMIN) CODE CREATE TABLE news ( id int(10)
    unsigned NOT NULL auto_increment, postdate timestamp(14) NOT NULL, title varchar(50) NOT NULL
    default '', content text NOT NULL, PRIMARY KEY (id), KEY postdate (postdate), FULLTEXT KEY
    content (content) ) >>>> script files 1 file will show the news ,1 file will....
  25. I.p. Ping Online Or Offline
    (7)
    Does anyone know of a script that will tell people if an IP is online or offline? Like it will ping
    it like every fifteen minutes or so and will display an online or offline image accordingly. Or at
    least it supports images, text is fine I guess, but I'd rather it use images. Any help on this
    will be appreciated! Thanks!....
  26. Problem On Mysql "order By"
    (6)
    Can someone please help...? I have a problem with using "ORDER BY" in mysql... CODE SELECT *
    FROM `foo` WHERE b='abc' ORDER BY 'number' ASC i want to sort the table out by
    the value in "number" which is a number.. but it came out to be sort by like this way...
    1->10->2->20 it only sort out the front digit.... but what i want is it will sort by how great the
    number is like this... 1->2->3........->10....->20 sorry my english isn't good enough...to
    describe my problem properly... hope you can understand and help me on this.....thx....
  27. Show Visitors Ip Addresss
    (9)
    Want to show the IP of the visitor to your site? All you have to do is add this code to your page
    where you want the IP to be shown: CODE ?> ....
  28. Php Hit Counter
    record your visitors... (3)
    All you do is copy this code into the page you want to display it on. CODE $counterfile =
    "counter.txt"; $counter = file("$counterfile"); $c = $counter ; if (strlen($c) == 0) {$c=0;}
    $c=$c+1; $a = fopen("$counterfile", "w"); fwrite($a, $counter = ""); fputs($a, $c); fclose($a); echo
    ("$c"); ?> Make a file called 'counter.txt' in the same directory as the page the code is
    on. Remember to CHMOD your txt file to 666. (change the permissions to 666)....
  29. Mysql Password
    (4)
    Hey guys quick question about trap 17s mysql version. How do i change the password to the database?
    I cant seem to find online help for this version anywhere. Any help is very apperciated!....
  30. Mysql Question:
    (7)
    what do I need to input to create a new user and pass. I've tried before, but it kept giving me
    an error like I wasn't allows to creat users. Please note that this is on my computer. So, I was
    also wondering how to 'log in' to root user so that i can make a new user. Thanks in
    advance.....

    1. Looking for visitors, online, php, mysql, needed

Searching Video's for visitors, online, php, mysql, needed
See Also,
advertisement


Visitors Online - With PHP (no MySQL is needed)

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com