Hi. To jailbreak a 3.1.3 iPhone safely you'll need to use Spirit: http://spiritjb.com/.
Please note that this won't unlock the phone to work with other networks as suggested above, it just allows you to install non-Apple approved applications (e.g. Cydia, MXTube, SBSettings and so on).
If you're on O2 and want to unlock you can just request it for free by filling in this form https://www.o2.co.uk/apps/help/help?qid=1&q1=2&route=unlocking&case=Handset%20Unlocking%20Form
Hope that helps! :thumbup: