Announcement

Collapse
No announcement yet.

Users OnLine

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Users OnLine

    There are some search hits for this topic but nothing I have found answers this query.

    Client wants Users OnLine displayed.
    Following advice in http://www.oziz.co.uk/scripts/php_users.php I have created the MySql database.

    When this code is put in a standalone file on the server it works: see http://www.graphicz.eu.com/whoos.php

    PHP Code:
    <?php

    //online

    $server "localhost"// usually localhost

    $db_user "web178-*********"

    $db_pass "*********"

    $database "web178-*********"

    $timeoutseconds 300// length of gaps in the count



    //get the time

    $timestamp time(); 

    $timeout $timestamp-$timeoutseconds



    //connect to database

    mysql_connect($server$db_user$db_pass); 



    //insert the values

    $insert mysql_db_query($database"INSERT INTO useronline VALUES

    ('
    $timestamp','$REMOTE_ADDR','$PHP_SELF')"); 

    if(!(
    $insert)) { 

         print 
    ""





    //delete values when they leave

    $delete mysql_db_query($database"DELETE FROM useronline WHERE timestamp<$timeout"); 

    if(!(
    $delete)) { 

        print 
    ""





    //grab the results

    $result mysql_db_query($database"SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'"); 

    if(!(
    $result)) { 

        print 
    ""





    //number of rows = the number of people online

    $user mysql_num_rows($result); 

    if(!(
    $user)) {

    print(
    "ERROR: " mysql_error() . "\n");

    }





    //spit out the results

    mysql_close(); 

    print(
    "$user"); 



    ?>
    When it is put into Actinic thus I get errors:
    A PHP error has been found on the page ('Fatal error: Call to undefined function mysql connect() in main on line 27).
    Code:
    	
    <actinic:block php="true" >
    
    //online
    
    $server = "localhost"; // usually localhost
    
    $db_user = "web178-*********"; 
    
    $db_pass = "*********"; 
    
    $database = "*********"; 
    
    $timeoutseconds = 300; // length of gaps in the count
    
    
    
    //get the time
    
    $timestamp = time(); 
    
    $timeout = $timestamp-$timeoutseconds; 
    
    
    
    //connect to database
    
    mysql_connect($server, $db_user, $db_pass); 
    
    
    
    //insert the values
    
    $insert = mysql_db_query($database, "INSERT INTO useronline VALUES
    
    ('$timestamp','$REMOTE_ADDR','$PHP_SELF')"); 
    
    if(!($insert)) { 
    
         print ""; 
    
    } 
    
    
    
    //delete values when they leave
    
    $delete = mysql_db_query($database, "DELETE FROM useronline WHERE timestamp<$timeout"); 
    
    if(!($delete)) { 
    
        print ""; 
    
    } 
    
    
    
    //grab the results
    
    $result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'"); 
    
    if(!($result)) { 
    
        print ""; 
    
    } 
    
    
    
    //number of rows = the number of people online
    
    $user = mysql_num_rows($result); 
    
    if(!($user)) {
    
    print("ERROR: " . mysql_error() . "\n");
    
    }
    
    
    
    
    
    //spit out the results
    
    mysql_close(); 
    
    print("$user"); 	
    </actinic:block>
    Take a look: http://www.graphicz.eu.com/site1/ scroll right down almost to the bottom

    I guess I am missing something glaringly obvious but I would appreciate any advice.
    Thank you.
    Jonathan Chappell
    Website Designer
    SellerDeck Website Designer
    Actinic to SellerDeck upgrades
    Graphicz Limited - www.graphicz.co.uk

    #2
    I might be miles off on this, but when you put php into a block-if you're telling actinic to run it while generating the page (i.e. before uploading to the server).

    For an online user count to work I'd assume you actually want this to run on the server.

    So I'd say remove the blockif and put back your <?php bits.

    Mike
    -----------------------------------------

    First Tackle - Fly Fishing and Game Angling

    -----------------------------------------

    Comment


      #3
      +1 for me, Actinic's php engine is an offline one, used during offline page creation.

      Comment


        #4
        As said by the two above, you need this PHP code on every page. You'll also need to change all your pages from .html to .php in order for it to run.

        There's another (slightly cunning) way to get around this: Keep your whoos.php file on your server. However edit it to change the lines:
        Code:
        print("ERROR: " . mysql_error() . "\n");
        to be:
        Code:
        print("document.write('ERROR: " . mysql_error() . "');");
        and change
        Code:
        print("$user");
        to be
        Code:
        print("document.write('$user');");
        Now your Actinic layouts can stay .html and you display the count by something like:
        Code:
        Users online: <script type="text/javascript" src="whoos.php"></script>
        Make sure that whoos.php is in your acalaog directory by uploading it via Design / Additional Files.

        N.B. All untested.
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment


          #5
          Just as an aside.

          I'm sure I read somewhere that you can also call a php script just by calling it as an image.

          i.e. instead of

          Users online: <script type="text/javascript" src="whoos.php"></script>

          You could use

          Users online: <img src="whoos.php">

          Although looking through Norman's post I think he's using the javascript to display the results by getting the php script to generate the results as javascript. Very clever.

          Mike
          -----------------------------------------

          First Tackle - Fly Fishing and Game Angling

          -----------------------------------------

          Comment


            #6
            Brilliant!

            http://www.graphicz.eu.com/site1/

            Thank you Norman
            Jonathan Chappell
            Website Designer
            SellerDeck Website Designer
            Actinic to SellerDeck upgrades
            Graphicz Limited - www.graphicz.co.uk

            Comment

            Working...
            X