stormx Posted August 30, 2008 Share Posted August 30, 2008 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? Link to comment https://forums.phpfreaks.com/topic/122045-solved-fsock-getting-from-ssl-issues/ Share on other sites More sharing options...
DarkWater Posted August 30, 2008 Share Posted August 30, 2008 Use cURL or try using \r\n instead of \n. Link to comment https://forums.phpfreaks.com/topic/122045-solved-fsock-getting-from-ssl-issues/#findComment-630017 Share on other sites More sharing options...
stormx Posted August 30, 2008 Author Share Posted August 30, 2008 Could you give me a working cURL script? I can't seem the find them on google :-\ Link to comment https://forums.phpfreaks.com/topic/122045-solved-fsock-getting-from-ssl-issues/#findComment-630020 Share on other sites More sharing options...
DarkWater Posted August 30, 2008 Share Posted August 30, 2008 <?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("<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>"; ?> Link to comment https://forums.phpfreaks.com/topic/122045-solved-fsock-getting-from-ssl-issues/#findComment-630025 Share on other sites More sharing options...
stormx Posted August 31, 2008 Author Share Posted August 31, 2008 Unfortunately that script you gave me doesn’t even echo anything. Even if I do: <?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); echo curl_exec($ch); ?> Thanks for it, I just don't know why it's not working:( Link to comment https://forums.phpfreaks.com/topic/122045-solved-fsock-getting-from-ssl-issues/#findComment-630029 Share on other sites More sharing options...
stormx Posted August 31, 2008 Author Share Posted August 31, 2008 Is it anything to do with my php.ini? Link to comment https://forums.phpfreaks.com/topic/122045-solved-fsock-getting-from-ssl-issues/#findComment-630040 Share on other sites More sharing options...
DarkWater Posted August 31, 2008 Share Posted August 31, 2008 <?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("<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>"; ?> I swear I had put that in code tags earlier. I think you may need to set some specific SSL options with curl_setopt. Check out the manual page here: http://us3.php.net/manual/en/function.curl-setopt.php And play around with it until it works. Try using https:// instead of ssl://, by the way. Link to comment https://forums.phpfreaks.com/topic/122045-solved-fsock-getting-from-ssl-issues/#findComment-630056 Share on other sites More sharing options...
stormx Posted August 31, 2008 Author Share Posted August 31, 2008 You are a legend DarkWater, it fully works I owe you a million thankyou's. Link to comment https://forums.phpfreaks.com/topic/122045-solved-fsock-getting-from-ssl-issues/#findComment-630082 Share on other sites More sharing options...
DarkWater Posted August 31, 2008 Share Posted August 31, 2008 You are a legend DarkWater, it fully works I owe you a million thankyou's. Lol, no problem. 999,999 more to go, by the way. Link to comment https://forums.phpfreaks.com/topic/122045-solved-fsock-getting-from-ssl-issues/#findComment-630083 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.