Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Call on ASP Variables via PHP

    Hello People, i have a problem with a PHP script which i downloaded on the Net. The Script Calls one ASP URL for Statistic Data of a Game. I want to display some of this Stats on my Website. Can someone help me out there ?
    Because im not a professional

    Okay this is the where the Script is located :

    http://65.254.53.148/bf2/Bf2View.cgi

    The name of the File is : bf2-xml_parser.zip / PHP to XML

    CODE :

    PHP Code:

        $titleFile = "titles";
        $titleFileDelimiter = ",";
        
        if(file_exists($titleFile)) {
            $titleData = file($titleFile);
            $titleArrayCounter = 0;
            for($a=0;$a<count($titleData);$a++) {
                $titleArrayTemp = explode($titleFileDelimiter,$titleData[$a]);
                $unfriendlyTitleArray[$titleArrayCounter] = $titleArrayTemp[0];
                $titleTypeArray[$titleArrayCounter] = $titleArrayTemp[1];
                $friendlyTitleArray[$titleArrayCounter] = $titleArrayTemp[2];
                $titleArrayCounter++;
            }
        } else {
            echo "The file containing rank feed heading definitions was not found (".$titleFile.").";
            exit();
        }

        function parseRank($rankFile, $unfriendlyTitleArray, $titleTypeArray, $friendlyTitleArray) {
            $rankData = file($rankFile);
            if(substr($rankData[4],2,2) == "-1") {
                echo "No account with that name was found.<br><br>\n\n";
                makeForm($_GET['accountName']);
                exit();
            }
            echo "<?xml version="1.0\" encoding=\"UTF-8\"?>\n\n<root>\n";
            
    $badSymbols = array("\n""\r");
            for(
    $i=1;$i<4;$i+=2) {
                
    $rankHeadingLine str_replace($badSymbols''explode("\t",$rankData[$i]));
                
    $rankDataLine explode("\t",$rankData[$i+1]);
                for(
    $k=1;$k<count($rankHeadingLine);$k++) {
                    
    $headingData makeFriendlyHeading($rankHeadingLine[$k], $unfriendlyTitleArray$titleTypeArray$friendlyTitleArray);
                    
    $contentData makeFriendlyContent($rankHeadingLine[$k], $unfriendlyTitleArray$rankDataLine[$k], $titleTypeArray);
                    echo 
    "  <".$rankHeadingLine[$k]." friendly=\"".$headingData."\">".$contentData."</".$rankHeadingLine[$k].">\n";
                }
            }
            echo 
    "</root>\n";
        }
        
        function 
    makeFriendlyElapsedTime($time 0) {
            
    $hours    = (int)floor($time/3600);
            
    $minutes  = (int)floor($time/60)%60;
            
    $seconds  = (int)$time%60;
            if(
    $hours && $hours 10) {
                
    $txt "0".$hours.":";
            } else if(
    $hours 10) {
                
    $txt $hours.":";
            } else {
                
    $txt "00:";
            }
             if(
    $minutes && $minutes 10) {
                
    $txt .= "0".$minutes.":"
            } else if(
    $minutes 10) {
                
    $txt .= $minutes.":";
            } else {
                
    $txt .= "00:";
            }
            if(
    $seconds>&& $seconds 10) {
                
    $txt .= "0".$seconds;
            } else if(
    $seconds 10) {
                
    $txt .= $seconds;
            } else {
                
    $txt .= "00";
            }
            return(
    $txt);
        }

        function 
    makeFriendlyHeading($rawContent$unfriendlyTitleArray$titleTypeArray$friendlyTitleArray) {
            for(
    $j=0;$j<count($unfriendlyTitleArray);$j++) {
                if(
    trim($rawContent) == trim($unfriendlyTitleArray[$j])) {
                    return(
    trim($friendlyTitleArray[$j]));
                    exit();
                }
            }
            return(
    trim($rawContent));
            exit();
        }

        function 
    makeFriendlyContent($headingContent$unfriendlyTitleArray$rawContent$titleTypeArray) {
            for(
    $l=0;$l<count($unfriendlyTitleArray);$l++) {
                if(
    trim($headingContent) == trim($unfriendlyTitleArray[$l])) {
                    if(
    trim($titleTypeArray[$l]) == "T") {
                        return(
    trim(date("Y-m-d"$rawContent)));
                        exit();
                    } else if(
    trim($titleTypeArray[$l]) == "E") {
                        return(
    trim(makeFriendlyElapsedTime($rawContent)));
                        exit();
                    } else if(
    trim($titleTypeArray[$l]) == "%") {
                        return(
    trim($rawContent."%"));
                        exit();
                    }
                }
            }
            return(
    trim($rawContent));
            exit();
        }

        function 
    makeForm($oldAccount) {
            echo 
    "You can download this script for non-commercial use by clicking <a href=\"./bf2-xml_parser.zip\">here</a><br><br>\n\n";
            echo 
    "<form action=\"./index.php\">\n\n";
            echo 
    "Enter BattleField 2 <b>account name</b>: <input type=\"text\" name=\"accountName\" value=\"".$oldAccount."\">\n\n<br><br>";
            echo 
    "<input type=\"submit\" value=\"Submit\">\n\n";
            echo 
    "</form>";
        }

        if(isset(
    $_GET['accountName'])) {
            
    $badSymbols = array("\n""\r""?""&");
            
    $accountName str_replace($badSymbols''trim($_GET['accountName']));
            if(
    $accountName <> trim($_GET['accountName'])) {
                echo 
    "The account name you entered was malformed, please try again.\n\n<br><br>\n\n";
                
    makeForm(trim($_GET['accountName']));
                exit();
            }            
            
    $rankURL "http://bf2web.gamespy.com/ASP/getplayerinfo.aspx?nick=".$accountName."&info=&debug=tx&nocache=".rand(50032768) * rand(50032768);
            
    parseRank($rankURL$unfriendlyTitleArray$titleTypeArray$friendlyTitleArray$allowLocalRankFile$allowXMLSave);
        } else {
                
    makeForm('');
        }
    In case there is a PHP to XML Parser which is good , but how can i read out
    the calls in PHP and display just a couple of the Stats in HTML Format ?

    Thank you, Human
    Last edited by Human; 07-03-2005 at 06:07 AM.

  • #2
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Someone has a clue ? Please Help !

  • #3
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay i found another way now to get the Data, but how can i get this Formatted and displayed in a good order and in plain HTML Format ?

    Now im getting this Result :


    HTTP/1.1 200 OK Date: Mon, 04 Jul 2005 02:01:07 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 1.1.4322 Pragma: no-cache Set-Cookie: ASP.NET_SessionId=dp1l4k455z31gtjoosa5ywit; path=/ Cache-Control: private Expires: Mon, 04 Jul 2005 02:01:07 GMT Content-Type: text/html; charset=utf-8 Content-Length: 88 O H asof D 1120417267 H pid nick scor cmsc D 43411067 Human_{Kamikaze} 1765 1420 $ 66
    PHP Code:

    ini_set
    ("allow_url_fopen",true);
    $fp fsockopen ("bf2web.gamespy.com"80$errno$errstr30);
    if (!
    $fp) {
       echo 
    "$errstr ($errno)\n";
    } else {

       
    fputs ($fp"GET /ASP/getplayerinfo.aspx?nick=Human_{Kamikaze}&info=scor&info=cmsc&debug=tx&nocache=632555423584611697 HTTP/1.1\r\n");
    fputs($fp,"Host: bf2web.gamespy.com\r\n");
    fputs($fp,"Connection: close\r\n\r\n");

       while (!
    feof($fp)) {
           echo 
    fgets($fp,128);
       }
       
    fclose($fp);

    The Values of each Variable is Important to me, can someone help me out there ?

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    This:
    HTTP/1.1 200 OK Date: Mon, 04 Jul 2005 02:01:07 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 1.1.4322 Pragma: no-cache Set-Cookie: ASP.NET_SessionId=dp1l4k455z31gtjoosa5ywit; path=/ Cache-Control: private Expires: Mon, 04 Jul 2005 02:01:07 GMT Content-Type: text/html; charset=utf-8 Content-Length: 88 O H asof D 1120417267 H pid nick scor cmsc D 43411067 Human_{Kamikaze} 1765 1420 $ 66
    Is almost irrelivent for what you need. All that matters IMO is your HTTP/1.1 200 OK.

    What I need to see, as opposed to all that stuff in your pages there, is what your input and output will be. What you need to retrieve for instance. What would be nice is an xml output instead, but if thats not an option, please let me know where you can find what you are looking for, between tables, ids, etc. This is simply a matter of matching in that case.

    What I don't understand, is that I was under the impression of this being a reading question, you appear to be trying to write to the files. Please let me know what thats about too.

  • #5
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay i found another way to get my Data, which is fine so far, but
    im not able to create Line breakes in Tables. dont know how to create them.

    PHP Code:

    <?php

        $titleFile 
    "titles";
        
    $titleFileDelimiter ",";
        
    $accountName $_REQUEST['id'];
        
        if(
    file_exists($titleFile)) {
            
    $titleData file($titleFile);
            
    $titleArrayCounter 0;
            for(
    $a=0;$a<count($titleData);$a++) {
                
    $titleArrayTemp explode($titleFileDelimiter,$titleData[$a]);
                
    $unfriendlyTitleArray[$titleArrayCounter] = $titleArrayTemp[0];
                
    $titleTypeArray[$titleArrayCounter] = $titleArrayTemp[1];
                
    $friendlyTitleArray[$titleArrayCounter] = $titleArrayTemp[2];
                
    $titleArrayCounter++;
            }
        } else {
            echo 
    "The file containing rank feed heading definitions was not found (".$titleFile.").";
            exit();
        }

        function 
    parseRank($rankFile$unfriendlyTitleArray$titleTypeArray$friendlyTitleArray) {
            
    $rankData file($rankFile);
            if(
    substr($rankData[4],2,2) == "-1") {
                echo 
    "No account with that name was found.<br><br>\n\n";
                exit();
            }
            echo 
    "\n";
            
    $badSymbols = array("\n""\r");
            for(
    $i=1;$i<4;$i+=2) {
                
    $rankHeadingLine str_replace($badSymbols''explode("\t",$rankData[$i]));
                
    $rankDataLine explode("\t",$rankData[$i+1]);
                for(
    $k=1;$k<count($rankHeadingLine);$k++) {
                    
    $headingData makeFriendlyHeading($rankHeadingLine[$k], $unfriendlyTitleArray$titleTypeArray$friendlyTitleArray);
                    
    $contentData makeFriendlyContent($rankHeadingLine[$k], $unfriendlyTitleArray$rankDataLine[$k], $titleTypeArray);
                    echo 
    "  <tr><td bgcolor=\"ffffff\">".$headingData." :</td><td bgcolor=\"ffffff\" name=\"".$rankHeadingLine[$k]."\" friendly=\"".$headingData."\">".$contentData."</td></tr>\n";
                }
            }
            echo 
    "\n";
        }
        
        function 
    makeFriendlyElapsedTime($time 0) {
            
    $hours    = (int)floor($time/3600);
            
    $minutes  = (int)floor($time/60)%60;
            
    $seconds  = (int)$time%60;
            if(
    $hours && $hours 10) {
                
    $txt "0".$hours.":";
            } else if(
    $hours 10) {
                
    $txt $hours.":";
            } else {
                
    $txt "00:";
            }
             if(
    $minutes && $minutes 10) {
                
    $txt .= "0".$minutes.":"
            } else if(
    $minutes 10) {
                
    $txt .= $minutes.":";
            } else {
                
    $txt .= "00:";
            }
            if(
    $seconds>&& $seconds 10) {
                
    $txt .= "0".$seconds;
            } else if(
    $seconds 10) {
                
    $txt .= $seconds;
            } else {
                
    $txt .= "00";
            }
            return(
    $txt);
        }

        function 
    makeFriendlyHeading($rawContent$unfriendlyTitleArray$titleTypeArray$friendlyTitleArray) {
            for(
    $j=0;$j<count($unfriendlyTitleArray);$j++) {
                if(
    trim($rawContent) == trim($unfriendlyTitleArray[$j])) {
                    return(
    trim($friendlyTitleArray[$j]));
                    exit();
                }
            }
            return(
    trim($rawContent));
            exit();
        }

        function 
    makeFriendlyContent($headingContent$unfriendlyTitleArray$rawContent$titleTypeArray) {
            for(
    $l=0;$l<count($unfriendlyTitleArray);$l++) {
                if(
    trim($headingContent) == trim($unfriendlyTitleArray[$l])) {
                    if(
    trim($titleTypeArray[$l]) == "T") {
                        return(
    trim(date("Y-m-d"$rawContent)));
                        exit();
                    } else if(
    trim($titleTypeArray[$l]) == "E") {
                        return(
    trim(makeFriendlyElapsedTime($rawContent)));
                        exit();
                    } else if(
    trim($titleTypeArray[$l]) == "%") {
                        return(
    trim($rawContent."%"));
                        exit();
                    }
                }
            }
            return(
    trim($rawContent));
            exit();
            }            
            
    $rankURL "http://bf2web.gamespy.com/ASP/getplayerinfo.aspx?nick=".$accountName."&info=scor&info=cmsc&info=jond&info=bbrs&info=smoc&debug=tx&nocache=".rand(50032768) * rand(50032768);
            
    parseRank($rankURL$unfriendlyTitleArray$titleTypeArray$friendlyTitleArray$allowLocalRankFile$allowXMLSave);


    ?>
    The problem for me now is this line :


    PHP Code:
    function parseRank($rankFile$unfriendlyTitleArray$titleTypeArray$friendlyTitleArray) {
            
    $rankData file($rankFile);
            if(
    substr($rankData[4],2,2) == "-1") {
                echo 
    "No account with that name was found.<br><br>\n\n";
                exit(); 
    Okay here a sample for a Player with Stats : http://www.kamikaze-clan.com/members.php [ click on Human_{Kamikaze} ]
    For getting the exit(); view of it , with no stats look at DJ_{Kamikaze}

    How can i get this to work as a same look ? For Players with the Stats, with Table. And for thos without Stats , without Stats Table ?

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Ok, so your looking to simply grab the information for that user you specify correct? Both the profile and profile comment yeah?
    Hmm, this isn't going to be easy. There is no identifiable information from the code that has been provided, its simply a layout of html tables, no id's or anything of the sorts.
    Under the assumption this is not your website, I'd suggest asking the webmaster if they either do, or if they can impliment an xml/rss feed for you to gather your information off of. Simple task for them, even simpler for you.

  • #7
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The Kamikaze-Clan.com Website is mine, i implemented the Code to the Player Profiles.

    Would like to know how make it sorted , like this site here :

    http://www.got3n.com/stats.php

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Ok, lets see here.
    First, watch for this:
    Don\'t run you\'ll die tired, don\'t camp you\'ll only die fat!
    A simple stripslashes() around the variable or array that is called from will remove that problem.
    So you appear to have everything you need, which is great. To me, it looks quite good.
    I'm not sure what your looking at altering the order of. Without knowing how this code looks within where you are receiving it from makes it a littler harder, but no worries. Off hand, I'd say your looking for the order in which the users appear on the screen to be chosen, is that correct? I assume this from what is shown in your comparison url.

    Is this comming from XML to start with BTW? Cause if your using an rss feed for it, we can make this reaaaalllllyyyy easy. I'm just wondering cause of this line here:
    echo "The file containing rank feed heading definitions was not found (".$titleFile.").";
    Please let me know on that one, you can avoid a lot of this stuff by using either an XML->xsl processor server side, or by using the XML DOM in that case.

    Otherwise, let me know what your looking at sorting, as well as the array its located in. It'll be a cinch from there.
    Or, you can give me a copy file of the raw data, and how you would like it to appear with a simple example. I'd be able to throw it together for you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •