Tag Archives: Tutorial

PHP Tutorial: PayPal Instant Payment Notification (IPN)

Got a letterIn a previous post I tried to give an introduction on how to get started with PayPal Payment Data Transfers (PDT). PDT is very handy in several cases, but you can’t always rely on it since it requires the user to return to your page after doing the payment. That will often happen, but it’s not guaranteed to happen. If you for example want to mark an order in your system as paid or something like that, you most likely want to use PayPal Instant Payment Notifications (IPN) in addition to PDT.

Instant Payment Notification (IPN) is a message service that notifies you of events related to PayPal transactions. You can use it to automate back-office and administrative functions, such as fulfilling orders, tracking customers, and providing status and other information related to a transaction. — PayPal

Once again the documentation, tutorials and code samples I found on this was a bit all over the place. Sort of messy and outdated. So, once again I decided to do my own thing and just follow the steps required and implement them myself. And since the tutorial on PDT turned out to be a bit of a success, I decided to share this too. Hopefully it can make the lives of fellow developers easier :)

Continue reading

PHP: How to get all images from an HTML page

rgbstock.com
I was curious to how I could make something similar to what Facebook does when you add a link. Somehow it loads images found on the page your link leads to, and then it presents them to you so you can select one you want to use as a thumbnail.

Well, step one to solve this is of course to find all the images on a page, and that is what I will present in this post. It will be sort of like a backend service we can use later from an AJAX call. You post it a URL, and you get all the image URLs it found back. Let’s put the petal to medal!

Continue reading

PHP: How to proportionally resize an uploaded image

Big mug and tiny mug
rgbstock.com
Say you have a form where someone can upload a profile image. The uploaded image can be of any size of course, but you want all the profile images to fit inside a certain frame. You could just set the dimensions on the image tag to this size, but in most browsers that would look ugly, and it would also most likely stretch the image. It would look awful. In addition you would be serving a image which most likely was a lot larger than you wanted it to be. This would cost you bandwidth.

In this case you might want to proportionally resize the image to the appropriate size when you get it uploaded. You can then store the resized image instead and serve it directly with no problems afterwards. It doesn’t have to be difficult! Here’s how :)

Continue reading

Unix: How to redirect stderr to stdout

Today I ran a Java application in a Unix console. It printed out some messages before it crashed with an exception and a loong stack trace. Too long to see the top of. So, I figured I’d just pipeline it into the lovely less like this:

$ java -jar foobar.jar | less

The result was not what I expected however. All I got to see was the messages that had been printed out. No exception or stack trace to be seen.

Continue reading

Automatic login in Windows 7 for lazy single users

I’m the only one who use my computer and it’s in my room and I don’t really care about locking it or anything like that. I just find it annoying that I have to type a password everytime I boot it up or it comes back from sleep or screen saver mode.

I usually do this whenever I reinstall Windows. At least on my desktop computer. My laptops usually have password protection enabled. Anyways, I don’t reinstall that often so I always forget how to do it. Even though it’s very simple… Decided to share the procedure here, so I know where to find it :)

Continue reading

How to backup a folder with Robocopy

HarddriveAs a simple way to keep my computer backed up I copy all that I care about onto external hard drives twice a day. I mostly do this in case my internal hard drives would die or something like that, so I haven’t cared too much about finding anything more fancy with incremental history and such. What I have is a simple batch file that I have set to run periodically using the Task Scheduler in Windows.

Note: If you want an easier solution which supports incremental backups to external drives, other computers and the cloud, you should check out CrashPlan. I personally pay for a CrashPlan+ Family Unlimited license and use it to back up all my computers. Very handy and has already prevented me from losing all my stuff once :)

Continue reading

PHP Tutorial: PayPal Payment Data Transfers (PDT)

MoneySay you have a PayPal “Buy Now”-button on your website and you have assigned return URLs like http://example.com/order?done and http://example.com/order?canceled. You can then welcome the user back after a successful payment. But what if you wanted to say something more interesting than just “hey, welcome back” when they click on that “Return to Merchant”-button? And can you know if the order was actually done or canceled? Maybe you’d like to log the transaction in your database and mark a payment as complete or something like that too? In that case you sure can’t trust a simple flag in the address bar…

Payment Data Transfer (PDT) is a secure method to retrieve the details about a PayPal transaction so that you can display them to your customer. It is used in combination with Website Payments Standard, so that after a customer returns to your website after paying on the PayPal site, they can instantly view a confirmation message with the details of the transaction. — PayPal

I’ve tried to figure out how to use PDT and found that most samples and classes to build from are usually quite ugly, old or outdated. I didn’t find them too useful anyways… So, therefore, I’ve tried to do my own thing based on the documentation found on the PayPal Developer websites. (Seriously, how many versions of documents and developer websites do they have anyways? It’s like a complete jungle…)

Since the documentation was a bit of a mess, I thought I make a small tutorial on the steps needed to get started. That way I can learn it better myself and hopefully help some other poor souls that need to figure this stuff out as well. Please provide feedback if you have any! Would love to make this page nicer and clearer if possible :)

Continue reading