Keeping cookies without using curl's cookie jar files... Lycos Mail, IndiaTimes, Rediffmail address book import scripts
Free code...
You can support development of more free scripts by purchasing the full package of my php address book importing scripts. There are more than 100 websites (some of them are big names) worldwide that have already integrated my scripts with their cms and online community websites. While my scripts might not be the cheapest right now I do my best to provide top notch quality, and unlike many other websites that resell scripts made by others, I have actually developed every single line of code that I offer myself and I am able to provide quick updates whenever necessary.
This is actually only part of the code that I use for my import scripts. It is a very essential part of the code because it allows for keeping all cookies in a string/array instead of storing them in curl's cookie jar files (also it automatically updates your $ch object with the new cookies so you don't even need to worry about that).
I am releasing this part of the code due to some people trying to claim this as their own code (even as part of "their" import scripts!). There are much bigger chunks of my code sitting out there with someone else's name on it and I really do not appreciate that. The code below (or anything that's very close to it) has been originally used in my scripts and is developed by me.
I developed most of it back in January 2006 and I haven't made any major changes ever since because it has been working perfectly for all this time:
function read_header($ch, $string)
{
global $location;
global $cookiearr;
global $ch;
# ^overrides the function param $ch
# this is okay because we need to
# update the global $ch with
# new cookies
$length = strlen($string);
if(!strncmp($string, "Location:", 9))
{
$location = trim(substr($string, 9, -1));
}
if(!strncmp($string, "Set-Cookie:", 11))
{
$cookiestr = trim(substr($string, 11, -1));
$cookie = explode(';', $cookiestr);
$cookie = explode('=', $cookie[0]);
$cookiename = trim(array_shift($cookie));
$cookiearr[$cookiename] = trim(implode('=', $cookie));
}
$cookie = "";
if(trim($string) == "")
{
foreach ($cookiearr as $key=>$value)
{
$cookie .= "$key=$value; ";
}
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}
return $length;
}
Using the header function with curl:
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header');If you use any of this code it is okay to give me some credit. I will appreciate that very much.
And, no, it is NOT okay to release any of my address book import scripts under your name (no matter if you paid for them or you downloaded them from somewhere for free). My scripts are *not* copyright free.
More free code will be available soon. I'm currently working on RediffMail, IndiaTimes (Rediff Mail and India Times address book scripts are now available upon request, soon you'll be able to download them here as well) and Lycos mail address book/contacts importer scripts and I will release them for free (Lycosmail address book script is almost ready). If you know of any popular online mailing service in your country please let me know and I can work on that too. I'm currently concentrating on more scripts that will be not commercial. For example you can now download my gmail address book script.
Some of the code here is provided for free, however I do ask you to link to me on the section of your site where you use the scripts.
Suggested link format:
or anything more relevant.