0

Does anyone know if it's possible to check the current status of the PSN (Playstation Network) and display it on your website?

To better illustrate, the status can be checked here:

https://support.us.playstation.com/app/answers/detail/a_id/237

I'm building a site in Laravel 4 and want to show a simple online/offline indicator on the homepage, but I'm not sure where to begin.

I found this on Github earlier. It looked promising, but it hasn't been updated in over 3 years and doesn't seem to be working.

https://github.com/jflaflamme/psn-status

Thanks!

Scully
  • 1,038
  • 3
  • 10
  • 23
  • 2
    You could parse that page with a DOM parser, and look for the element with class `offline indicator`. Or, even look at the title tag. – Brad Mar 07 '14 at 16:38
  • That seems to be what the linked git repo does, albeit with regex instead of proper parser. Looks like maybe the tag/class they're reading needs updating. Otherwise you can probably borrow from that code, it's a very short script. – Wesley Murch Mar 07 '14 at 16:40

1 Answers1

0

Here's the function I created to check whether or not the PSN is online.

function psn_online() 
{
    // Reference the PSN's network status page
    $str = file_get_contents('https://support.us.playstation.com/app/answers/detail/a_id/237');

    // Return the page title
    preg_match("/\<title\>(.*)\<\/title\>/", $str, $title);
    $page_title = $title[1];

    // If page title contains the word Online
    if (strpos($page_title, 'Online') !== false)
    {
        return true; 
    }
}

I then use the following to check:

<?php if (psn_online()) {} ?>

Thanks for the direction in the comments above, guys.

Is there any way to improve my code?

Scully
  • 1,038
  • 3
  • 10
  • 23
  • [Obligatory comment](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454). – Daedalus Mar 08 '14 at 08:01