Curl and Cookies

I noticed the other day that the cheat sheet I have on this site for curl doesn’t show how to use cookies, so I thought I’d remedy that omission, and quickly! Being able to use the command line to authenticate and then go on and use part of a site behind a login box can be really handy, and it is also super-simple.

-c to Save a Cookie

Pass the -c switch followed by a filename and curl will write the cookies to a file. This is the “cookie jar” and you can dip into it whenever you want to send the cookies back with a future request. For example:
curl -c cookies.txt http://www.lornajane.net
This writes a file named cookies.txt to the local directory. When I look in it, it contains:

# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.

www.lornajane.net FALSE / FALSE 0 s9y_4e071c5ccc553288993faf0369cb076c 539e01676501366ea0f04e2646b1a31d

-b to Send Cookies

All I do when I want to use the cookie on future requests is pass exactly the same command but with a -b switch; this will read the named file and send the cookies along. You can edit the cookies as you wish, at your own risk of course, and this makes the use of cookies and curl an absolutely invaluable technique for testing! It’s also common to use it on sites where you want to download a file directly to the server but the site requires login first.

Business Strategies: Office Day

I’m now self-employed, which means that I have to do my own administration, invoicing, accounts, correspondence, sales, marketing and maintenance (not to mention running the household, a sports team, and whatever else I’ve volunteered to get involved with lately). I am pretty organised as a person, which is a real gift now I have all this going on! I have some coping strategies and I thought I’d share one that has helped hugely – the office day.

The idea of the office day is that I block out a whole day every month or so where I’m not going anywhere, not on site with clients, not speaking, not delivering anything, just in the office, doing whatever needs doing. I tend to put these days in either day before or after runs of days away – either with clients or at events, just to give me time to catch my breath. Working this way means that when I’m working on something, I can just work on it, and know that there is time set aside for all the little things. Also the days where I’m just back from somewhere and the inbox is so full, it is ready to bite, then it gives time to get things straightened out and right, without feeling stressed because there is other work to do. Although it does mean that I’m not doing billable work that day, I find that splitting the work up like this works really well for me, and I thought I’d share – perhaps this suggestion will help someone else, and I’m always interested to hear how others fit in all the business bits and pieces around their “real” work.

Fetching Namespaced XML Elements With SimpleXML

Recently I was working with some google APIs and needed to retrieve some namespaced elements from the result set. This confused me more than I expected it to so here’s my code for the next time I need it (and if you use it too, then great!)

I was reading from their analytics data feed API, this returns a few key fields and then multiple <entry> tags, each with namespaced children. The entry tags look something like: Continue reading

Be My Guest for DayCamp4Developers

This weekend I’m presenting at DayCamp4Developers, a virtual event comprising a full day of workshops for developers of all disciplines to improve their soft skills and move forward in their career. I get to attend since I’m speaking, but even after I’ve given my slot I know I’ll be online to watch the other talks and I know I’ll learn something myself! I believe that, however good your technical skills are, being able to communicate effectively means the different between being the bearded expert in the corner who knows everything but has been in the same job 10 years, and being the high flier that soft skills and technical skills combined could make you.

I have one guest ticket for this event, and I want to make sure that it goes to someone who will make good use of it. So, if you would like to be my guest for DayCamp4Developers, this weekend 6th November, then leave me a comment and tell me why you want to attend. In a couple of days (probably Wednesday evening, UK time) I’ll close the comments and pick a winner – put your email address in the comments box (it isn’t displayed) so I can reach you and let you know.

If you don’t win, and want to join us anyway, then you can still buy tickets. Check with your local user group if they have an affiliate code and if not – use this link to buy your tickets, using my affiliate code ;)

Looking forward to “seeing” everyone on Saturday!

Posted in php

Deprecated Methods in Pecl_Http

I’m a big fan of pecl_http, which I use quite often as I work so regularly with APIs and on systems where I can get it installed, it’s much nicer than PHP’s curl extension. Recently though I’ve been often seeing output which reads:

Function HttpRequest::addRawPostData() is deprecated

It isn’t obvious from the PHP manual page what I ought to do instead, however further inspection shows that it is recommended to use setBody() instead. This can be used in exactly the same way, and my code seems to work perfectly well with this substitution. If you have any more information about this change, leave me a comment – I’d be interested to hear it.

Advice To Another Blogger

Recently I was approached by a friend of mine looking to start his own technical blog. I’ve been blogging here for some years, and he wrote to ask my advice. I replied to him, but thought that the ideas could be useful to others in the same position, so here’s that email, published here for anyone else who wants to see it:
Continue reading

Three Months In: The (Ad)Venture Continues

It’s three months since I gave up the day job and so many people have asked me how it’s going, that I thought I’d give a quick round up!

I am a statistics nut so it will surprise nobody that I track my time religiously (using harvest, which I’ll post about some day soon). From this I can tell you that I spend about 40% of my time working for other people, and the rest doing things like writing, preparing talks, accounts, meetings, or whatever. I’ve also taken 14 days off, which has been absolutely fabulous after a decidedly work-heavy first half of 2010. The biggest change is that I’ve only worked one weekend day. One.

Continue reading

Is Enum Evil?

When I work on database designs, either on my own projects or as advisor to others, I often find people very reluctant to use an enum type for any columns. Now, I’m not about to advocate the gratuitous use of an enum column, they definitely have some pitfalls, but I think it is important to understand these rather than just shouting “enum evil!” if anyone should mention them.

There are cases where an enum is the correct choice for a particular type of data, so let’s look at what an enum type actually is and does.

Continue reading

My Talk Filing System

Three years ago, I had never spoken in public (I have video of that first attempt and all I can say is that I’ve come a long, long way!). Since then, I’ve done rather a lot of it. I’ve submitted countless conference talks, had the minority of those accepted, and prepared and delivered those that were. Not many talks have been given twice, but some have, and now some are getting rebranded since I am working for myself and can choose my own slide branding these days. All this adds up to a lot of content to keep track of!

Continue reading

Best Practices in API Design: Audio and Slides

Earlier in the year I gave a talk at PHP UK in London entitled “Best Practice for API Design”. I really enjoyed giving this talk, since I work so much with APIs and enjoy sharing my ideas. The audio is now online so if you missed the talk, feel free to have a listen. You can also see the slides (on slideshare) and also read the series of blog posts I wrote on this topic which originally inspired the talk.