Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2002
    Location
    Ohio
    Posts
    3,139

    * php script problem

    Guess who? Its me again with a petty script problem.

    I'm trying to have a script query a page that is dynamically created and have the script display whether or not a predetermined value was found.

    I have some ereg_replace() commands in there in case some of the queried page didnt have anything that php doesn't like.

    Everything works fine all the way up to the "if ereg... etc" statement (verified by using echo $buff5; ) . Regardless of the value to look for, it always returns false.

    I have dug into the manual, but everything I try returns false. I tried working on this for 5 hours and I havent gone past this part.

    Quick summary:
    I want this script to see if my OpenRPG game server is running by probing the central server. If it is running, the script tells you if its running, otherwise it says it isn't running. I want to put this on my site so my visitors can see if my server is up.

    Any suggetions?

    Thanks in advance.

    PHP Code:
    <?php

    $fd 
    fopen("http://my.openrpg.com/openrpg_servers.php""r");
    while (!
    feof ($fd)) {
            
    $buffer fgets($fd4096);
    //Replace the crap in the metaserver
            
    $buff0 ereg_replace ("\""" "$buffer);
            
    $buff1 ereg_replace ("\'"""$buff0);
            
    $buff2 ereg_replace ("<servers>"""$buff1);
            
    $buff3 ereg_replace ("<server"""$buff2);
            
    $buff4 ereg_replace ("/>"""$buff3);
            
    $buff5 ereg_replace ("2 The Xtreme""2TX"$buff4);
    //Look for Our Server
            
    if (ereg ("OpenRPG Dev"$buff5)) {
                    echo 
    "Our server is running\n";
                    return;
            } else {
                    echo 
    "Our Server is not Running\n";
                    return;
            }
    }
    fclose ($fd);

    ?>
    edit
    If you want to check for a server that is always running, have the script search for OpenRPG Dev.
    Last edited by MGCJerry; 08-12-2002 at 02:40 AM.
    Glioblastoma Multiforme (GBM) Brain Cancer Awareness. May is Brain Cancer awareness month. Gray Matters!
    Incurable, 6-18 months prognosis, survivors longer than 3 years less than 1% chance.
    Don't like what I say? Ignore me.

  2. #2
    Join Date
    Nov 2001
    Posts
    857
    First you are simply searching the string $buffer to see if "OpenRPG Dev" is in it. So why go through the trouble and CPU resources to take all of that other crap out. It doesn't matter.

    Your script doesn't work because you have put your conditional IF statements in your while loop taking in the information from the server.

    So what is happening is your script enters the while loop fgets the first line into $buffer searches for all of those things that aren't there because there is only one line. It then hits the IF and checks to see if that string is there. It isn't since there is only the first line in the string you are searching through so it hits the else. Prints to the screen the server is not up and ends the script.

    Take the If statements out of the while loop. What I have below should work perfectly....

    You might try this:
    PHP Code:
    <?php
     $fd 
    fopen("http://my.openrpg.com/openrpg_servers.php""r");
       
    $buffer fread($fd4096);
     
    fclose ($fd);

    //Look for Our Server
     
    if (strstr($buffer"OpenRPG Dev")) 
     {
       echo 
    "Our server is running\n";
       return;
     } 
     else 
     {
       echo 
    "Our Server is not Running\n";
       return;
     }
    ?>
    Last edited by michaeln; 08-12-2002 at 12:54 PM.
    <?
    header("Location: http://www.hostevolve.com/");
    ?>

  3. #3
    Join Date
    Nov 2001
    Posts
    857
    After thinking about it some more this one is actually a bit faster. I have tested both of my scripts and they work.

    PHP Code:
    <?php
     $url 
    "my.openrpg.com";
     
    $query "/openrpg_servers.php";
     
    $fp fsockopen($url80$errno$errstr30);
     if(!
    fp)
     {
      
    $content "$errstr ($errno)";
     }
     else
     {
       
    fputs($fp"GET $query HTTP/1.0\r\nHost: $url\r\n\r\n");
       
    $buffer fread($fp4096);
       
    fclose($fp);
       
    //Look for Our Server
       
    if (strstr($buffer"OpenRPG Dev"))
       {
         
    $content =  "Our server is running\n";
       }
       else
       {
         
    $content =  "Our Server is not Running\n";
       }
     }

    echo 
    $content;
    ?>
    Last edited by michaeln; 08-12-2002 at 11:03 AM.
    <?
    header("Location: http://www.hostevolve.com/");
    ?>

  4. #4
    Join Date
    Jan 2002
    Location
    Ohio
    Posts
    3,139

    Thumbs up

    Thanks a bunch michaeln.

    Should have known it was going to be a loop. The first snippet was easer to understand and thet let me see what was wrong plus your explination was a great help too.
    Glioblastoma Multiforme (GBM) Brain Cancer Awareness. May is Brain Cancer awareness month. Gray Matters!
    Incurable, 6-18 months prognosis, survivors longer than 3 years less than 1% chance.
    Don't like what I say? Ignore me.

  5. #5
    Join Date
    Nov 2001
    Posts
    857
    No problem...
    <?
    header("Location: http://www.hostevolve.com/");
    ?>

Posting Permissions

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