Curl Cookies – Quick Tip

I know I haven’t got around to writing script that uses cookies to login. However if you’re on that path and are interested in using cookies to do things like login and stay logged into a site there’s one troubling thing I had big issues with when I started.

To use a cookie we need to set it’s location and this is where I’ve had troubles. For some reason I’ve had problems using a cookie not set with the full path. So when you set your cookie location make sure you use the full path of your cookie location.

$cookie = “/home/user/tmp/cookie.txt”;
If you’re going to use multiple threads or want to code up a captcha solve you have to save the session so you probably want to do a
$cookie = “/home/user/tmp/cookie-“.rand(111,9999).”.txt”;

And that’s the quick tip. I beat my head against the wall with this one a bunch of times and the full path seemed to be the thing that solved the curl cookie issues I had. If you’re having problems with cookies give this a try.

Just quickly to use cookies you just use a couple of simple lines.

So the initial call you need to set a cookie like this

curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); // sets the cookie file location
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); // this says to start a new cookie file.

And that’s it to set the cookie on login or whatever you might need to start a cookie for. Then all your calls after that would look like this.

curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); // sets the cookie file location
curl_setopt($ch, CURLOPT_COOKIE, $cookie); // use the cookie we have on file

And there you have it cookies are just that easy. I’ll get some example code up in the next day or so to show them in the wild.

Google enters Online Processing, Storage and Serving Space

If you haven’t heard already Amazon has been doing this for a bit. Basically rather then buying a new server you can use a nice web based service to do things for you. Add all your stuff to their servers to run and it will act as a virtual server for you. Google is offering decent amount of bandwidth, storage and processing under their free plan. Read more about it here:

Google AppEngine

This is only in beta right now and only open to the first 10k people that signed up at 9pm PST. I tried at 10:30pm and it made it sound like I missed the boat and was added to a waiting list. But mind as well get on that list now if you’re interested.

PHP Platform I Write Code In

As I’m sure you know PHP as with most languages you can code right in a text editor on your home computer. However this might not be the most effective use of your time. I get asked a lot, what I use to code in. Well after trying quite a few things the ZEND IDE is about the best thing I’ve found out there. Now I know there’s some of you that are going to whine that it’s a little overhead intensive and yes you’re right. Zend is by no means notepad. However it brings a lot of tools to the table that make it well worth that over head in my opinion.

  1. Built in sFTP, FTP drive mapping
  2. Stepped debugging
  3. Robust code completion library
  4. Version control and management

Now if you’re going to use Zend I invite you to go to tools/preferences first thing and uncheck “Use OS look and feel”. What this does is it makes Zend try and emulate what the rest of your computer looks like. For example if you’re running XP like me it gives it the XP look and feel. Honestly I hear a lot that Zend is super slow and people just can’t put up with it. Well this is what makes it slow, turn this off and the performance will improve 10 fold.

1. sFTP/FTP Drive Mapping
What got me started on writing this post is I was at nickycakes blog today and he was talking about drive mapping. I’m sure if you’re just starting or when you started with all this PHP and servers stuff one of the biggest pain in the butt’s was figuring out how this all worked. When I first started I used to run a copy of WAMP on my local machine and code everything locally. Then when I finished it and got it working I migrated it to the server. If you’ve ever done this you know the headache this can be. Windows has a totally different file structure. Permissions can be a pain in the ass and so on. Also once you have it on the server it’s going to require some debugging ( funny how software writing works that way ). So when I first started I’d download the file, edit it, upload it and test. As you can see doing this 100 times can be an arduous task.

Zend to the rescue. With zend you have a file manager in your left pane by default. In this pane all you have to do is left click then hit “add FTP server”. A window will pop up that will ask you the details of you FTP or sFTP connection. Then once you hit ok it’ll connect to the server and map a drive into Zend just like another hard drive on your local box. You can open, edit, close files all in real time which totally eliminates the upload/download task. This also allows you to build in real time on the server where the scripts are going to reside in the end. One thing to take note of. If you’re used to coding locally and uploading you always have a sort of backup of a working version online. Now that you’re controlling things in real-time you can easily write over something that works with something that doesn’t. Remember when you hit save the old file is gone.

2. Stepped Debugging
When I first shifted to PHP I came from a small background in Visual Basic and developing in Visual Studio. Well visual studio has very very robust debugging tools. For example if ( this is for php only coders ) you could hit run and it would go through your script step by step. Then as it’s going through you could mouse over each variable, object, array or whatever to see what was contained in it on that line. You can then make some tweaks and run that same line again and see if it fixed it. Something like this might be useful right? Well Zend has debugging built into it. And you can set it up so that it works direct on your server.

3. Robust Code Completion Library
This was HUGE when I was new and didn’t know many of the functions at all. Code completion allows you to start writing a function and it will bring up a list of functions to finish it. For example let say you’re looking for a string function to do something. Well you know that most of the string functions start with a “str” so you start typing that and it pops up the whole list of functions that start with “str” then you page down the list and find the one you’re looking for. When you type the complete function it shows you 1. a description of what the function does, 2. what the function takes as inputs and 3. what the functions generates as an output. This can be extremely helpful and save you a lot of time from going to Zend also has a powerful real-time syntactic code check. Just like when you’re working on a word document and it underlines grammar mistakes in real-time so does Zend with your syntax. It’s very useful to see if you missed a bracket here or there which you might spend a good amount of time debugging.

4. Version control management
If you’re working with a team on a single project and sharing files this can be really useful. Also is very helpful if you want to make backups along the way in an easy fashion. Zend supports both CVS and SVN. I’m not going to get into a lot chat about versioning. But just know it supports all the features of versioning natively.

5. I’m sure there’s other things I’m not thinking of right now.
If you’re reading this and use the Zend IDE feel free to add them in the comments.

That’s just a few reason to give Zend a shot. I can guarantee you with the tools it provides it will help you learn faster and speed your coding up. Don’t be lame and try it for a day or two. Really give it a shot as it’s a complex program that takes some getting used to. But will save you time and improve your coding once you d.