Ann's Corner |
![]() |
||||
Professional Life |
PHP CodePHP is a very versatile, easy to use language. Here are a few of my most often used snippets of code. Sometimes you will need to know what your host is running and what you have access to using PHP. To find out, create a file named something like "phpinfo.php" and save it in the root directory of your site. Put the following code snippet at the top of this file, save it and access the page with your browser. //php info<?php echo phpinfo(); ?> Any variable you create can be echoed onto any page. For
instance, to personalize a greeting for each user simply create an html
form on a page, set the forms' action to post to itself, then call the
variable
you just posted. <form name="form1" method="post" action="<?php echo "$thisfile";?>"> Now at the very top of whatever.php, enter this code:
On your page where you want the personalized greeting to appear, enter this code:
What this does is each time the page loads, it will check
to see if the variable "name" is in the url. If it isn't,
nothing happens, but if it is, whatever value the user entered into the
form "name" box will be echoed back to the page. The last useful php snippet I'll post here is about manipulating dates. This snippet will echo the current date and time wherever you put it on your page. <?php // Prints something like: Wednesday
|
||||
Hobbies |
|||||
Photography |
|||||
| You are the 165717 visitor. |
|||||