Jump to content

[SOLVED] weird issue, I can't explain


HaLo2FrEeEk

Recommended Posts

EDIT: Ok, nevermind, for whatever reason it was printing the URLs the same, but the url I grabbed from the parsed HTML was escaping the & signs, so it was passing the URL with the escaped entity, which was causing it to have issues.  I got it working now and I just wasted a ton of time typing this post!  Sorry!

 

I'm trying to make something so that my users can embed images from another site in my forum.  The reason they can't is because it's a dynamically generated image that uses this format:

 

http://www.bungie.net/Stats/Halo3/PlayerModel.ashx?p1=0&p2=8&p3=6&p4=6&p5=2&p6=26&p7=21&p8=24

 

That's a player snapshot from Halo 3, a player's current armor variant.  The link above is mine.  Now, I've got a function that parses that information from the remote page here:

 

http://www.bungie.net/Stats/Halo3/Default.aspx?player=halo2freeek

 

You can see the image at the bottom.  My function works, I've tested it by printing out the URL.  Here is my code:

 

<?php
function parseModelURL($gt) {
  $html = file_get_contents("http://www.bungie.net/Stats/Halo3/Default.aspx?player=".$gt);
  preg_match('%PlayerModel\.ashx\?(.+?)"%', $html, $match);
  $modelurl = $match[1];
  //$modelurl = str_replace("&", "&", $modelurl);
  if($modelurl == '') {
    $modelurl = 'null';
    }
  return $modelurl;
  }

$gamertag = str_replace(" ", "+", $_REQUEST['gt']);
$model = parseModelURL($gamertag);
$snapshot_url = "http://www.bungie.net/Stats/Halo3/PlayerModel.ashx?".$model;
$snapshot = file_get_contents($snapshot_url);

echo $snapshot;
?>

 

If a person tries to visit that link with a missing value, or without any values, it shows this:

 

PlayerModel.ashx

 

My code is supposed to parse the last bit of the URL, this part:

 

p1=0&p2=8&p3=6&p4=6&p5=2&p6=26&p7=21&p8=24

 

And it does, and returns it and saves it to $model.  Then I attach that to the beginning of the url:

 

http://www.bungie.net/Stats/Halo3/PlayerModel.ashx?

 

so I should have the full link I posted at the top of this post.  Then it uses file_get_contents to retrieve that image and for whatever reason, I still get the grey image.  I've tested it by manually putting in the whole URL into the file_get_contents function and it works fine, but if Ilet it insert the URL in there using the variables it echoes out the grey image.  I cannot explain why this is happening and it's really REALLY annoying.  Please, can someone help me figure this out!  I'm going to be using htaccess to rewrite the url so instead of this:

 

http://infectionist.com/misc/snapshot.php?gt=gamertag

 

it's

 

http://infectionist.com/misc/gamertag.png

 

But I need it to work first.

 

Thank you in advance for any help!

Link to comment
https://forums.phpfreaks.com/topic/162188-solved-weird-issue-i-cant-explain/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.