Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder
    Join Date
    Nov 2010
    Posts
    204
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Can someone tell me why this isn't working please ?

    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.

    Code:
    <?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.
    Last edited by MoreBloodWine; 05-18-2011 at 10:16 PM.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    What does fetch_web_data do? Did you write that yourself? Are you using curl or file_get_contents?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Nov 2010
    Posts
    204
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    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.
    Last edited by MoreBloodWine; 05-18-2011 at 09:32 AM.

  • #4
    Regular Coder
    Join Date
    May 2011
    Posts
    240
    Thanks
    1
    Thanked 56 Times in 55 Posts
    Check if the following code displays the image. If not, check your webserver's error log for errors.

    PHP Code:
    <?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($imgPngtrue);
    imageSaveAlpha($imgPngtrue);
    header("Content-type: image/png");
    imagePng($imgPng);

  • #5
    Regular Coder
    Join Date
    Nov 2010
    Posts
    204
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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_ps...box-status.php instead of http://www.eojmarket.com/xbox_and_ps...ive-status.php.

    In any case, all is well.
    Quote Originally Posted by gvre View Post
    Check if the following code displays the image. If not, check your webserver's error log for errors.

    PHP Code:
    <?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($imgPngtrue);
    imageSaveAlpha($imgPngtrue);
    header("Content-type: image/png");
    imagePng($imgPng);

  • #6
    Regular Coder
    Join Date
    Nov 2010
    Posts
    204
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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.
    Code:
    <?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.

  • #7

  • #8
    Regular Coder
    Join Date
    Nov 2010
    Posts
    204
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by gvre View Post
    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.

  • #9
    Regular Coder
    Join Date
    May 2011
    Posts
    240
    Thanks
    1
    Thanked 56 Times in 55 Posts
    Try this

    PHP Code:
    <?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";
    }

  • Users who have thanked gvre for this post:

    MoreBloodWine (05-18-2011)

  • #10
    Regular Coder
    Join Date
    Nov 2010
    Posts
    204
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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_ps...tatus/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';
    Quote Originally Posted by gvre View Post
    Try this

    PHP Code:
    <?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";
    }

  • #11
    Regular Coder
    Join Date
    Nov 2010
    Posts
    204
    Thanks
    10
    Thanked 0 Times in 0 Posts
    I just realized the src is all thats reference so all I need ot change is the image name, marking as solved ;-)

  • #12
    Regular Coder
    Join Date
    May 2011
    Posts
    240
    Thanks
    1
    Thanked 56 Times in 55 Posts
    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.

  • #13
    Regular Coder
    Join Date
    Nov 2010
    Posts
    204
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by gvre View Post
    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...


  •  

    Posting Permissions

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