You are not logged in.

Dear visitor, welcome to sourceserver.info. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

  • MadMakz

    Super Moderator

    You have to register first, to connect to this user.

24

PHP Error_Reporting() Temporär ändern/abschalten ++ Steamcommunity Status Script

Rating:

by MadMakz, Wednesday, November 30th 2011, 11:20pm

Für die SteamCommunity Anzeige auf meinen Websites (u.a. nucleardawn.de), welches eine leicht abgeänderte Version dieses vB Addons ist (Ja ich weiß, geht auch schöner wenn man die Community APi nutzen würde), stand ich vor dem Problem das file_get_contents() bei Timeouts immer ein nervendes PHP Warning von sich gibt. Nervend deswegen weil 1. meine version des Scripts bereits ein Errorhandle besitzt und 2. der Fehler sich auf ein nicht-Lokales Problem bezieht.

Da ich aber deswegen nicht gleich error_reporting() deaktivieren wollte habe ich mir ein Workarround überlegt wie ich die Error Funktion nur während eines bestimmten Code Teils temporär abändere.

PHP Source code

1
2
3
4
$error_reporting error_reporting();
error_reporting(0);  
    <!-- code -->
error_reporting($error_reporting);


Nichts Weltbewegendes aber für mich dennoch das erste mal von Nöten.

Ich stelle euch mal den ganzen Code zu Verfügung. Es ist zwar eher Suboptimal (da es nicht die Steam API nutzt) aber er funktioniert. Wenn ich irgendwann mal Lust habe oder Steam sein Design ändert schreibe ich evtl. mal eine API Version. Atm reichts's aber :P

v1.1

Spoiler Spoiler

PHP Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
$gruppe "meine_steam_gruppe"// Der Gruppenname hinter http://steamcommunity.com/groups/
echo stgrp_status($gruppe);

function stgrp_status($group false){
    if(!$group){ return false; }

    $error_reporting error_reporting();
    error_reporting(0);  
    $url file_get_contents('http://steamcommunity.com/groups/'.$group); 
    $default_socket_timeout ini_get("default_socket_timeout");
    ini_set("default_socket_timeout"0); 
    if($http_response_header[0] != "HTTP/1.1 200 OK"){
        error_reporting($error_reporting);
        ini_set("default_socket_timeout"$default_socket_timeout);
        return "<div class="blockrow"><b>Steamcommunity appears to be down.</b></div>";
    }
    error_reporting($error_reporting);
    ini_set("default_socket_timeout"$default_socket_timeout);
    
    preg_match('#<h1>(.+)</h1>#sU'$url$aMatches);
    $return "<div class="blockrow">";
    $return .= "<table>";
    $return .= "<a class="clanname" href='http://steamcommunity.com/groups/$group' target='_blank'>$aMatches[1]</a>"; 
    $return .= "<br>";
    preg_match('#<div class="groupMemberRow">(.+)</div>#sU'$url$aMatches); 
    $aMatches str_replace('class="linkStandard"''class="linkStandard" target="_blank"'$aMatches[1]);
    $pieces explode(" "$aMatches);
    $domain strstr($pieces[3], '>');
    $strip1 substr($domain1); 
    $return .= "<span class="resultsb">$strip1 Members</span>";
    $return .= "<br>";
    $domain1 strstr($pieces[6], '>');
    $strip2 substr($domain11);
    $return .= "<span class="membersInGame"><font color=#8bc53f>$strip2 In-Game</font></span>"; 
    $return .= "<br>";
    $domain2 strstr($pieces[9], '>');
    $strip3 substr($domain21); 
    $return .= "<span class="membersOnline"><font color=#62a7e3>$strip3 Online</font></span>";
    $return .= "</table>";
    $return .= "</div>";
    return $return;
}
?>

v1.2
http://rcs.madmakz.com/misc-tools/src/4c…pStatus/sgs.php
v1.3
http://rcs.madmakz.com/misc-tools/src/0d…pStatus/sgs.php
v1.4
fget: https://tracker.madmakz.com/redmine/proj…pStatus/sgs.php
cURL: https://tracker.madmakz.com/redmine/proj…us/sgs_curl.php
XML: https://tracker.madmakz.com/redmine/proj…tus/sgs_xml.php

Die $return's entstanden aus dem Grund das der Code für vBulletin erst-genutzt wurde, dort sind Widgets als Funktion aufgebaut. return $return; (letzte Zeile) habe ich bereits in echo $return; abgeändert.
Hab's jetzt als Funktion gepostet.

BTW: Wer nicht weiß was oder woher dort oben $http_response_header her kommt -> http://php.net/manual/de/reserved.variab…ponseheader.php

Update:
  • 1.1 - 16.12.2011
    • Funktion resettet default_socket_timeout zurück zu dem was in der php.ini steht.

  • 1.2 - 09.09.2012
    • Leichterer Code
    • Angepasst an neues Steamcommunity Layout (2012/Greenlight)

  • 1.3 - 20.09.2012
    • Fixed "Undefined variable: return"

  • 1.4
    • Script jetzt in drei Versionen verfügbar. fget, cURL und XML.

This article has been read 48,991 times.


Comments (3)

  • 3

    by MadMakz (Tuesday, October 16th 2012, 12:04am)

    v1.4 - U.a. eine Version die die XML APi benutzt.

  • 2

    by MadMakz (Sunday, September 9th 2012, 2:24am)

    updated

  • 1

    by BIGFAT (Tuesday, January 10th 2012, 6:20am)

    Danke!

Blog navigation

Next article

SSLgen

by MadMakz (Monday, May 14th 2012, 4:25pm)

Previous article

God damn WAMP...

by MadMakz (Monday, November 28th 2011, 6:16pm)