Why PHP?
Whenever possible I try to stay away from Microsoft products and .asp is just insane and bloated. PHP is swift and easy to use once you get a solid handle on it. Even if you like MS and you select that for your operating system on your server you can still run PHP which is part of the beauty of the language. On this page you’ll find downloadable scripts as well as the text files which show you the code so you can create things for your own website such as contact us forms. A lot of places try to provide contact forms like Go Daddy, LLC (for instance but they also like to keep their secrets because their forms are often times very difficult to use. Primarily because they are fearful of being…well, honestly I can’t really think of any reason to defend their stance on things. I guess if you would like to know why they do things they do you can contact them. Either way, here on my site I hope you will find it a place that doesn’t mind sharing the “secrets of the coding trade” then you can have fun getting your site to do what you want. On this particular page I was going to share different code that you can use on your web page. A lot of the code I’ve figured out on my own just coding around. Hopefully you can find some of my code helpful.
Time to get the led out!
In this area I will include the download links to the files so you can download them in .zip format(s) as well as viewing the code as .txt files. If you would like to download the .txt file, copy/paste then just change the file extension you can do that as well. As time moves forward I will be adding more to this list but for now this is a good start. Enjoy 😉
PHP & HTML Code Samples
- Contact Us Form
CLICK HERE to download the zip file which includes both the index.php and the actual contact us form page titled matts_contact_form.php.- Look at the code for the index page HERE. This will simply open a new window and allow you to view the content that would be in the index.php file. Again, if you would like to simply copy/paste the code and drop it in a .txt document and then just rename the file extention. It does need to be used with the matts_contact_form.php file though.
- Of course, HERE is the PHP code which makes the whole form work. It is designed so you can add in special fields such as “PHONE” or “ADDRESS” and such.
- Password Protect Page Using PHP
Step 1.The main idea is to insert only one line of code into each of your web pages you want to protect. This code includes a form processing script at the beginning of your original code. It first displays a small form to enter your password and if it is ok then shows the original page content.So now we need to create a PHP script with a simple form processing. The form is very simple, only a password field and a submit button is present. The code is the following:<?php
function showForm($error=“LOGIN”){
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“DTD/xhtml1-transitional.dtd”>
<html>
<body>
<?php echo $error; ?>
<form action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>” method=”post” name=”pwd”>
Password:
<table>
<tr>
<td><input name=”passwd” type=”password”/></td>
</tr>
<tr>
<td align=”center”><br/>
<input type=”submit” name=”submit_pwd” value=”Login”/>
</td>
</tr>
</table>
</form>
</body>
<?php
}
?>Step 2.
As we don’t want to show the form always we put it inside a function and this function will be called if necessary. The main application logic checks if the form was submitted or not. If not then displays the form else check the entered password. If it fails then informs the visitor and displays the login form again. If the password was right then we do nothing so the rest of the code will be displayed.
Don’t forget that in case of displaying the form we need to exit from the code processing to hide the important page content.
The application logic looks like this:
<?php
$Password = ‘demo’; // Set your password hereif (isset($_POST[‘submit_pwd’])){
$pass = isset($_POST[‘passwd’]) ? $_POST[‘passwd’] : ”;if ($pass != $Password) {
showForm(“Wrong password”);
exit();
}
} else {
showForm();
exit();
}
?>As you can see the password is hard coded and exists in human readable format. If you want you can store it in a separate file and encode it for example with md5() function. All is up to you.
Step 3.
Now we are ready with the script. Now if you want to protect any of your pages you need to insert the following line of code at the beginning of your PHP code:
<?php require_once(‘protector.php’); ?>
Summary of Downloads & Extra Links
Program Downloads