Monday, June 28, 2010

PHP's mail function

Assuming you have gotten to this tutorial, then you have successfully installed PHP, MySQL and Apache on your computer. I am also assuming you remember to turn the services ON before you try this tutorial.

In this tutorial, we will write a simple automated PHP emailer... it is the simplest PHP mail function code I could come up with.

Open Komodo. Select 'file' and create a new PHP file. Remember that in order to work, you need to save your PHP files in /Applications/MAMP/htdocs (for MAC) and C:/XAMPP/htdocs/xampp/ (for Windows). See my older tutorials on configuring your PC or Mac for PHP if you are unfamiliar with either environment or are just starting out.

Once you have your blank PHP file open, type in the following: (due to security restrictions of this site I have to leave spaces between ">","<","?" and "php". Please be sure to OMIT those spaces in your final code).

< ? php

$message = "Take me to your leader. This message was generated by PHP code";
$reply_email = "youremail@gmail.com";
$target_email = "yourtarget@gmail.com";

mail($target_email, "Greetings Earthings", $message, "From: $reply_email");

? >

I would recommend setting the target email to an email address you have access to until you are certain that your code is working correctly. Save it as something like emailer.php in /Applications/MAMP/htdocs (for MAC) and C:/XAMPP/htdocs/xampp/ (for Windows)

To actually execute this little program (on a Mac), go to http://localhost:8888/ to get to the index directory. Click on the name of your file. To execute this code (on a PC) go to http://localhost/xampp/emailer.php or whatever you named it.

If it executes, all you will see is a blank white screen. You will have to check your target email to REALLY know if your code is working properly. Please do not jump into this code until you know for SURE that you have your PHP environment working properly FIRST!

Sunday, June 27, 2010

Your first REAL PHP editor

So, you have managed through much study and prayer to install and configure your PC or Mac for PHP... that is all fine and dandy--but now what? Your computer has become a very small server from which you can connect to some BIGGER more POWERFUL server, if only you could get your code together...

And that is where the Komodo Editor can be a real life saver. It helps you take your PHP code from its location in Applications\MAMP\htdocs\ (for Mac) or C:\XAMPP\htdocs\xampp\ (for Windows) and sends it out to your real server somewhere far far away...

After downloading Komodo:

1. Click file

2. Select PHP as the code type from the right hand list

3. Write your PHP code... mine will be for attachment stripping if I can get it to load (stay tuned)

4. Name your file with the .php extension. Note that you can also open files from your server, provided you have authorized access to them.

5. You can now save your files to your server by entering your server info at the prompt screens

The joy of what to actually WRITE in your php file, I will address in my next short little blog...

Configuring the PC for PHP, MySQL and Apache

When we last left off, I had just configured a Mac for PHP, MySQL and Apache. Since my personal computer runs Windows XP, it only seems fitting that our next tutorial be geared towards the PC...

You will need XAMPP. It contains PHP, MySQL and Apache in one package.

1. Install XAMPP, being careful to note where it is storing itself in your directory. We are going to assume you left it at its default setting...

2. Click the XAMPP Control Panel icon that should have installed on your desktop.

3. When it opens, check the Apache and MySQL boxes.

4. Click Admin. You will be taken to the default splash.php screen.

5. To modify this default screen, go to: C:\XAMPP\htdocs\xampp\splash.php

6. Using a text editor like notepad, open splash.php and add the line: < ? php echo "hello"; ? > and save it. (please note that their is NO space between the "<", ">", "php" and the " ?" The spaces were added to over-ride some security features of this blog page)

7. Your changes should be visible by opening your browser and typing: http://localhost/xampp/splash.php

You should note that all php files you create need to be stored in the htdocs\xampp folder in order to function properly...

Configuring the Mac for PHP programming

Ok, so I get it--there are a LOT of tutorials about how to activate your PHP on the Mac 10.6 OS... but none of them REALLY helped me in the lab so I poked around until I found my own way to set up a good programming environment for PHP, Apache and MySQL environment...

Basically, one needs three pieces of software for this: Cyberduck for ftp client, Text Wrangler to edit PHP and MAMP to act as a local server. Some websites tell you that a better way is to modify your computers config files, but I was not able to get ANYTHING to work that way.

After you download the three above programs:

1. Open Text Wrangler and type: < ? php infophp(); ? > (please note that their is NO space between the "<", ">", "php" and the " ?" The spaces were added to over-ride some security features of this blog page)
2. Save as 'info.php' in Applications>MAMP>htdocs
3. Open Firefox or some other web browser and type http://localhost:8888/
it should bring up your index page. The 8888 is your Apache port that you will need in future
4. Click on info.php

If all goes well...

A page should pop up with details about your PHP... if not, something else has gone horribly awry...

Setting up CyberDuck is my next big adventure... I need to get the server info from the client...

Monday, June 14, 2010

My morning Toast and problem...

Last night in the labs, I had one of those interesting situations arise that SHOULD have been a "no brainer" to solve, yet actually caused me a great deal of unexpected Toast Titanium oddities.

It all started when a non-Apple using student entered my lab to copy a DVD--and not just ANY DVD, but a portfolio/movie/super-important DVD that needed to be submitted by the next morning... He had only one DVD-R to write this copy to...

"Will Toast burn a DVD?" "We can always try!" I had burned CD's with Toast before--what was the worst that could happen? Toast popped up and demanded admin username and password.... It asked for my email.... It asked to do updates--THEN it decided to burn the DVD. Three minutes later, the lab computer spat forth its unholy creation... The resulting DVD had separated out the audio from the video into two separate files and was rendered unplayable...

Feeling utter ashamed at my bad advice and apparent lack of Toast Titanium knowledge, I copied his DVD to a file on the computer, told him to return in the morning FIRST THING, and skittered off to Walmart to get some extra DVD's... Why, oh why--did Toast burn DVD's differently and where did I go wrong?

The next morning, I arrived with ten extra DVD's, used ARP to drag the students folder to my workstation and began experimenting. The Toast Titanium online help was not really helpful... Google search resulted in a number of helpful movie hacking ideas, but not much for the law-abiding among us...

Toast it has a fascinating feature. One can take a file and convert it to an ISO-like object assigned with a .toast extension. You can access it by opening Toast and selecting the little icon with two DVD's on it. Once there, select "Image File." I drug the copied file into the resulting screen and clicked "save as disk image." I then selected the resulting .toast file and drug it back in and hit the record button... A simple burn later, I had a DVD in hand when my student arrived at the lab...
He was happy--I was happy... and now I carry extra DVD's with me.