Log in

View Full Version : if () -> <if> conversion


silentshadow204
07-16-2005, 03:57 AM
This is for a module for vBadvanced CMPS but this is a coding question rather than CMPS support.

I've been successful in setting up the module to work with the portal system. The only problem I am having now is converting the php if () to something vbulletin will understand. I don't have a full grasp of php so converting the php to if statements is a bit confusing.

This is the setup for the ping php include

<?
// The IP address to ping.
$ip = "70.84.217.62";

// This line actually executes the ping.
$cmd = shell_exec("ping -c 1 -w 1 $ip");

// This line determins if the ping was successful or not
$ping_results = explode(",",$cmd);

eval('$home[$mods[\'modid\']][\'content\'] = "' . fetch_template('adv_portal_vent') . '";');
?>


This is the php used for the echo of the html. "1 recieved" means the server is up and 0 means the server is down. I want different text and images to display when the server is up or down.

if (eregi ("1 received", $ping_results[1], $out)) { echo " text "; }


How would I convert the above into an <if> that vbulletin will understand and allow to be processed. If anyone has a better suggestion on how to do this, I'm all ears. The only stipulation is that the server will not respond to queries on port 80; port 4151 will respond to ping requests though. This script just checks if the server responds in general and not on a specific port.

Guest190829
07-16-2005, 04:09 AM
You can have two seperate templates I guess if the server is up or down


if (eregi ("1 received", $ping_results[1], $out)) { echo " text "; }
{
//eval template that show images/text when the server is up
}
else
{

//eval other template that show images/text when server isn't up.
}

silentshadow204
07-16-2005, 04:14 AM
You can have two seperate templates I guess if the server is up or down


if (eregi ("1 received", $ping_results[1], $out)) { echo " text "; }
{
//eval template that show images/text when the server is up
}
else
{

//eval other template that show images/text when server isn't up.
}


Wow, that's perfect. So simple that it didn't even occur to me. :ermm:

edit: Just implemented the code and it worked like a charm. Many thanks for your assistance.

Guest190829
07-16-2005, 04:20 AM
No Problem, Glad I could help. :)