Call to undefined function on setting referrer script - php

I am using this script to either set the referrer to the url or if the referrer is empty or cookie is set, hit the image.
The code below is what I have so far, the curl function part works if i put it in a file on it's own but am having trouble putting it with the cookie part.
The error is Call to undefined function geturl()
<?php
$image = 'image_url';
if($_COOKIE["6346"] == 1) {
$show = 0;
}
else {
$show = 1;
$hours = rand(24,68);
setcookie('6346', 1, time()+(60*60*$hours));
}
if (!empty($_SERVER['HTTP_REFERER'])) {
$goodreferer = 0;
}
else {
$goodreferer = 1;
}
if ($show == 1 && $goodreferer == 0) {
echo geturl('url(dot)com', 'referer(dot)com');
function geturl($url, $referer) {
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg,text/html,application/xhtml+xml';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$useragent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERAGENT, $useragent);
curl_setopt($process, CURLOPT_REFERER, $referer);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
$return = curl_exec($process);
curl_close($process);
return $return;
}
}
else {
header('Location: ' . $image);
exit;
}
?>

When a function is defined in a conditional manner its definition must be processed prior to being called. from the PHP Manual Conditional functions.
So try define the geturl() before its been called.
Try this SO post too Php - a function inside an if structure

You are calling the function before it's defined. Move the function to the top of the file. Also, you should not define the function in an if statement.

Don't define your function inside an if() control structure. That is a sure recipe for confusion. It's like multiple inheritance -- just because you CAN does not mean you SHOULD!
I think if you use good indenting of the control structures, you will find that your logic is easier to follow and the code is easier to debug. This version of the script works correctly.
http://www.laprbass.com/RAY_temp_user1923808.php
<?php // RAY_temp_user1923808.php
error_reporting(E_ALL);
$image = 'image_url';
if( isset($_COOKIE["6346"]) && ( $_COOKIE["6346"] == 1) )
{
$show = 0;
}
else
{
$show = 1;
$hours = rand(24,68);
setcookie('6346', 1, time()+(60*60*$hours));
}
if (!empty($_SERVER['HTTP_REFERER']))
{
$goodreferer = 0;
}
else
{
$goodreferer = 1;
}
if ($show == 1 && $goodreferer == 0)
{
echo geturl('url(dot)com', 'referer(dot)com');
}
else
{
header('Location: ' . $image);
exit;
}
function geturl($url, $referer) {
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg,text/html,application/xhtml+xml';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$useragent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERAGENT, $useragent);
curl_setopt($process, CURLOPT_REFERER, $referer);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
$return = curl_exec($process);
curl_close($process);
return $return;
}

Related

Parsing data from url - Localhost vs Server

I want to download entire page using this function, which I get from stackoverflow
public function get_remote_data($url, $post_paramtrs = false) {
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
if ($post_paramtrs) {
curl_setopt($c, CURLOPT_POST, TRUE);
curl_setopt($c, CURLOPT_POSTFIELDS, "var1=bla&" . $post_paramtrs);
} curl_setopt($c, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:33.0) Gecko/20100101 Firefox/33.0");
curl_setopt($c, CURLOPT_COOKIE, 'CookieName1=Value;');
curl_setopt($c, CURLOPT_MAXREDIRS, 10);
$follow_allowed = ( ini_get('open_basedir') || ini_get('safe_mode')) ? false : true;
if ($follow_allowed) {
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
}curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 9);
curl_setopt($c, CURLOPT_REFERER, $url);
curl_setopt($c, CURLOPT_TIMEOUT, 60);
curl_setopt($c, CURLOPT_AUTOREFERER, true);
curl_setopt($c, CURLOPT_ENCODING, 'gzip,deflate');
$data = curl_exec($c);
$status = curl_getinfo($c);
curl_close($c);
preg_match('/(http(|s)):\/\/(.*?)\/(.*\/|)/si', $status['url'], $link);
$data = preg_replace('/(src|href|action)=(\'|\")((?!(http|https|javascript:|\/\/|\/)).*?)(\'|\")/si', '$1=$2' . $link[0] . '$3$4$5', $data);
$data = preg_replace('/(src|href|action)=(\'|\")((?!(http|https|javascript:|\/\/)).*?)(\'|\")/si', '$1=$2' . $link[1] . '://' . $link[3] . '$3$4$5', $data);
if ($status['http_code'] == 200) {
return $data;
} elseif ($status['http_code'] == 301 || $status['http_code'] == 302) {
if (!$follow_allowed) {
if (empty($redirURL)) {
if (!empty($status['redirect_url'])) {
$redirURL = $status['redirect_url'];
}
} if (empty($redirURL)) {
preg_match('/(Location:|URI:)(.*?)(\r|\n)/si', $data, $m);
if (!empty($m[2])) {
$redirURL = $m[2];
}
} if (empty($redirURL)) {
preg_match('/href\=\"(.*?)\"(.*?)here\<\/a\>/si', $data, $m);
if (!empty($m[1])) {
$redirURL = $m[1];
}
} if (!empty($redirURL)) {
$t = debug_backtrace();
return call_user_func($t[0]["function"], trim($redirURL), $post_paramtrs);
}
}
} return "ERRORCODE22 with $url!!<br/>Last status codes<b/>:" . json_encode($status) . "<br/><br/>Last data got<br/>:$data";
}
Then I manipulate with this data, but it is not the point. I'm working on Localhost, and it works fine. But when I deloyed my app to server, I'm getting different results.
Basically, that function above returns different results depending where I use it - localhost or web server. For example, on localhost function returns html with 163 lines of code, however on web server only 74 lines.
P.S. app is very small, only 1 .php file and it is identical on localhost and web server.
What can be possible reason that script on localhost returning different data then from server?

How to login with curl and get link download in other website

I have a website i want get link download from it , but this website request me login , and i create login with curl , but it not work !
this is my code
config.php
$config['id'] = 'dinhvanvu94#gmail.com'; //
$config['password'] = 'nhocmiss#2'; //
curl.php
class cURL {
var $headers;
var $user_agent;
var $compression;
var $cookie_file;
var $proxy;
function __construct($cookies=TRUE,$cookie='cook.txt',$compression='gzip',$proxy='') {
$this->headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
$this->headers[] = 'Connection: Keep-Alive';
$this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$this->user_agent = 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36';
$this->compression=$compression;
$this->proxy=$proxy;
$this->cookies=$cookies;
if ($this->cookies == TRUE) $this->cookie($cookie);
}
function cookie($cookie_file) {
if (file_exists($cookie_file)) {
$this->cookie_file=$cookie_file;
} else {
fopen($cookie_file,'w') or $this->error('The cookie file could not be opened. Make sure this directory has the correct permissions');
$this->cookie_file=$cookie_file;
fclose($this->cookie_file);
}
}
function getheader($url) {
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
curl_setopt($process,CURLOPT_ENCODING , $this->compression);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($process,CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($process,CURLOPT_CAINFO, NULL);
curl_setopt($process,CURLOPT_CAPATH, NULL);
$return = curl_exec($process);
curl_close($process);
return $return;
}
download.php
include('start.php');
function _login()
{
global $html, $curl, $config;
preg_match('#<input type="hidden" value="(.*?)" name="fs_csrf" />#',$html,$fs_csrf);
$data = 'fs_csrf=' . $fs_csrf[1] . '&LoginForm%5Bemail%5D=' . urlencode($config['id']). '&LoginForm%5Bpassword%5D=' . urlencode($config['password']) . '&LoginForm%5BrememberMe%5D=0&LoginForm%5BrememberMe%5D=1&yt0=%C4%90%C4%83ng+nh%E1%BA%ADp';
$curl->post('https://www.fshare.vn/login',$data);
}
$html = $curl->get('https://www.fshare.vn/file/TM5MQ3VX2T');
if(!preg_match('#<a style="cursor: pointer;color: \#999999;" title="(.*?)"#', $html, $acc))
{
// chua dang nhap
_login();
}
$link = $curl->get('https://www.fshare.vn/download/index');
echo $link;
and start.php
include('config.php');
include('curl.php');
$curl = new cURL();
This í my code and it word to login thi web but it not get link
Your email and password are not stored in the config array, they are in a comment.
$config['id'] = 'THIS IS WHERE YOU WRITE YOUR EMAIL';
$config['password'] = 'THIS IS WHERE YOU WRITE YOUR PASSWORD';
You are trying to use $curl->get() and $curl->post() in your download.php file. These methods are not defined.Is the class code written by you?

php how add pause in script?

We are have a code:
<?php
function cURL_AutonavigatorRu($level = false, $model_id = false){
#http://www.autonavigator.ru
$ch = curl_init('http://www.autonavigator.ru/dispatcher.pl');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36");
$headers = array
(
'Accept: application/json',
'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4',
'Accept-Encoding: gzip,deflate',
'Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7'
);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_REFERER, "http://www.autonavigator.ru/my/offer_add/");
if($level == '1'){
curl_setopt($ch, CURLOPT_POSTFIELDS, 'class=list&method=make&show_all=1&vehicle=car&type=used');
}
elseif($level == '2' && $model_id){
curl_setopt($ch, CURLOPT_POSTFIELDS, 'class=list&method=model&show_all=1&vehicle=car&type=used&make_id='.$model_id);
}
elseif($level == '3' && $model_id){
curl_setopt($ch, CURLOPT_POSTFIELDS, 'class=list&method=modif&show_all=1&model_id='.$model_id);
}
else{
curl_setopt($ch, CURLOPT_POSTFIELDS, 'class=list&method=modif&show_all=1&model_id='.$model_id);
}
curl_setopt($ch, CURLOPT_ENCODING , "gzip");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
$json = json_decode(iconv("windows-1251","utf-8",$result), true);
return $json['list'];
}
$ArrAuto = cURL_AutonavigatorRu('1');
foreach($ArrAuto as $auto) {
echo $auto['value'].'<br>';
//sleep(2);
$AllModif1 = cURL_AutonavigatorRu('2',$auto["id"]);
var_dump($AllModif1);
echo '<br><br>----------------------------------<br><br>';
}
We are have problem - web site block curl and not give results for each $AllModif1 = cURL_AutonavigatorRu('2',$auto["id"]); in one time(in curl we get null).
Tell me please how make to pause the script that cycle foreach($ArrAuto as $auto) worked every 5 seconds?
P.S.: How make pause 4 secound between cycle?
P.P.S.: we are know about sleep() but i not get result with it see please prntscr.com/4ylm9y
Use sleep:
foreach($ArrAuto as $auto){
//Your amazing code here
sleep(4);
}
You should check the sleep() function
Add sleep(4); in your foreach loop.
just add sleep(5); in your foreach()
Add the following:
sleep(4);
More info here: http://php.net/manual/en/function.sleep.php

php curl not saving file to location

I have been searching for an answer for this all day, but with no luck!
I want to download/copy an image from the web to a location on my server, The code below doesn't seam to throw any errors other than the image is just not saving to the required or any directory.
As you can see I am using cURL to get the image and the variable $contents is returning true (1) so I am assuming the script works but I am actually missing something.
Many thanks in advance for your help. :-)
$dir = URL::base() . "/img/products/";
$imgSrc = "an image on the web";
$file = fopen($dir, "wb");
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
$ch = curl_init($imgSrc);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FILE, $file); // location to write to
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
$contents = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
fclose($lfile);
if ($curl_errno > 0)
{
Log::write("CURL", "cURL Error (".$curl_errno."): ".$curl_error);
}
else
{
Log::write("CURL", "Data received: " . $contents);
}
return;
Provide the file the writing access to PHP FILE using curl to store the contents. This can be done in three ways:
If you have the terminal access then use chmod to provide the writing access
If you have the CPanel access then use directory explorer then provide the writing access to the file by changing file properties.
You must have the access to FTP and change the file access attributes and provide the writing access.
Don't use curl.
If all you need to do is download an image, go for "file_get_contents" instead.
It's dead easy:
$fileContents = file_get_contents("https://www.google.com/images/srpr/logo4w.png");
File::put('where/to/store/the/image.jpg', $fileContents);
function saveImageToFile($image_url,$output_filename)
{
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$raw=curl_exec($ch);
curl_close ($ch);
if(file_exists($saveto))
{
unlink($saveto); //Saves over files
}
$fp = fopen($saveto,'x');
fwrite($fp, $raw);
fclose($fp);
}
Your problem is quite simple, and I have no idea how everyone else ignored it. It is Laravel-specific. Your $dir variable returns an HTTP resource identifier. What you need is a filesystem identifier.
For laravel, change your URL::to() to path("public") to tell Laravel to stop using HTTP URIs and instead take the local path to the public folder (/your/laravel/setup/path/public/).
code
$dir = path("public") . "img/products/";
$imgSrc = "an image on the web";
$file = fopen($dir . substr($imgSrc,strrpos("/",$imgSrc)+1), "wb");
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
$ch = curl_init($imgSrc);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FILE, $file); // location to write to
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
$contents = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
if ($curl_errno > 0)
{
Log::write("CURL", "cURL Error (".$curl_errno."): ".$curl_error);
}
else
{
Log::write("CURL", "Data received: " . $contents);
fwrite($file,$contents);
fclose($file);
}
return;
OK, finally got it all working and here is the code if anyone else ever tries to do the same sort of thing!
I was missing these parts:
$dir = $_SERVER['DOCUMENT_ROOT'] . "/img/products/";
and
fwrite($file,$contents);
So here is my final code... credit to Sébastien for pointing me in the right direction. Thanks.
if($method == 'save')
{
$productId = Input::get('pId');
$removeProductImages = DB::table('product_ref_images')->where('product_id', '=', $productId)->delete();
$imagesData = Input::get('imageRefs');
$dir = $_SERVER['DOCUMENT_ROOT'] . "/img/products/";
$sortOrder = 0;
for ($i=0; $i < count($imagesData); $i++) {
$imgSrc = trim($imagesData[$i]['imgSrc']);
$imgId = trim($imagesData[$i]['imgId']);
$file = fopen($dir . basename($imgSrc), "wb");
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
$ch = curl_init($imgSrc);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FILE, $file);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
$contents = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
if ($curl_errno > 0)
{
Log::write("CURL", "cURL Error (".$curl_errno."): ".$curl_error);
break;
}
else
{
fwrite($file,$contents);
fclose($file);
$imageIds = DB::table('product_ref_images')->order_by('image_id', 'desc')->first();
if($imageIds == null)
{
$imageIds = 0;
}
else
{
$imageIds = $imageIds->image_id;
}
$updateImages = DB::table('product_ref_images')
->insert(array(
'image_id' => $imageIds + 1,
'product_id' => $productId,
'flickr_image_id' => $imgId,
'sort_order' => $sortOrder++,
'local_storage_url' => $dir . basename($imgSrc),
'created_at' => date("Y-m-d H:i:s"),
'updated_at' => date("Y-m-d H:i:s")
));
}
}
return Response::json('Complete');
}
Remove this line:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
You're storing the response to a file, not to the return variable. Otherwise, you have to save it yourself (like you did in the other solution).

PHP Display Image (SSL PROXY)

I am trying to make a PHP script that accepts a URL and displays it (trying to keep SSL on my project)
However, I am unable to get anything to output with my script. No errors are being displayed and I am at a loss of words. What am I not seeing?
<?php
//if parameter is empty
if((!isset($_GET['img'])) or ($_GET['img'] == '') or (!isset($per['scheme'])))
{
exit;
}
$per = parse_url($_GET['img']);
print_r ($per);
$imgurl = $_GET['img'];
print_r ($imgurl);
$imgurl = str_replace(' ', "%20", $imgurl);
$aFile = getimagesize($imgurl);
print_r ($aFile);
//check file extension
if($aFile == 'jpg' or $aFile == 'jpeg'){
header('Content-Type: image/jpeg');
imagejpeg(getimg($file));
} elseif($aFile == 'png') {
header('Content-Type: image/png');
imagepng(getimg($file));
} elseif($aFile == 'gif') {
header('Content-Type: image/gif');
imagegif(getimg($file));
} else {
die('not supported');
}
$imgurl = $_GET['img'];
$imgurl = str_replace(' ', "%20", $imgurl);
function getimg($imageurl) {
$cache_expire = 60*60*24*365;
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg, image/png';
$headers[] = 'Cache-Control: maxage=. $cache_expire';
$headers[] = 'Pragma: public';
$headers[] = 'Accept-Encoding: None';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6';
$process = curl_init($imageurl);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
curl_setopt($process, CURLOPT_REFERER, $_GET['img']);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_HTTPGET, true);
curl_setopt($process, CURLOPT_USERAGENT, $user_agent);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($process);
curl_close($process);
return $return;
}
exit;
?>
Here is an edited version of the script that outputs garbled text when I use readfile:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
//if parameter is empty
if((!isset($_GET['img'])) or ($_GET['img'] == ''))
{
exit;
}
$per = parse_url($_GET['img']);
$imgurl = $_GET['img'];
$imgurl = str_replace(' ', "%20", $imgurl);
$aFile = getimagesize($imgurl);
//check file extension
$checkmime = getimagesize($imgurl);
if($checkmime['mime'] != 'image/png' && $checkmime['mime'] != 'image/gif' && $checkmime['mime'] != 'image/jpeg') {
die('not supported');
} else {
readfile("$imgurl");
}
function getimg($imageurl) {
$cache_expire = 60*60*24*365;
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg, image/png';
$headers[] = 'Cache-Control: maxage=. $cache_expire';
$headers[] = 'Pragma: public';
$headers[] = 'Accept-Encoding: None';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6';
$process = curl_init($imageurl);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
curl_setopt($process, CURLOPT_REFERER, $_GET['img']);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_HTTPGET, true);
curl_setopt($process, CURLOPT_USERAGENT, $user_agent);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($process);
curl_close($process);
return $return;
}
exit;
?>
If this truly is your entire script your problem first lies with $per['scheme'] not being set so it will trip the first if() statement and have the script exit.
You check if it's not set here: !isset($per['scheme']) so it will make the expression TRUE and thus end the script, reason no output even from print_r();
Use this instead:
if (empty($_GET['img'])) // Check if $_GET['img'] is not set AND is = '' (empty)
{
exit;
}
Use:
} else {
header('Content-Type: ' . $checkmime['mime']);
readfile($imgurl);
}

Categories