PHP Primer

PHPinfo Howto

quagmyreby quagmyre

An Adult Website without scripts is about impossible to run and grow into something really large so as as Adult Webmaster you really need to learn a thing or two about scripting languages. PHP is a relatively simple and versatile scripting language that is quick to learn. Today, we are going to show you a bit about how it works and briefly cover a bit about syntax. Using PHP you can fully automate certain aspects of adult websites and take away a good portion of the tedium that we call our work day.

Most programming tutorials start with teaching "hello world" but i think that is a waste. I think that any code you write should have a specific real world use. Our first PHP tutorial is very simple but also very necessary. Have no worries, these tutorials will get progressively more difficult. We are going to find out if our server has PHP installed and what environmental options are set up. To do this, we are going to set up a simple page to put on the server.



Here is the code:

<?php
phpinfo();
?>


You would save that to your web server in your HTML folder as phpinfo.php or something equally creative. Here is what it is: All php code must start with "<?php" and ends with "?>"which lets the php parser know it is code and not just text or HTML. Quick note: you *can* use just <? instead of <?php on most servers but for compatibility it is correct to waste the extra 3 characters and play it safe. The "phpinfo" is a function. Basically, a function is a built in subroutine. The phpinfo subroutine tells the PHP parser to spill it's guts and tell you all about itself. It will tell the PHP version number, the server OS version, values of configuration options, default header options and if PHP is configured for other server applications like MySQL.

"()" Is where any arguments would go. No, this does not mean you get to debate things with PHP, it is pretty stubborn and set in it's ways. This means different subtasks to the function. Because the "()" is empty, it means all of the information is shown in the output. if we had said "phpinfo(INFO_LICENSE)" instead it will show only the PHP license in the output. See the php manual for more options. A neat trick with the php manual is if you know a function and want to know more about it you put http://www.php.net/function_name in your browser. For instance, the last link is http://www.php.net/phpinfo and you would use http://www.php.net/echo to go to the manual page on echo.

Most every line in PHP code ends with a ";" which is why it is there. As you code, you will spend a lot of time trying to figure out why your scripts don't work only to find it is because you dropped a ";" from your code or some other simple typo. Sorry, but it is true.

Go ahead and type this code into a file called phpinfo.php and upload it to your server's web root (make link) then fire up your browser and go to http://www.somedomain.com/phpinfo.php (replace somedomain.com with your actual domain name) and you will see what I meant by "output" above. Want to see how it should look? Check these Google results.

It didn't work? Check your typing and make sure you saved it as phpinfo.php and that Notepad did not turn it into phpinfo.php.txt or some such silliness. If you have checked it a dozen times and are sure you have everything right then there is a good chance that PHP is not on your server. Time to holler at the host and see about getting them to install PHP.

Oh, I misheard you and it works fine? Then view the source on the phpinfo.php page and you will see that most all of the valid HTML has been produced by the function. Not entirely valid mind you, but close enough for the purposes of this page so we won't bother hacking the PHP configuration and fixing it, maybe in the future. For now, we will let it be stubborn. I know it was simple, but it beat the Hell out of "Hello World" IMHO. More to come as we build our site!
Really want that Hello World Tutorial? Here it is.


copyright by quagmyre, Inc. 2000-2003 © Don't be a fuck!

Privacy Statement