Solved

ASP, PHP, or XML Question

Posted on 2009-06-30
4
378 Views
Last Modified: 2013-12-13
We need to create XML parsing. Company XYZ has developed a program for us to use. We are supposed to have replicated sites and Company XYZ controls the backend database. We have to create something to get their data. We have to program a code to pull the url to get a repid(user id)  from the rename(user name), and the repid has to imported into the website so that the repid can be associated to an iframe and edi.asp calls.

Example: http://mywebsite.com/myname myname has to be pulled from the url, get the associated repid, then associate a name, email, order data, and such with it. After the data is pulled in storage, we needto hold it storage and use it later that session in an iframe or page to associate repid with sales, signups, and pull contact info into a page.
The edi.asp link points to XML data. We need to extract that that based on repid and display it into a webpage and associate sales to distributor that sent them to the site.
Sample url we have to extract xml data from. http://shop.mywebsite.com/EDI.asp?companyid=111&apikey=aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa&type=countries (numbers have been changed for security)
here is a sample code they sent us:
VBScript as your scripting language: Can this be translated from asp to PHP in order to use on a linux server to get the xml data from a sql database using asp.net?

VBScript as your scripting language:
 
            function fcnGetXML(RepURL) 
 
                        DataToSend = "companyid=111&apikey=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&type=reps&sitename=" & RepURL
                        servername = cstr(request.ServerVariables("Server_Name"))
 
                        postUrl = "http://subdomain.mywebsite.com/EDI.asp"
 
                        'Set url to send request to including web service name.
 
                        postUrl = postUrl                  
 
                        Set xmlhttp = server.Createobject("MSXML2.XMLHTTP")
 
                        'Prepare request header.
 
                        xmlhttp.Open "POST",postUrl,false
 
                        xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"                      
 
                        'Send request:
 
                        xmlhttp.send DataToSend
 
                        If cstr(xmlhttp.Status) = "200" then
 
                                    'Success, parse result
 
                                    fcnGetXML = xmlhttp.responseText
 
                        Else
 
                                    'failure handle failure
 
                                    fcnGetXML = "0"
 
                        End if
 
            end function

Open in new window

0
Comment
Question by:itsmedtt
  • 2
4 Comments
 
LVL 16

Expert Comment

by:golfDoctor
ID: 24745536
0
 
LVL 16

Assisted Solution

by:golfDoctor
golfDoctor earned 100 total points
ID: 24745538
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 400 total points
ID: 24745633
This teaches the way to translate your function into PHP.  HTH, ~Ray
<?php // RAY_temp_fcnGetXML.php with PHP as your scripting language:
error_reporting(E_ALL);
 
// DECLARE THE FUNCTION
function fcnGetXML($RepURL)
{
// THE SITE WE WANT TO TALK TO
    $server_url  = "subdomain.mywebsite.com";
 
// THE PAGE INSIDE THE WEB SITE
    $request_uri = "/EDI.asp";
 
// THE POST DATA THAT WE WANT TO SEND
    $dat = array(
      'companyid' => '111',
      'apikey'    => 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
      'type'      => 'reps',
      'sitename'  => $RepURL
     );
 
// CONSTRUCT THE POST STRING URLENCODED AND SEPARATED BY AMPERSANDS
    $postdata  = '';
    foreach ($dat as $key => $val)
    {
        $postdata .= '&' . $key . '=' . urlencode($val);
    }
    $postdata = ltrim($postdata, '&');
 
// CONSTRUCT THE HEADERS
    $header = '';
    $header .= "POST $request_uri HTTP/1.0\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($postdata) . "\r\n\r\n";
 
// SHOW WHAT WE ARE GOING TO DO - OMIT THIS SEGMENT IN PRODUCTION CODE
    echo "<pre>\n";
    echo "REQUEST DATA FOLLOWS:\n";
    var_dump($server_url);
    var_dump($request_uri);
    var_dump($postdata);
    var_dump($header);
    echo "</pre>\n";
 
 
// OPEN THE SOCKET TO THE PAGE
    $fp = fsockopen ($server_url, 80, $errno, $errstr, 30);
 
// TEST FOR VERIFICATION
    if (!$fp)
    {
        die("HTTP ERROR $server_url $request_uri fsockopen() FAILED ERRNO=$errno ERRSTR=$errstr");
    }
 
// HTTP OPEN - WRITE HEADER AND REQUEST
    fputs ($fp, $header . $postdata);
 
// HTTP OPEN - READ RESPONSE
    $reply = '';
    while (!feof($fp))
    {
        $reply .= fgets($fp, 1024);
    }
 
// SEE WHAT THE FOREIGN SITE SAID  - OMIT THIS SEGMENT IN PRODUCTION CODE
    echo "<pre>\n";
    echo htmlentities($reply);
    echo "</pre>\n";
 
// RETURN THE DATA
    return $reply;
 
} // END OF FUNCTION
 
 
// SAMPLE CALLING SEQUENCE
$rep_identity = 'Billy';
$xml_response = fcnGetXML($rep_identity);
echo $xml_response;

Open in new window

0
 

Author Comment

by:itsmedtt
ID: 24747428
Thanks for your replies. Let me check these out and I will get back to you.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
edit .asp files 5 31
Wordpress Cron - Send XML Data to external server FTP 3 22
Html value of radio 14 28
Reg Exp to extract Url from string asp 12 14
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question