Avatar caching error

Proximity

IDK?
Feb 13, 2014
673
56
So I am trying to avatar cache for my radio it will grab the user name from the db and their look and show it

So I am using this script it puts the avatar into the directory but it doesn't show the avatar

Code:
<?phperror_reporting(-1);
?>
    <?php
// Report all PHP errors

    // Copyright Clawed.
    // Got bored to be honest.
  
    function filter( $string ) {
        return mysql_real_escape_string( $string );
    }
  
    define( "HOSTNAME", "localhost" );
    define( "USERNAME", "root" );
    define( "PASSWORD", "" );
    define( "DATABASE", "" );
  
    if( !mysql_connect( HOSTNAME, USERNAME, PASSWORD ) ) die( mysql_error() );
    if( !mysql_select_db( DATABASE ) ) die( mysql_error() );
  
    $url = "http://habbo.ca/";
  
    if( !filter( $_GET['username'] ) ) {
        die( "<h1>Error</h1><hr>Username required.<hr>" );
    }
  
    $query = mysql_query( "SELECT look,username FROM users WHERE username = '" . filter( $_GET['username'] ) . "'" ) or die( mysql_error() );
    if( mysql_num_rows( $query ) < 1 ) { die( "Username does not exists." ); }
    $array = mysql_fetch_assoc( $query );
    $url = $url . "habbo-imaging/avatarimage?figure=" . $array['look'];
  
    if( filter( $_GET['direction'] ) ) {
        $url = $url . "&direction=" . filter( $_GET['direction'] );
    }
  
    if( filter( $_GET['gesture'] ) ) {
        $url = $url . "&gesture=" . filter( $_GET['gesture'] );
    }
  
    if( filter( $_GET['size'] ) ) {
        $url = $url . "&size=" . filter( $_GET['size'] );
    }
  
    if( filter( $_GET['img_format'] ) ) {
        $url = $url . "&img_format=" . filter( $_GET['img_format'] );
    }
  
    if( filter( $_GET['action'] ) ) {
        $url = $url . "&action=" . filter( $_GET['action'] );
    }
  
    $dir = "./avatars/";
    $open = fopen( $url, "r" );
    $hash = filter( $array['username'] ) . "-" . md5( $array['look'] );
    $path = $dir . $hash . ".png";
  
    if( !file_exists( $path ) ) {
        if( $open ) {
            file_put_contents( $path, $open );
            $image = file_get_contents( $path );
            fclose( $open );
        }
    }else{
        $image = file_get_contents( $path );
    }
  
    header( "Content-Type: image/png" );
    exit( $image );

?>
 
UPDATE:

This is the error message in the log:

Code:
[24-Nov-2015 12:30:32 Europe/Belgrade] PHP Notice:  Undefined index: username in C:\inetpub\wwwroot\avatarimage.php on line 51
[24-Nov-2015 12:30:32 Europe/Belgrade] PHP Notice:  Undefined variable: image in C:\inetpub\wwwroot\avatarimage.php on line 65
[24-Nov-2015 12:30:53 Europe/Belgrade] PHP Notice:  Undefined index: direction in C:\inetpub\wwwroot\avatarimage.php on line 32
[24-Nov-2015 12:30:53 Europe/Belgrade] PHP Notice:  Undefined index: gesture in C:\inetpub\wwwroot\avatarimage.php on line 36
[24-Nov-2015 12:30:53 Europe/Belgrade] PHP Notice:  Undefined index: size in C:\inetpub\wwwroot\avatarimage.php on line 40
[24-Nov-2015 12:30:53 Europe/Belgrade] PHP Notice:  Undefined index: img_format in C:\inetpub\wwwroot\avatarimage.php on line 44
[24-Nov-2015 12:30:53 Europe/Belgrade] PHP Notice:  Undefined index: action in C:\inetpub\wwwroot\avatarimage.php on line 48
[24-Nov-2015 12:30:53 Europe/Belgrade] PHP Warning:  fopen(http://habbo.nl/habbo-imaging/avatarimage?figure=sh-295-82.ch-210-82.hd-180-1.lg-275-89.hr-125-47): failed to open stream: HTTP request failed! HTTP/1.1 463 
 in C:\inetpub\wwwroot\avatarimage.php on line 53
[24-Nov-2015 12:30:53 Europe/Belgrade] PHP Notice:  Undefined variable: image in C:\inetpub\wwwroot\avatarimage.php on line 68
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,135
2,461
Firstly, the fuck are you doing here?
PHP:
<?phperror_reporting(-1);
?>

The undefined index errors are shown because you call $_GET[] vars without checking if they are set, so they are undefined.
As for the fopen error, that's probably the cause of your problem. Don't use fopen, it's not the proper function for this situation. Either use cURL to get the data or file_get_contents.
 

Users who are viewing this thread

Top