Top Bottom
Dan.com

PHP Function to Submit Site to Del.icio.us

Dynadot
Impact
2,577
Please Note:
1. $site must start with http://
2. $tags must be separated with spaces, not commas
3. $proxy_addy must start with http://
4. $use_proxy must be passed in as TRUE if you want to use a proxy
5. Make sure you have CURL installed.

I wrote this and I am giving you guys permission to use it however you want commercial or otherwise, just don't sell the code itself. Have fun!

Demo using this function can be found at BMBot.com.

rep appreciated :)

PHP:
<?php

function delicious_submit($user, $pass, $site, $note, $desc, $tags, $proxy_addy, $proxy_port, $use_proxy = FALSE)
{
	// Set curl options.
	$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
	curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
	curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	if($use_proxy){
		curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
		curl_setopt($ch, CURLOPT_PROXY, $proxy_addy);
		curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
	}

	// Visit login page.
	$url = 'https://secure.del.icio.us/login';
	$params = '';
	curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
	curl_setopt($ch, CURLOPT_URL, $url);
	$result = curl_exec($ch);
	
	//Grab unique token.
	$piece = strstr($result, "inkey\"");
	$piece = strstr($piece, "value=\"");
	$token = substr($piece, 7, 32);

	// Log in with token, user and pass.	
	$url = 'https://secure.del.icio.us/login';
	$params = 'inkey=' . $token . '&user_name=' . $user . '&password=' . $pass . '&login=log%20in';	
	curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
	curl_setopt($ch, CURLOPT_URL, $url);	
	$result = curl_exec($ch);	

	// Submit the url.
	$url = 'http://del.icio.us/' . $user . '?url=' . $site . '&submit=save&jump=no';
	curl_setopt($ch, CURLOPT_HTTPGET, 1);
	curl_setopt($ch, CURLOPT_URL, $url);
	$result = curl_exec($ch);

	// Grab the new token.
	$piece = strstr($result, "key\"");
	$piece = strstr($piece, "value=\"");
	$token = substr($piece, 7, 32);

	// Grab the unique key code.
	$piece = strstr($result, $user . "?");
	$piece = substr($piece, strlen($user));
	$piece = strstr($piece, $user . "?");
	$quote = strpos($piece, "\"");
	$len = strlen($user);
	$code = substr($piece, $len + 1, $quote - $len - 1);

	// Submit the url, description, notes, and tags along with the new token and key code.
	$url = 'http://del.icio.us/' . $user . '?' . $code;
	$params = 'url=' . $site . '&oldurl=' . $site . '&description=' . $desc . '&notes=' . $note . '&tags=' . $tags . '&jump=no&key=' . $token;
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
	curl_setopt($ch, CURL_OPT_URL, $url);
	$result = curl_exec($ch);

	curl_close($ch);
}

?>
 
Last edited:
Impact
2,577
If by asking how to install it you're asking me to give you the rest of the code to have a working site, sorry... I'm not that generous :)

This is the hard part. If you need help making an html form and using a while loop you're best bet is www.Codewalkers.com or reading the manual.
 
Name Worth