Posts in the “php” category

A PayPal PHP IPN example

If you're looking for a PayPal IPN example written in PHP, I believe the following code works okay. It's based on the PayPal PHP IPN example (from the PayPal developer site), but I fixed some bugs from their example, added an alternate PHP socket example so you don't have to use SSL to connect to PayPal, and added more variables to the script.

A PHP script to send email with an attachment

PHP email FAQ: How do I send email from a PHP script? (Including sending email with an attachment.)

Continuing with my initiation into the PHP programming world, I just finished developing a PHP script to send a mail message with an arbitrary attachment. (I write 'arbitrary' there because a lot of the example PHP mail scripts I've seen focus on attaching an image, and I'm not really familiar with MIME types yet, and "image/jpg" wasn't working for my needs.)

How to use a here document in PHP

PHP here document FAQ: How do I create a here document in PHP?

If you ever need to use a "here document" in PHP, here's a short example of the PHP here document syntax:

<?php

print <<< END
Four score and seven years ago
our fathers set onto this continent
(and so on ...)
END;

?>

I believe the closing tag you use ("END" in my case) must begin in the first column. This is typical with here document syntax, but I haven't tested it in PHP.

OpenSSO and PHP - A simple PHP script to retrieve OpenSSO identity information

Here's a simple PHP program I wrote to test how PHP works with OpenSSO, specifically how it works with OpenSSO identity information.

I saved this file with the name info.php, then put it in a directory on my Apache web server that is protected by an OpenSSO login policy. To access this page, I enter the URL for the page in my browser and try to access it, with the URL being something like this:

PHP here document (heredoc) examples

PHP here doc FAQ: Can you share some examples of the PHP "here" doc (heredoc) syntax?

"Here" documents in many languages are provided as a way to address the following problems:

PHP redirect - How to send a redirect with PHP

PHP redirection FAQ: How can I redirect a user in a PHP script?

I've been working with OpenSSO a lot lately (Sun's open source identity management product), and one thing you see right away is that they redirect the user's browser a lot during the login process. During a typical login process a user will attempt to access a protected page; an OpenSSO agent will redirect the user's browser to the OpenSSO login page; and after a successful login they redirect you back to the protected resource.

The PHP "headers already sent" error message

Still in my early days working with PHP, I've learned that it's really easy to generate the dreaded "headers already sent" error message. If for some reason you actually want to generate this error message intentionally, I've learned that all you have to do is try to send HTML body content (any non-header content) before calling the header() or setcookie() methods, and you'll get that PHP error message right away.

CakePHP find distinct - SELECT DISTINCT syntax for the CakePHP find method

As a CakePHP newbie, I'm spending a lot of time learning how to formulate SQL queries with the CakePHP find function syntax. This morning I need to create a "select distinct" SQL query in CakePHP. Fortunately this wasn't too hard once I figured out how to piece it all together.

In my case, I have a database table named logfile_records, and I wanted to run a SQL "select distinct" query against that table. If I was going to write the query in plain SQL I'd write it like this:

CakePHP, PHP, and LAMP developer jobs

Having learned a lot about PHP and CakePHP lately, I was wondering what the job market looks like for CakePHP developers these days, so I've been poking around various websites lately to see what's going on.

Careerbuilder.com shows a few jobs for CakePHP developers, with salaries in the wide range of $50K to $100K per year. Digging into the descriptions, some of those jobs are actually for Rails developers, PHP developers, and LAMP developers.

PHP job interview questions

Summary: A collection of PHP job interview questions (and other standard computer programming interview questions).

Over the years, I've found the best way to find out how a potential programmer works is to sit with him at a computer keyboard and write some code, typically something requiring some database interaction, and potentially interaction with another developer.