View Full Version : Resolved Can someone tell me why this isn't working please ?
MoreBloodWine 05-18-2011, 08:23 AM Just like the title asks... can someone tell me why this isn't working... I'm guessing it has to do with the preg matches since I know the site doesnt have content gathering blocked.
<?php
global $sourcedir;
if (file_exists('/removed/public_html/SSI.php') && !defined('SMF'))
require_once('/removed/public_html/SSI.php');
elseif (!defined('SMF'))
die('This script wasn\'t able to connect to SMF...');
if (($temp = cache_get_data('xbox_status', 300)) == null)
{
require_once($sourcedir . '/Subs-Package.php');
$request = @fetch_web_data('http://support.xbox.com/en-gb/Pages/xbox-live/xbox-live-status.aspx');
if ($request !== false && preg_match('~<img src="/SiteAssets/XboxSupportV2/images/xbox-live-down.gif" width="24" height="24" alt="Service Alert" />~smi', $request, $matches))
$temp = 'http://www.eojmarket.com/xbox_and_psn_network_status/xbox-down.png';
else if ($request !== false && preg_match('~<img src="/SiteAssets/XboxSupportV2/images/xbox-live-running.gif" width="24" height="24" alt="Service Alert" />~smi', $request, $matches))
$temp = 'http://www.eojmarket.com/xbox_and_psn_network_status/psn-up.png';
else
$temp = 'http://www.eojmarket.com/xbox_and_psn_network_status/xbox-unable.png';
cache_put_data('xbox_status', $temp, 300);
}
$imgPng = imageCreateFromPng($temp);
imageAlphaBlending($imgPng, true);
imageSaveAlpha($imgPng, true);
header("Content-type: image/png");
imagePng($imgPng);
?>
Ps; I have a similar file for the PSN and it works fine so I know my file paths etc are set up right.
Edit: When I call mysite.com/code.php in an img src tag I should be seeing one of three images but instead am seeing the red x in a box thing.
_Aerospace_Eng_ 05-18-2011, 09:13 AM What does fetch_web_data do? Did you write that yourself? Are you using curl or file_get_contents?
MoreBloodWine 05-18-2011, 09:27 AM What does fetch_web_data do? Did you write that yourself? Are you using curl or file_get_contents?
The easiest way I can think of explaing it is that it's like file_get_contents but for the forum system whos SSI.php this references. Like I said, I have an 100% similar file that works for the PSN (PlayStation Network) which works just fine... the only difference between it and this code is the xbox site and the referenced images.
Edit: I'm thinking the issue may be because the referenced img tags it's looking for on the xBox site is nested inside of DIV's.
Check if the following code displays the image. If not, check your webserver's error log for errors.
<?php
$request = file_get_contents('http://support.xbox.com/en-gb/Pages/xbox-live/xbox-live-status.aspx');
if ($request !== false && preg_match('~<img src="/SiteAssets/XboxSupportV2/images/xbox-live-down.gif" width="24" height="24" alt="Service Alert" />~smi', $request, $matches))
$temp = 'http://www.eojmarket.com/xbox_and_psn_network_status/xbox-down.png';
else if ($request !== false && preg_match('~<img src="/SiteAssets/XboxSupportV2/images/xbox-live-running.gif" width="24" height="24" alt="Service Alert" />~smi', $request, $matches))
$temp = 'http://www.eojmarket.com/xbox_and_psn_network_status/psn-up.png';
else
$temp = 'http://www.eojmarket.com/xbox_and_psn_network_status/xbox-unable.png';
$imgPng = imageCreateFromPng($temp);
imageAlphaBlending($imgPng, true);
imageSaveAlpha($imgPng, true);
header("Content-type: image/png");
imagePng($imgPng);
MoreBloodWine 05-18-2011, 03:30 PM I actually goofed big time... I shoulda checked the damn link I was using in my img src tag. I kept trying to use http://www.eojmarket.com/xbox_and_psn_network_status/xbox-status.php instead of http://www.eojmarket.com/xbox_and_psn_network_status/xbox-live-status.php.
In any case, all is well.Check if the following code displays the image. If not, check your webserver's error log for errors.
<?php
$request = file_get_contents('http://support.xbox.com/en-gb/Pages/xbox-live/xbox-live-status.aspx');
if ($request !== false && preg_match('~<img src="/SiteAssets/XboxSupportV2/images/xbox-live-down.gif" width="24" height="24" alt="Service Alert" />~smi', $request, $matches))
$temp = 'http://www.eojmarket.com/xbox_and_psn_network_status/xbox-down.png';
else if ($request !== false && preg_match('~<img src="/SiteAssets/XboxSupportV2/images/xbox-live-running.gif" width="24" height="24" alt="Service Alert" />~smi', $request, $matches))
$temp = 'http://www.eojmarket.com/xbox_and_psn_network_status/psn-up.png';
else
$temp = 'http://www.eojmarket.com/xbox_and_psn_network_status/xbox-unable.png';
$imgPng = imageCreateFromPng($temp);
imageAlphaBlending($imgPng, true);
imageSaveAlpha($imgPng, true);
header("Content-type: image/png");
imagePng($imgPng);
MoreBloodWine 05-18-2011, 05:42 PM I know I marked this solved but there was one other thing I wanted to ask...
How would I add a linkable URL below the else if statement (down image) ?
I tried an echo but that didnt work...
Here's the code I'm trying to modify (same as previously posted)... Ty.
<?php
global $sourcedir;
if (file_exists('/removed/SSI.php') && !defined('SMF'))
require_once('/removed/SSI.php');
elseif (!defined('SMF'))
die('This script wasn\'t able to connect to SMF...');
if (($temp = cache_get_data('xbox_status', 300)) == null)
{
require_once($sourcedir . '/Subs-Package.php');
$request = @fetch_web_data('http://support.xbox.com/en-gb/Pages/xbox-live/xbox-live-status.aspx');
if ($request !== false && preg_match('~<img src="/SiteAssets/XboxSupportV2/images/xbox-live-down.gif" width="24" height="24" alt="Service Alert" />~smi', $request, $matches))
$temp = 'http://www.eojmarket.com/xbox_and_psn_network_status/xbox-down.png';
else if ($request !== false && preg_match('~<img src="/SiteAssets/XboxSupportV2/images/xbox-live-running.gif" width="24" height="24" alt="Service Alert" />~smi', $request, $matches))
$temp = 'http://www.eojmarket.com/xbox_and_psn_network_status/xbox-up.png';
else
$temp = 'http://www.eojmarket.com/xbox_and_psn_network_status/xbox-unable.png';
cache_put_data('xbox_status', $temp, 300);
}
$imgPng = imageCreateFromPng($temp);
imageAlphaBlending($imgPng, true);
imageSaveAlpha($imgPng, true);
header("Content-type: image/png");
imagePng($imgPng);
?>
Ideally I want to add a link so that when the "down" image shows a clickable link is shown below the image that takes a user to xBox's support pages.
You cannot because this code creates and outputs an image.
MoreBloodWine 05-18-2011, 08:53 PM You cannot because this code creates and outputs an image.
Well, how might it be re-worked to achieve this or should I maybe try to write a smaller script using the same pregmatches but with links for the output instead of images.
Try this
<?php
/**
* Check xbox live status
* @return int -1 on failure, 0 if xbox network is up, 1 if xbox network is down
*/
function GetXboxStatus()
{
$request = @file_get_contents('http://support.xbox.com/en-gb/Pages/xbox-live/xbox-live-status.aspx');
if ($request === false)
return -1;
$upPattern = '#src=".+?xbox-live-running.gif"#si';
$downPattern = '#src=".+?xbox-live-down.gif"#si';
if (preg_match($upPattern, $request))
return 0;
if (preg_match($downPattern, $request))
return 1;
return -1;
}
$status = GetXboxStatus();
if ($status == -1)
{
// failure
echo "Network failure<br />\n";
}
else if ($status == 0)
{
// up
echo "<img src=\"http://www.eojmarket.com/xbox_and_psn_network_status/psn-up.png\" />\n";
}
else
{
// down
echo "<a href=\"#\">link here</a>\n";
echo "<img src=\"http://www.eojmarket.com/xbox_and_psn_network_status/xbox-down.png\" />\n";
}
MoreBloodWine 05-18-2011, 10:02 PM I ended up doin a seperate file with the pregmatch like I was talking but your code works like a friggin charm so good my my files hello yours.
http://www.eojmarket.com/xbox_and_psn_network_status/test.php
Thx man, you rock !
Actually, I also have one for another site...
How would you make these...
preg_match('~<img src="/SiteAssets/XboxSupportV2/images/xbox-live-down.gif" width="24" height="24" alt="Service Alert" />~smi', $request, $matches))
preg_match('~<img src="/SiteAssets/XboxSupportV2/images/xbox-live-running.gif" width="24" height="24" alt="Service Alert" />~smi', $request, $matches))
Look like these... my concer is with the height, width and the alt or should all I need to do is replace the image names ?
$upPattern = '#src=".+?xbox-live-running.gif"#si';
$downPattern = '#src=".+?xbox-live-down.gif"#si';
Try this
<?php
/**
* Check xbox live status
* @return int -1 on failure, 0 if xbox network is up, 1 if xbox network is down
*/
function GetXboxStatus()
{
$request = @file_get_contents('http://support.xbox.com/en-gb/Pages/xbox-live/xbox-live-status.aspx');
if ($request === false)
return -1;
$upPattern = '#src=".+?xbox-live-running.gif"#si';
$downPattern = '#src=".+?xbox-live-down.gif"#si';
if (preg_match($upPattern, $request))
return 0;
if (preg_match($downPattern, $request))
return 1;
return -1;
}
$status = GetXboxStatus();
if ($status == -1)
{
// failure
echo "Network failure<br />\n";
}
else if ($status == 0)
{
// up
echo "<img src=\"http://www.eojmarket.com/xbox_and_psn_network_status/psn-up.png\" />\n";
}
else
{
// down
echo "<a href=\"#\">link here</a>\n";
echo "<img src=\"http://www.eojmarket.com/xbox_and_psn_network_status/xbox-down.png\" />\n";
}
MoreBloodWine 05-18-2011, 10:16 PM I just realized the src is all thats reference so all I need ot change is the image name, marking as solved ;-)
You shouldn't try to match width, height, alt or any other attribute because the regexp will fail with a minor change of html code (e.g. height="25").
The best solution is to use an API, if exists, instead of html parsing.
MoreBloodWine 05-18-2011, 10:35 PM You shouldn't try to match width, height, alt or any other attribute because the regexp will fail with a minor change of html code (e.g. height="25").
The best solution is to use an API, if exists, instead of html parsing.
Well like I said, I looked closer and noticed all your matching is the src so the width height etc is a moot point compared to my old regex's I needed to match them. In either case, all is well and marked as solved ;-)
Here's what I did with the link stuff...
eojmarket.com
top left...
|
|