| | |
Need help making simple random images
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
•
•
gee, sorry for being such a newb, but what is CURL?
thanks so much for going over the regex. hopefully i will be able to use it soon. i'm terribly excited about the possibilities of this code for making mosaics on my pages...
CURL PHP Manual: http://php.net/curl
Heres a good simple class for CURL I found on the php CURL manual page:
[PHP]<?php
/*
Sean Huber CURL library
This library is a basic implementation of CURL capabilities.
It works in most modern versions of IE and FF.
==================================== USAGE ====================================
It exports the CURL object globally, so set a callback with setCallback($func).
(Use setCallback(array('class_name', 'func_name')) to set a callback as a func
that lies within a different class)
Then use one of the CURL request methods:
get($url);
post($url, $vars); vars is a urlencoded string in query string format.
Your callback function will then be called with 1 argument, the response text.
If a callback is not defined, your request will return the response text.
*/
class CURL {
var $callback = false;
var $cookiejar = 'cookie.txt';
var $cookiefile = 'cookie.txt'
function setCookieJar($file_path) {
var $cookiejar = $file_path;
}
function setCookieFile($file_path) {
var $cookiefile = $file_path;
}
function setCallback($func_name) {
$this->callback = $func_name;
}
function doRequest($method, $url, $vars) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiejar);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiefile);
if ($method == 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
}
$data = curl_exec($ch);
curl_close($ch);
if ($data) {
if ($this->callback)
{
$callback = $this->callback;
$this->callback = false;
return call_user_func($callback, $data);
} else {
return $data;
}
} else {
return curl_error($ch);
}
}
function get($url) {
return $this->doRequest('GET', $url, 'NULL');
}
function post($url, $vars) {
return $this->doRequest('POST', $url, $vars);
}
}
?>
[/PHP]
ref: http://php.net/curl
I've added the two functions:
[PHP]function setCookieJar($file_path) {
var $cookiejar = $file_path;
}
function setCookieFile($file_path) {
var $cookiefile = $file_path;
}[/PHP]
This will allow you to set paths for your cookies to be saved in. Usually you would want to use a file below your webroot, that cannot be read.
IF just for the flickr images, you don't need those two functions... but say if you wanted to use it for the flickr API, which would need authentication for some requests, it would be best to protect the cookies from being read by anyone.
For flickr you'd use it something like:
[PHP]// you need curl since you cant use the php stream functions
$CURL = new CURL();
$php = $CURL->get("http://api.flickr.com/services/feeds/photos_public.gne?tags=$tags&format=php");
// since you cant use include() you'll need to strip the php tags
$php = str_replace(array('<?php', '?>'), '', $php);
// then you need to evaluate the php within, as would be done with an include()
eval($php);[/PHP]
I havent tested that but, it should work. Hope that gives you a start on getting the mosaics done..
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Other Threads in the PHP Forum
- Previous Thread: apache2-devel file?
- Next Thread: Making a phpbb installer like fantastico
Views: 4330 | Replies: 11
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cookies cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery js limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql stored structure subdomain syntax system table tutorial update updates upload url validation validator variable video web xml youtube






