allow_url_fopen Issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

dt22
Forum Commoner
Posts: 32
Joined: Sat Oct 10, 2009 2:53 am

allow_url_fopen Issue

Post by dt22 »

Hi all,

Am in a big trouble.. Am handling the file_get_contents and it is working excellent in my local host. but the server am using is a shared server which is showing allow_url_fopen as On but disable_functions: show_source, system, shell_exec, passthru, exec, popen, proc_open, allow_url_fopen. And it is not working with the server. is there anything i can do to change allow_url_fopen from the disable_functions list.

Or is there any other functions like file_get_content to handle third party url without conflict with the allow_url_fopen because i can't change this.

Somebody please guide me. Thanks in advance.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: allow_url_fopen Issue

Post by Celauran »

Have you looked at cURL?
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: allow_url_fopen Issue

Post by maxx99 »

dt22
Forum Commoner
Posts: 32
Joined: Sat Oct 10, 2009 2:53 am

Re: allow_url_fopen Issue

Post by dt22 »

i tried all that but these are not working with the server i don't know why...
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: allow_url_fopen Issue

Post by maxx99 »

Do you get any notices or error messages?
dt22
Forum Commoner
Posts: 32
Joined: Sat Oct 10, 2009 2:53 am

Re: allow_url_fopen Issue

Post by dt22 »

Warning: fsockopen() [function.fsockopen]: unable to connect to url details :80 (Unable to find the socket transport "http" - did you forget to enable it when you configured PHP?) in /sms-placement.php on line 57
Unable to find the socket transport "http" - did you forget to enable it when you configured PHP? (0)..

This is the warning coming.. this is a page which used to send the sms to the students in our db
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: allow_url_fopen Issue

Post by maxx99 »

Try to remove http:// from your our provide only hostname like: fsockopen('www.example.com')
dt22
Forum Commoner
Posts: 32
Joined: Sat Oct 10, 2009 2:53 am

Re: allow_url_fopen Issue

Post by dt22 »

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: allow_url_fopen Issue

Post by maxx99 »

Could you provide some code of yours? do you try to pass some data with GET?
dt22
Forum Commoner
Posts: 32
Joined: Sat Oct 10, 2009 2:53 am

Re: allow_url_fopen Issue

Post by dt22 »

$fp = fsockopen('www.bulksms.mysmsmantra.com:8080/WebSMS ... eno='.$row['stud_primary_mobile'].'&message='.$msg, 80, $errno, $errstr, 30);

This is the url am trying to open..

if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= 'Host: http://www.bulksms.mysmsmantra.com:8080 ... eno='.$row['stud_primary_mobile'].'&message='.$msg.'\r\n';
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp); }
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: allow_url_fopen Issue

Post by maxx99 »

Just as i thought :) you cannot do this
You can work with this function or just see how the GET params are passed (with fputs) After you open a socket

Code: Select all

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 :

Code: Select all

 $string =  http_request('GET', 'www.youtube.com', 80, array('param1'=>'value1',"param2"=>'value2'));
dt22
Forum Commoner
Posts: 32
Joined: Sat Oct 10, 2009 2:53 am

Re: allow_url_fopen Issue

Post by dt22 »

i tried it but nothing happening:

$string = http_request('GET', 'www.bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp', 80, array('username'=>$sms_details[1],"password"=>$sms_details[2],"sendername"=>$sms_details[3],"mobileno"=>$row['stud_parent_primary_mobile'],"message"=>$msg));
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: allow_url_fopen Issue

Post by maxx99 »

Try

Code: Select all

$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));
dt22
Forum Commoner
Posts: 32
Joined: Sat Oct 10, 2009 2:53 am

Re: allow_url_fopen Issue

Post by dt22 »

nothing happen...not even a error or warning..
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: allow_url_fopen Issue

Post by maxx99 »

how about the $string variable? is it empty?
Post Reply