YamdaBlam!

PHP

PHP – first day of the current month

by Jay on Aug.20, 2010, under PHP

A really quick post mainly for myself, because I will need to remember this at some stage in the future

$startDate=date(“Y-m-d”, strtotime(date(‘m’).’/01/’.date(‘Y’).’ 00:00:00′));

Enjoy!

Leave a Comment :, , more...

Getting GPS Data out of your images

by Jay on Jul.21, 2010, under PHP, jQuery

Privacy is important

Your privacy is a big deal. Be it in the physical world or in the virtual world. The unfortunate thing is that because browsing the web can be done in solitude, personal privacy tends to be an after thought. Not too mention that nearly everybody in the western world has access to an internet connected device.

When you take a photo on one of the latest digital cameras, or from a smart phone and if the device has GPS functionality, it can be assumed that the photo has been tagged with the location of where it was taken. This information is stored in a data format call EXIF. You can read all about it here and here.

It is not a huge leap of the imagination that if your photos are published on the internet ( which is public and not private ) that you are enabling others to track your movements without your expressed informed consent. This information can be used against you aswell as for you. The question should arise of how to manage your online profile. I will cover this topic in a later post.

GPS Data

Photo location is encoded using the Global Positioning System. This is a network of satellites orbiting the globe which return positions of devices which request it.  If you would like to know more about this see here.

Do your uploaded photos hold GPS data?

There are loads of web apps out there that will answer this question for you. In the spirit of DIY and because I like to program, I decided to put together my own image information parsing system. You can see it in action here. This basically reads the EXIF data from an image supplied via a URL to the image in question.

Next steps…

As you see from the lab, the system generates a link to the search page on http://maps.google.com/ When time permits, I will add a Google Mapping feature which will display the position from the image on a Google map. Watch this space.

Demo

This little web app is built using the ExifReader.php class from quiteless.com. You can get it here. It is an elegant PHP class which is now part of my library. Thank you Steve! (quiteless.com)

As always, feedback and comments are more than welcome!

Enjoy!

Leave a Comment :, , , , , , more...

Cannot use object of type stdClass as array

by Jay on Jul.19, 2010, under PHP, Technology

Problem

I was getting this particular error when decoding JSON data block from a web service.

It basically is trying to assert that the data block is a different type to the variable which it is being assigned to.

Meet solution

Explore the data dump by using something like

echo ‘<pre>’;  print_r($dataDump); echo ‘</pre>’;

and you will see the different data types for example:

stdClass Object ( [acc] => Array ….

Drill down through the structure to the data you want and check the data type of it. To prevent this error, simply apply some Type casting during the variable assignment. Bada-bing… problem, meet solution.

1 Comment :, , , , , , more...

URL Shortening on your site

by Jay on Jul.15, 2010, under API, PHP, Technology, jQuery

A nice feature to have on a site would be that of a URL shortener. I’ve looked at some of the more popular ones and decided to play with the API of the most popular, http://bit.ly.

I selected bit.ly as it is the most widely used, your account can be integrated with your Twitter client (Twitter for iPhone for example) and most impressively, you can get real time statistics on the shortened URL’s you create. This would be very useful for those companies who wish to track their marketing campaigns running on their website/twitter/Facebook accounts.

In the spirit of exploration, I’ve created a simple PHP bit.ly class, called bitlyApi.class.php.

To get up and running with this, I first created a new bit.ly account and copied out the API key they provide. Once you create an account, you will have access to the realtime statistics feature, otherwise you’ll just get the bog standard URL shortener service.

The bit.ly API is really straight forward. Have a look at the previous link to see what you can do.

Taking the most obvious function, URL shortening, the class simply takes in a valid URL, puts together the API request and sends it along with my username and API key and in return a JSON encoded string.

Download the sample code and have a look here at the live demo.

Note, that the code supplied is not production ready. I would need to have your usual input validation etc..

Feel free to comment!

Leave a Comment :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

 

Archives

All entries, chronologically...