Page 2 of 3

Re: allow_url_fopen Issue

Posted: Tue Nov 22, 2011 3:38 am
by dt22
no its not empty

Re: allow_url_fopen Issue

Posted: Tue Nov 22, 2011 3:40 am
by maxx99
What does it contain then? :)

Re: allow_url_fopen Issue

Posted: Tue Nov 22, 2011 3:45 am
by dt22
it contains the username and password and sms message, receiving person mobile number etc..

Re: allow_url_fopen Issue

Posted: Tue Nov 22, 2011 3:48 am
by maxx99
Returned string should be the same as the source of page under URL you provided.
Is it the same? maybe it contains some errors? what do you expect to get in return from the .jsp page?

Re: allow_url_fopen Issue

Posted: Tue Nov 22, 2011 3:53 am
by dt22
ok... i will detail my problem once again ok.. am sending sms to students of my db and its a crone job.. and the for loop must perform continuously still it send sms to all.. so each time the mobile number will change and all the other thinks will remain same...

Re: allow_url_fopen Issue

Posted: Tue Nov 22, 2011 3:58 am
by dt22
i tried to echo the string then i got like this: Error 0: php_network_getaddresses: getaddrinfo failed: No such host is known.

Re: allow_url_fopen Issue

Posted: Tue Nov 22, 2011 3:58 am
by maxx99
Ok thats clear.
How does the source of the page looks when you open it with your browser?

http://www.bulksms.mysmsmantra.com:8080 ... ssage=text

It should be the same as $string variable. If it is that means that request was a success and your message should be sent (or not if theres a problem on external service).

Re: allow_url_fopen Issue

Posted: Tue Nov 22, 2011 4:03 am
by dt22
$string = http_request('GET', 'www.bulksms.mysmsmantra.com', 8080,'/WebSMS/SMSAPI.jsp', array('username'=>$sms_details[1],"password"=>$sms_details[2],"sendername"=>$sms_details[3],"mobileno"=>$row['stud_parent_primary_mobile'],"message"=>$msg));
print_r($string);

giving output like: Error 0: php_network_getaddresses: getaddrinfo failed: No such host is known.

Re: allow_url_fopen Issue

Posted: Tue Nov 22, 2011 4:36 am
by maxx99
Id suggest to change www.bulksms.mysmsmantra.com to bulksms.mysmsmantra.com
Paste your response for this URL

Re: allow_url_fopen Issue

Posted: Tue Nov 22, 2011 4:51 am
by dt22
i tried it and nothing happening.. working fine in localhost...

$string = http_request('GET', 'bulksms.mysmsmantra.com', 8080,'/WebSMS/SMSAPI.jsp', array('username'=>$sms_details[1],"password"=>$sms_details[2],"sendername"=>$sms_details[3],"mobileno"=>$row['stud_primary_mobile'],"message"=>$msg));

Re: allow_url_fopen Issue

Posted: Tue Nov 22, 2011 5:13 am
by maxx99
And is the content of $string still "Error 0: php_network_getaddresses: getaddrinfo failed: No such host is known." ?

Are you sure that you have access from your server to outside world? :) and your DNS can resolve that hostname?

Re: allow_url_fopen Issue

Posted: Tue Nov 22, 2011 5:13 am
by dt22
i tried another method also:

$oDOMDocument = new DOMDocument();
$oDOMDocument->formatOutput = true;
$oDOMDocument->loadHTMLFile('http://bulksms.mysmsmantra.com:8080/Web ... eno='.$row['stud_parent_primary_mobile'].'&message='.$msg);

its also working fine with local host but showing error in server: like this:

Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: Document is empty in http://bulksms.mysmsmantra.com:8080/Web ... cvbxcbxcvb, line: 1 in

Re: allow_url_fopen Issue

Posted: Tue Nov 22, 2011 5:18 am
by dt22
yes...because all the functions working finely from my local host.... even thats file_get_contents...all getting trouble when uploading it to server.

Re: allow_url_fopen Issue

Posted: Tue Nov 22, 2011 5:19 am
by maxx99

Code: Select all

<?php 
function http_request( 
     $verb = 'GET',             /* HTTP Request Method (GET and POST supported) */ 
     $ip,                       /* Target IP/Hostname */ 
     $port = 80,                /* Target TCP port */ 
     $uri = '/',                /* Target URI */ 
     $getdata = array(),        /* HTTP GET Data ie. array('var1' => 'val1', 'var2' => 'val2') */ 
     $postdata = array(),       /* HTTP POST Data ie. array('var1' => 'val1', 'var2' => 'val2') */ 
     $cookie = array(),         /* HTTP Cookie Data ie. array('var1' => 'val1', 'var2' => 'val2') */ 
     $custom_headers = array(), /* Custom HTTP headers ie. array('Referer: http://localhost/ */ 
     $timeout = 1000,           /* Socket timeout in milliseconds */ 
     $req_hdr = false,          /* Include HTTP request headers */ 
     $res_hdr = false           /* Include HTTP response headers */ 
     ) 
 { 
     $ret = ''; 
     $verb = strtoupper($verb); 
     $cookie_str = ''; 
     $getdata_str = count($getdata) ? '?' : ''; 
     $postdata_str = ''; 

     foreach ($getdata as $k => $v) 
                 $getdata_str .= urlencode($k) .'='. urlencode($v) . '&'; 

     foreach ($postdata as $k => $v) 
         $postdata_str .= urlencode($k) .'='. urlencode($v) .'&'; 

     foreach ($cookie as $k => $v) 
         $cookie_str .= urlencode($k) .'='. urlencode($v) .'; '; 

     $crlf = "\r\n"; 
     $req = $verb .' '. $uri . $getdata_str .' HTTP/1.1' . $crlf; 
     $req .= 'Host: '. $ip . $crlf; 
     $req .= 'User-Agent: Mozilla/5.0 Firefox/3.6.12' . $crlf; 
     $req .= 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' . $crlf; 
     $req .= 'Accept-Language: en-us,en;q=0.5' . $crlf; 
     $req .= 'Accept-Encoding: deflate' . $crlf; 
     $req .= 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7' . $crlf; 
     
     foreach ($custom_headers as $k => $v) 
         $req .= $k .': '. $v . $crlf; 
         
     if (!empty($cookie_str)) 
         $req .= 'Cookie: '. substr($cookie_str, 0, -2) . $crlf; 
         
     if ($verb == 'POST' && !empty($postdata_str)) 
     { 
         $postdata_str = substr($postdata_str, 0, -1); 
         $req .= 'Content-Type: application/x-www-form-urlencoded' . $crlf; 
         $req .= 'Content-Length: '. strlen($postdata_str) . $crlf . $crlf; 
         $req .= $postdata_str; 
     } 
     else $req .= $crlf; 
     
     if ($req_hdr) 
         $ret .= $req; 
     
     if (($fp = @fsockopen($ip, $port, $errno, $errstr)) == false) 
         return "Error $errno: $errstr\n"; 
     
     stream_set_timeout($fp, 0, $timeout * 1000); 
     
     fputs($fp, $req); 
     while ($line = fgets($fp)) $ret .= $line; 
     fclose($fp); 
     
     if (!$res_hdr) 
         $ret = substr($ret, strpos($ret, "\r\n\r\n") + 4); 
     
     return $ret; 
 } 
?> 

 Example usages : 

<?php 
 $string =  http_request('GET', 'bulksms.mysmsmantra.com', 8080,'/WebSMS/SMSAPI.jsp' , array('username'=>'dsdasd',"password"=>'sdasdasd','sendername'=>'xxx','mobileno'=>'111','message'=>'xxx'));

echo $string;


?>
This works for me.
Returns

Code: Select all

Example usages : You are not a registered user. 
If its not working for you, you probably need to do something with your config (to get access to that host)

Re: allow_url_fopen Issue

Posted: Tue Nov 22, 2011 5:21 am
by maxx99
dt22 wrote:yes...because all the functions working finely from my local host.... even thats file_get_contents...all getting trouble when uploading it to server.
I get that. But if its working locally that means that there is a configuration problem on remote server.