Adblock breaks this site

User's Online Script?

Discussion in 'Web Programming' started by Covey, Feb 12, 2007.

  1. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    User's Online Script?

    Ok for my program EliteSwitch im trying to make it have a user's online part, how would i do this?

    When i start the program i need it to add 1 to the user's online, then when i close the program it will have to take 1 away from the user's online.

    How can i do that?
     
  2. Michael3455

    Michael3455 Active Member

    Joined:
    Sep 11, 2005
    Posts:
    134
    Referrals:
    0
    Sythe Gold:
    0
    User's Online Script?

    I would think PHP and a Database would be the easiest. I don't think that it would be too hard to do it. I made a members login/members area script for a friend in PHP, from first looking at the language to completion of it, it took me around three hours. But I had some help from a friend...

    So.. For someone who can actually program, it might only take you 20 minutes to find out what you need to know... Or you could just google.. I'm sure you could find a script that would be similar to what you need.
     
  3. cp

    cp an cat
    Banned

    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0
    User's Online Script?

    What language is the program? I might be able to help you if you're using python for the program, or php.

    The language you're making your program in should have a kill function or a conditional statement on what to do if the program is exited, where you can have it invisibly load the webpage with php and do that. Same goes with opening it. And you could add a while loop to constantly refresh the frame or whatever that holds the data of the people online.

    Assuming you know php, just make a php file that when the get request is ?get=add you add one to the file and read it. If it's ?get=minus then you take one out and read that.

    Assuming that your language can actually do that.
     
  4. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    User's Online Script?

    i've got this code from smither at cruels.net
    Code:
    <?php
    If ($_GET['act'] == 'join') {
      // Add one to a file
    } else if ( $_GET['act'] == 'leave') {
      // Remove one
    } else {
      // echo file
    }
    
    ?>
    but i don't know how to use it.

    lets pretend my .php page is called 'online.php'

    when i load my program do it go to www.blah.com/online.php?join

    and when i exit to i go to www.blah.com/online.php?leave

    and to display the number of players online to i go to www.blah.com/online.php

    is that correct?

    also how to i exactly add one to a file and remove one from a file and echo the file (i know echo is a msgbox, well i think)
     
  5. cp

    cp an cat
    Banned

    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0
    User's Online Script?

    Code:
    <?php
    $fp = fopen('peepz.txt', 'w+');
    $ro = fopen('peepz.txt', 'r');
    $read = fread($ro, filesize("peepz.txt"));
    if(isset($_GET['join'])) {
    $read = $read + 1;
    fwrite($fp, $read);
    }
    else {
    if(isset($_GET['leave'])) {
    $read = $read - 1;
    fwrite($fp, $read);
    }
    }
    
    echo("".$read."");
    ?>
    
    When a user joins, load online.php?join . When the user leaves, load online.php?leave .

    If you want to read (I don't know vb) read the url http://www.whatever.poo/online.php (without ?leave or ?join)

    If you get any errors (there shouldn't be any) tell me, or try fixing it yourself.

    Have fun.
     
  6. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    User's Online Script?

    i got an error :(

    Warning: fread(): Length parameter must be greater than 0. in /home/tesstott/public_html/sscovey/eliteswitch/users.php on line 4

    i have the users.php file and an online.txt, they are both CHMOD to 777.

    heres the users.php code:
    Code:
    <?php
    $fp = fopen('online.txt', 'w+');
    $ro = fopen('online.txt', 'r');
    $read = fread($ro, filesize("online.txt"));
    if(isset($_GET['join'])) {
    $read = $read + 1;
    fwrite($fp, $read);
    }
    else {
    if(isset($_GET['leave'])) {
    $read = $read - 1;
    fwrite($fp, $read);
    }
    }
    
    echo("".$read."");
    ?>
    i tried putting 0 and 1 in the online.txt but it made no difference :(

    pelase help
     
  7. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    User's Online Script?

    anyone?
     
  8. asrkj117

    asrkj117 Guest

    Referrals:
    0
    User's Online Script?

    try this

    <?php
    $fp = fopen('online.txt', 'w+');
    $ro = fopen('online.txt', 'r');
    $read = fread($ro, filesize("online.txt"));
    if(isset($_GET['join'])) {
    $read = $read + 1;
    fwrite($fp, $read);
    }
    else {
    if(isset($_GET['leave'])) {
    fwrite($fp, $read);
    }
    }

    echo("".$read."");
    ?>
     
  9. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    User's Online Script?

    still the same error :(
     
  10. Jazz00006

    Jazz00006 Apprentice
    Visual Basic Programmers

    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0
    User's Online Script?

    tried mine? (the one MH gave you)
     
  11. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    User's Online Script?

    yup, got it brewing now ^_^ thanks again.
     
< [Delphi][Source] FindColor(Tolerance) using ScanLines | [TuT]The Basic Html Code[TuT] >


 
 
Adblock breaks this site