allow_url_fopen Issue
Moderator: General Moderators
allow_url_fopen Issue
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.
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.
Re: allow_url_fopen Issue
Have you looked at cURL?
Re: allow_url_fopen Issue
You can also try Sockets http://php.net/manual/en/function.fsockopen.php
Re: allow_url_fopen Issue
i tried all that but these are not working with the server i don't know why...
Re: allow_url_fopen Issue
Do you get any notices or error messages?
Re: allow_url_fopen Issue
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
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
Re: allow_url_fopen Issue
Try to remove http:// from your our provide only hostname like: fsockopen('www.example.com')
Re: allow_url_fopen Issue
Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in
Re: allow_url_fopen Issue
Could you provide some code of yours? do you try to pass some data with GET?
Re: allow_url_fopen Issue
$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); }
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); }
Re: allow_url_fopen Issue
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
Example usages :
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;
}
?> Code: Select all
$string = http_request('GET', 'www.youtube.com', 80, array('param1'=>'value1',"param2"=>'value2'));Re: allow_url_fopen Issue
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));
$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));
Re: allow_url_fopen Issue
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));Re: allow_url_fopen Issue
nothing happen...not even a error or warning..
Re: allow_url_fopen Issue
how about the $string variable? is it empty?