Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, a couple of questions here. 1. I have apache with PHP support running my webpage. How can I display the server uptime, website users etc as normal text? 2. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2004
    Posts
    30

    Display server status/DNS settings


    Hi, a couple of questions here.

    1. I have apache with PHP support running my webpage. How can I display the server uptime, website users etc as normal text?

    2. I have set the IP and hostname to the required values which are 150.203.233.4 and postal.anu.edu.au. This all works fine. I have also installed jabberd 1.4 on it and mu-conference support. I think this requires a new subdomain, which I have set to conference.postal.anu.edu.au in the jabber.xml and muc.xml files. Is this all I need to do? If not, how do I set up the required subdomain? Im running Redhat 9.

    Thanks.

  2. #2
    Linux Engineer Giro's Avatar
    Join Date
    Jul 2003
    Location
    England
    Posts
    1,219
    To setup a subdomain just add it as a vhost like you normally would. Not sure how to display the server up time?

  3. #3
    Linux Guru
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    3,284
    to display things like server uptime etc, the following php script may work:

    Code:
    <?
    passthru&#40;"/usr/bin/uptime"&#41;;
    ?>
    Note, i havent tried it, so there is no gaurentee of it working, so let me know how it goes.

    Alternativly, you could could query /proc/uptime, though im not sure exactly how to interpret the data there, what format it is in etc.

    Not too sure what you are meaning by website users.

    Jason

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Feb 2004
    Posts
    30
    Sorry, by website users I mean the number of people browsing the page.

  6. #5
    Just Joined!
    Join Date
    Feb 2004
    Posts
    4
    pretty easy to do the number of users

    needs MySQL but here goes..

    create a new database, call it waht you want, now populate it with:

    CREATE TABLE useronline (
    timestamp int(15) DEFAULT '0' NOT NULL,
    ip varchar(40) NOT NULL,
    file varchar(100) NOT NULL,
    PRIMARY KEY (timestamp),
    KEY ip (ip),
    KEY file (file)
    );

    now for the php

    Code:
    <?php
    
    $server = "xxx";    //fill in xxx with your details
    $db_user = "xxx";
    $db_pass = "xxx";
    $database = "xxx";
    $timeoutseconds = 300;
    
    $timestamp = time&#40;&#41;;
    $timeout = $timestamp-$timeoutseconds;
    
    mysql_connect&#40;$server, $db_user, $db_pass&#41;;
    $insert = mysql_db_query&#40;$database, "INSERT INTO useronline VALUES &#40;'$timestamp','$REMOTE_ADDR','$PHP_SELF'&#41;"&#41;;
    
    if&#40;!&#40;$insert&#41;&#41; &#123;
    print "Useronline Insert Failed > ";
    &#125;
    
    $delete = mysql_db_query&#40;$database, "DELETE FROM useronline WHERE timestamp<$timeout"&#41;;
    
    if&#40;!&#40;$delete&#41;&#41; &#123;
    print "Useronline Delete Failed > ";
    &#125;
    
    $result = mysql_db_query&#40;$database, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'"&#41;;
    
    if&#40;!&#40;$result&#41;&#41; &#123;
    print "Useronline Select Error > ";
    &#125;
    
    $user = mysql_num_rows&#40;$result&#41;;
    
    mysql_close&#40;&#41;;
    
    if&#40;$user == 1&#41; &#123;
    print&#40;"$user user online\n"&#41;; //this bit prints if there is only 1 user
    &#125; else &#123;
    print&#40;"$user users online\n"&#41;; //otherwise this bit prints
    &#125;
    
    ?>
    i aint supporting this btw, i just knocked it up with some old code i had, if it wipes you off of the face of the planet, it aint my fault

Posting Permissions

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