|If you have read the first two tutorials in this series you should have everything installed on your computer that you will need to write and test your PHP programs. So let's get started. First open the Sokkit Control Panel and verify that the Sokkit web server is running. The button in the Web Server Controls section should be green. We will not be using MySQL. So you can leave that set to Stopped. Now open your text editor and type these three lines of code.|
Now let's break down the code and see how it works.
That's all you have to do to print "Hello World" in the web browser. Are you asking yourself why you would even bother to write this script when you can do the same thing with basic HTML? Well, you probably wouldn't. This is an oversimplified example of a PHP script. In reality you would be using PHP to control what is printed to the webpage. For example: Is it Saturday? If yes, then print "What are you doing at work on a Saturday?". If it is not Saturday, then print "Get to Work".
Now you are ready to save your new script as a PHP program file. Click File and Save As and name your new script HelloWorld.php3. The php3 extension will tell the server to process this file as a PHP script and not as an HTML webpage. When you save your file you need to save it in the following location.
Are you in the right folder? If you see an HTML file called sokkitdefault.html, then you are in the right place.
Now we will test the script. Open the Sokkit Control Panel again and RIGHT click on the View Site button. Choose "Open in New Window" from the pop-up list. This will cause the sokkitdefault.html webpage to be displayed in the new window. You should see a message saying "This site is powered by Sokkit 3.4". Now go to the url address line in the web browser. It should say http://localhost/. To test your script all you need to do is to add HelloWorld.php3 at the end of this and click Enter. That will start your script and you will see a white page with the words "Hello World."
Congratulations! You have just written your first PHP program.