need help with script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

need help with script

Post by jeeep »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hey all,
 I'm trying to determine if the problem I'm having is with this script or with my hosting company. I've asked them to open ip: 65.211.238.22 with port 443 (UDP) in my server firewall so this script can work. Here is the script itself



But for some reason (either an error in the script or a problem w/ my servers firewall and CURL https). i'm stumped can someone help? Let me know if you need anymore information. Thanks


[color=red][b]feyd[/b] | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by jeeep on Tue Aug 29, 2006 7:59 pm, edited 1 time in total.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Do you have error reporting on? Is your PHP configured with perl? What does it output? Does the script run?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

Yes have error reporting on and nothing comes up but a page stating "This page cannot be displayed" by IE. PHP is configured with perl. This is a curl test script to make sure we can connect to novaworld, which so far has been unsuccesful. However, when the url is changed to another url it works succsesfully (for example)


This is really the question, is something wrong with the connection settings with in the code to where it wouldnt connect correctly or is the problem with my server and its firewall?
Last edited by jeeep on Tue Aug 29, 2006 8:00 pm, edited 1 time in total.
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

seems like it has to be a firewall problem, any suggestions?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

"This page cannot be displayed" by IE
Yeah that is a network problem not a PHP problem. Your PHP isn't being executed.
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

They told me its a SSl problem. Yet my friend is running the same script on his server.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Instead of curl, use file_get_contents() Try this...

Code: Select all

<?php
function get_data($html , $findme){
 // Finds the $findme string and extracts the data between the > < tags
 $pos = strpos($html , $findme);
 $start_pos = strpos($html , ">" , $pos);
 $end_pos = strpos($html, "<" , $pos);
 $length = ($end_pos-$start_pos);
 $new_string = substr ($html , ($start_pos+1), ($length-1));
 // returns the new string as the output from the function
 return $new_string;
}
//Connect to Novaworld and get the DFX stats page for Jeeep-UA- (ID=109883645088)
$retrievedhtml = file_get_contents("https://www.novaworld.com/Players/DfxStats.aspx?id=109883645088&p=766075");
//Extract the data needed from Jeeep-UA- stats page
$jeeep_kills = get_data ($retrievedhtml , 'lbl6');
$jeeep_deaths = get_data ($retrievedhtml , 'lbl5');


echo "Jeeep-UA- Kills = $jeeep_kills<br>";
echo "Jeeep-UA- deaths = $jeeep_deaths<br>";
echo "<br><br><br>";
echo "$retrievedhtml";
?>
outputs

Code: Select all

Jeeep-UA- Kills = 18463
Jeeep-UA- deaths = 10458
<contents of url>snip</contents of url>
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Just because I am bored...

Code: Select all

<?php
$html = file_get_contents("https://www.novaworld.com/Players/DfxStats.aspx?id=109883645088&p=766075");

/*line breaks preceded by \\\ */

$extremelyConvolutedPattern = "/.*lbl16\">(?P<Experience>.*?)<.*lblPercentile\">(?P<Percentile>.*?)<.*lblXpRank\">(?P<Overall>.*?)<.*lbl1\">(\\\
?P<Playtime>.*?)<.*lbl6\">(?P<Kills>.*?)<.*lbl5\">(?P<Deaths>.*?)<.*lbl7\">(?\\\
P<Ratio>.*?)<.*lblAssistPointRatio\">(?P<AssistPoint>.*?)<.*lbl10\">(?P<Headshots>.*?)<.*lbl11\">(?\\\
P<KnifeKills>.*?)<.*lbl9\">(?P<DoubleKills>.*?)<.*lbl20\">(?P<TKOTHZoneTime>.*?)<.*lbl22\">(?\\\
P<FlagSaves>.*?)<.*lbl23\">(?P<FlagCaptures>.*?)</s";

preg_match($extremelyConvolutedPattern,$html,$mat);
unset($mat[0]); // for easier print_r'ing
echo "<pre>".print_r($mat,1)."</pre>";
?>

Code: Select all

Outputs: Array
(
    [Experience] => 172741
    [1] => 172741
    [Percentile] => 99%
    [2] => 99%
    [Overall] => 242
    [3] => 242
    [Playtime] => 15 days 9 hrs 16 min 
    [4] => 15 days 9 hrs 16 min 
    [Kills] => 18463
    [5] => 18463
    [Deaths] => 10458
    [6] => 10458
    [Ratio] => 1.765
    [7] => 1.765
    [AssistPoint] => 62.54
    [8] => 62.54
    [Headshots] => 1776
    [9] => 1776
    [KnifeKills] => 494
    [10] => 494
    [DoubleKills] => 1
    [11] => 1
    [TKOTHZoneTime] => 9 hrs 2 min 
    [12] => 9 hrs 2 min 
    [FlagSaves] => 275
    [13] => 275
    [FlagCaptures] => 531
    [14] => 531
)
Using the regex may be faster, it would probably be even faster to remove the labels ' ?P<LABEL> ' and just use the array index for the value you want...

Please note: the regex may work now, but if they change their id names, it will break...

<edit> More boredom... MUCH Smaller regex, which should be a little more resistant to change and will probably run a bunch faster...

Code: Select all

$html = file_get_contents("https://www.novaworld.com/Players/DfxStats.aspx?id=109883645088&p=766075");
$pat = '/<span id="Stats_([^\"]*?)">([^<]*?)<\/span>/s';
preg_match_all($pat,$html,$mat);
unset($mat[0]); // for easier print_r'ing
echo "<pre>".print_r($mat,1)."</pre>";
?>

Code: Select all

Outputs:Array
(
    [1] => Array
        (
            [0] => lblProductName
            [1] => lblPlayerName
            [2] => lblRestriction
            [3] => lbl15
            [4] => lbl16
            [5] => lblPercentile
            [6] => lblXpRank
            [7] => lbl1
            [8] => lbl6
            [9] => lbl5
            [10] => lbl7
            [11] => lblAssistPointRatio
            [12] => lbl10
            [13] => lbl11
            [14] => lbl9
            [15] => lbl20
            [16] => lbl22
            [17] => lbl23
            [18] => lblPlayerCreatedDate
            [19] => lblPcid
        )

    [2] => Array
        (
            [0] => Delta Force: Xtreme
            [1] => Jeeep-UA-
            [2] => 
            [3] => Chief Warrant Officer 2nd Tour
            [4] => 172741
            [5] => 99%
            [6] => 242
            [7] => 15 days 9 hrs 16 min 
            [8] => 18463
            [9] => 10458
            [10] => 1.765
            [11] => 62.54
            [12] => 1776
            [13] => 494
            [14] => 1
            [15] => 9 hrs 2 min 
            [16] => 275
            [17] => 531
            [18] => July 18, 2005
            [19] => 8S-W352NN   
        )

)
</edit>
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

wow great stuff you guys! however when i save these into a php file and upload them to my server (w/ either 777 or 755 permissions) these scripts dont work either. am i doing something wrong while uploading them?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

it's very possible that the server you're trying to hit is looking for a specific user agent. I had a similar problem when trying to get BF2 stats. You might try researching to determine if the user agent must be something specific. If so, just set it in your cURL.
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

would this specific user agent vary from server to server? my friend is using the same script on his server and everything is working properly.
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

ole wrote:
"This page cannot be displayed" by IE
Yeah that is a network problem not a PHP problem. Your PHP isn't being executed.
What would you suggest fix with-in the network?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I've seen this kind of behavior when the script is timing out or hits an infinite loop, try setting

Code: Select all

set_time_limit(180);
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

Yeah that seems to help, well atleast now I get a blank page other than an error page.
I've even got intouch with a Nova-Admin to ask him questions and when I forward them to my hosting ppl they just brush off what he says. Needless to say they have given up hope on this issue and wont help me any further. Now I just found out that they have suspended any further work on my server b/c its taking up "too many resources" (one of my test scripts). All this is pretty funny. Anyways here is the reply from the Nova-Admin; maybe you guys will listen.
"Well, if they are using Telnet to troubleshoot, that won't work. Telnet sessions would be terminated and may produce that kind of error.

We don't have any class C networks blocked or filtered, just a handfull of troublesome IPs are blocked. I verified that your site is not on that list.

You can try specifying a user agent, but I don't think that will make a difference. I have done GET requests on the server using little http apps in the past when we were troubleshooting some other issue and that app did not specify a user agent. Were you able to get the specific error from the server error logs? That would tell you pretty reliably what is failing in the script or why it's failing. "
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

Here is the failed attempt on my error logs:
[Wed May 3 06:17:20 2006] [error] [client 12.296.922.478] File does not exist: /home/uaxtrem/public_html/500.shtml
[Wed May 3 06:17:20 2006] [error] [client 12.296.922.478] Premature end of script headers: /home/uaxtrem/public_html/statsigfetch3.php
Post Reply