PDA

View Full Version : PHP Arrays..



LMS16
12-01-2011, 10:35 AM
Hey,

I know this sounds daft but I've just started using PHP Arrays & Im not familiar with them.
Ive looked on the PHP website & got abit of help & got my script to work.

Basically, I've made a script for work so that when one of our customer's servers is down, it will email us, it all works perfect apart from the array's are outputted twice which means it will send me 2 emails rather than 1...

Here's what I got..



$siteToMonitor = array("mail.**.co.uk", "mail.**.co.uk"); // Accessable mail. url's
$siteToMonitorNames = array("** Server", "** Server"); // Name of the server's
$count = count($siteToMonitor);
$count2 = count($siteToMonitorNames);
for($a = 0; $a < $count; $a++){
for($b = 0; $b < $count2; $b++){
if (isDomainAvailible("http://" . $siteToMonitor[$a])){
echo "<strong>" . $siteToMonitorNames[$b] . "<span style=\"color: green\">Active</span> - <a href=\"http://" . $siteToMonitor[$a] . "\" target=\"_blank\">http://" . $siteToMonitor[$a] . "</a></strong><br />";
}else{
//echo "<strong><span style=\"color: red\">Inaccessible</span> - <a href=\"http://{$value}\" target=\"_blank\">http://{$value}</a></strong><br />";
}
}
}



Can someone help me and point me in the right direction?

+REP, Lew.

Fiendly
12-01-2011, 11:37 AM
Have you tried changing:


$siteToMonitor = array("mail.**.co.uk", "mail.**.co.uk"); // Accessable mail. url's
$siteToMonitorNames = array("** Server", "** Server"); // Name of the server's
To:


$siteToMonitor = array("mail.**.co.uk"); // Accessable mail. url's
$siteToMonitorNames = array("** Server"); // Name of the server's
Seems like that could be your issue, but not sure what you've tried!

LMS16
12-01-2011, 12:03 PM
Yeah, the extra ones are additional ones.

Lew.

Fiendly
12-01-2011, 12:32 PM
Alright, what about this one:



for($a = 0; $a < $count; $a++){
for($b = 0; $b < $count2; $b++){


to:



for($a = 0; $a < $count; $a+){
for($b = 0; $b < $count2; $b+){


Sorry, wouldn't know a lot about php but trying my best.
Might be a double up somewhere!

LMS16
12-01-2011, 12:39 PM
Alright, what about this one:



for($a = 0; $a < $count; $a++){
for($b = 0; $b < $count2; $b++){


to:



for($a = 0; $a < $count; $a+){
for($b = 0; $b < $count2; $b+){


Sorry, wouldn't know a lot about php but trying my best.
Might be a double up somewhere!

Somehow I doubt that would work. I sorted it in the end by using mysql database :)

Lew.

Fiendly
12-01-2011, 12:53 PM
Haha, least it's all working.

Sorry I much of a help :(

Dentafrice
12-01-2011, 09:56 PM
Either way... this should've worked...


<?php
$sites = array();
$sites[0]["domain"] = "mail.**.co.uk";
$sites[0]["name"] = "** Server";

$sites[1]["domain"] = "mainl.**.co.uk";
$sites[1]["name"] = "** Server";

$count = count($sites);

for($i = 0; $i < $count; $i++) {
if(isDomainAvailible("http://" . $sites[$i]["domain"])) {
// site is availible...
echo "<strong>{$sites[$i]["name"]}<span style=\"color: green\">Active</span> - <a href=\"http://{$sites[$i]["domain"]}\" target=\"_blank\">http://{$sites[$i]["domain"]}</a></strong><br />";
} else {
echo "not active";
}
}

Want to hide these adverts? Register an account for free!