Hello All,

I am currently running a script to strip an .xml file and get the contents, that part of my script works. The part that doesn't is the FSOCK open to get the .xml

This is my code:

<?php


$link = "ssl://www.exetel.com.au/members/usagemeter.php?username,password";

$http_response = "";
$url = parse_url($link);
$fp = fsockopen($url[host], 443, $err_num, $err_msg, 30) or
die("Socket-open
failed--error: ".$err_num." ".$err_msg);
fputs($fp, "GET /$url[path]?$url[query] HTTP/1.0\n");
fputs($fp, "Connection: close\n\n");
 while(!feof($fp)) {
$http_response .= fgets($fp, 128);
 }
 fclose($fp);

$str = $http_response;

$tmp_explode = explode("<br>", $str);

$data = array();

foreach($tmp_explode as $line){
	$tmp_line = explode("=", $line);
	$data[$tmp_line[0]] = $tmp_line[1];
}

echo "<pre>";
echo $data['data_down'];
echo "</pre>";

?>

If I echo $http_response; the remote server says it can't understand my request, what seems to be the issue?

I also made a cURL script:

<?php
$link = "ssl://www.exetel.com.au/members/usagemeter.php?username,password";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$str = curl_exec($ch);

$tmp_explode = explode("
", $str);

$data = array();

foreach($tmp_explode as $line){
   $tmp_line = explode("=", $line);
   $data[$tmp_line[0]] = $tmp_line[1];
}

echo "

";
echo $data[

'data_down'];
echo "";

?>

This one doesn't echo anything, whats wrong?

    You have a couple errors. I'm going to correct the fsockopen version since I'm guessing you prefer that over the curl version.

    1) In the line fsockopen (...), make sure you add "ssl://" to the hostname. Right now you are only passing the hostname to fsockopen since parse_url does not retain the "ssl://" in the hostname. So it should look like this:

    fsockopen ("ssl://" . $url['host'], 443, ....

    2) This may not be required, but I highly recommend using braces {} to enclose complex variables inside quotes. So the line w/ the GET query should look like this:

    fputs ($fp, "GET {$url['path']}?{$url['query']} HTTP/1.0\r\n");

    Also Note that I used "\r\n" instead of just "\n". You have to terminate all lines with "\r\n".

    3) In the Connection close line, you need to terminate the line with "\r\n\r\n" instead of "\n\n"... basically add the carriage return character in there.

    Hope you get it working,
    -sridhar

      Write a Reply...