Entries Tagged 'PHP' ↓

PHP: Classes & OOP

Object orientated programming (OOP) is a commonly used term when discussing modern programming techniques. One of the things that makes humans stand out is the ability to categorise - we put objects into categories of similar type of function. For example, we have the category vechicle. Within this category, you have the different types of vehicle - car, bug, train, van. In the same bag, a llama is a type of animal. This analogy applies to programming - we create functions to do specific tasks and then group similar functions into classes. No only does this organise everything, but also allows a common access point for these similar functions.

Continue reading →

PHP Functions : An Introduction

Functions are a very important part of PHP and it is probably safe to say that they are used in every single script. This tutorial will guide you through the basics of PHP functions to creating your own to do specific tasks.

You have already used many functions with PHP. Every time you do:

<?php
explode(’ ‘, $value1);
?>

you’re using a function. These are known as built in PHP functions because they are the same and are available on every PHP setup. You can access them in any script without needing to do anything special.

A function can be classed as a subprogram that can act on data and return a value. Each function has its own name and when that name is encountered, the execution of the programme branches off to the first line (or statement) of that function. When the function has completed, it ‘returns’ and execution resumes from where it left off. A function will perform a specific task and do it well, returning the value you want with the arguments you pass to it.

When you lookup a function on the PHP website e.g explode(), you will see the description of the function, and what it does first. The description then explains how to use the function.

Continue reading →

Serialize this - Saving Objects in PHP

Author: Kevin Davies

When building my website “Crossword Heaven” I came across a problem. I created a PHP object called “crossword” but needed to save the information in the object to a database. Now considering that this object contained a lot of information this was not an easy thing to do. Or was it?

The answer: serialize().

What the serialize() function does is take something like an array or object and converts it into a string that can be stored in a database. All I had to do so that I could save the crossword object is something like “serialize($crossword).” Easy! Some words of warning though. If you’re using a version of PHP less than version 4 watch out because only properties get saved, not methods.

Here’s a peek at the actual code:

Continue reading →

Track your visitors, using PHP

Author: Dennis Pallett

There are many different traffic analysis tools, ranging from simple counters to complete traffic analyzers. Although there are some free ones, most of them come with a price tag. Why not do it yourself? With PHP, you can easily create a log file within minutes. In this article I will show you how!

Getting the information The most important part is getting the information from your visitor. Thankfully, this is extremely easy to do in PHP (or any other scripting language for that matter). PHP has a special global variable called $_SERVER which contains several environment variables, including information about your visitor. To get all the information you want, simply use the following code:

Continue reading →

PHP On-The-Fly!

Author: Dennis Pallett

Introduction PHP can be used for a lot of different things, and is one of the most powerful scripting languages available on the web. Not to mention it’s extremely cheap and widely used. However, one thing that PHP is lacking, and in fact most scripting languages are, is a way to update pages in real-time, without having to reload a page or submit a form.

The internet wasn’t made for this. The web browser closes the connection with the web server as soon as it has received all the data. This means that after this no more data can be exchanged. What if you want to do an update though? If you’re building a PHP application (e.g. a high-quality content management system), then it’d be ideal if it worked almost like a native Windows/Linux application.

Continue reading →

PHP and Cookies; a good mix!

Author: Dennis Pallett

Introduction Cookies have long been used in PHP scripts, and are a very useful function. But what exactly are cookies? Maybe you have used then, but you still don’t know exactly what they are. Or you are completely new to cookies? It doesn’t matter, because in this tutorial I will show you exactly what cookies are, and what they are used for.

Cookies in a nutshell Cookies are small pieces of information that is stored on the computer of your visitors. Each browser handles it differently, but most simply store the information in a small text file. Internet Explorer has a special folder, which can be found in your C:Windows or C:WindowsSystem32 folder. You can delete all your cookies, by going to the Options and ‘Clearing Cookies’ or deleting them by hand. I don’t recommend this though.

Continue reading →

Mastering Regular Expressions in PHP

Author: Dennis Pallett

What are Regular Expressions?

A regular expression is a pattern that can match various text strings. Using regular expressions you can find (and replace) certain text patterns, for example “all the words that begin with the letter A” or “find only telephone numbers”. Regular expressions are often used in validation classes, because they are a really powerful tool to verify e-mail addresses, telephone numbers, street addresses, zip codes, and more.

In this tutorial I will show you how regular expressions work in PHP, and give you a short introduction on writing your own regular expressions. I will also give you several example regular expressions that are often used. Regular Expressions in PHP Using regex (regular expressions) is really easy in PHP, and there are several functions that exist to do regex finding and replacing. Let’s start with a simple regex find.

Have a look at the documentation of the preg_match function. As you can see from the documentation, preg_match is used to perform a regular expression. In this case no replacing is done, only a simple find. Copy the code below to give it a try.

<?php

// Example string $str = "Let’s find the stuff <bla>in between</bla> these two previous brackets";

// Let’s perform the regex $do = preg_match("/<bla>(.*)</bla>/", $str, $matches);

// Check if regex was successful if ($do = true) { // Matched something, show the matched string echo htmlentities($matches['0']);

// Also how the text in between the tags echo ‘<br />’ . $matches['1']; } else { // No Match echo "Couldn’t find a match"; }

?>

After having run the code, it’s probably a good idea if I do a quick run through the code. Basically, the whole core of the above code is the line that contains the preg_match. The first argument is your regex pattern. This is probably the most important. Later on in this tutorial, I will explain some basic regular expressions, but if you really want to learn regular expression then it’s best if you look on Google for specific regular expression examples.

The second argument is the subject string. I assume that needs no explaining. Finally, the third argument can be optional, but if you want to get the matched text, or the text in between something, it’s a good idea to use it (just like I used it in the example). The preg_match function stops after it has found the first match. If you want to find ALL matches in a string, you need to use the preg_match_all function. That works pretty much the same, so there is no need to separately explain it.

Now that we’ve had finding, let’s do a find-and-replace, with the preg_replace function. The preg_replace function works pretty similar to the preg_match function, but instead there is another argument for the replacement string. Copy the code below, and run it.

<?php

// Example string $str = "Let’s replace the <bla>stuff between</bla> the bla brackets";

// Do the preg replace $result = preg_replace ("/<bla>(.*)</bla>/", "<bla>new stuff</bla>", $str);

echo htmlentities($result); ?>

The result would then be the same string, except it would now say ‘new stuff’ between the bla tags. This is of course just a simple example, and more advanced replacements can be done.

You can also use keys in the replacement string. Say you still want the text between the brackets, and just add something? You use the $1, $2, etc keys for those. For example:

<?php

// Example string $str = "Let’s replace the <bla>stuff between</bla> the bla brackets";

// Do the preg replace $result = preg_replace ("/<bla>(.*)</bla>/", "<bla>new stuff (the old: $1)</bla>", $str);

echo htmlentities($result); ?>

This would then print “Let’s replace the new stuff (the old: stuff between) the bla brackets”. $2 is for the second “catch-all”, $3 for the third, etc.

That’s about it for regular expressions. It seems very difficult, but once you grasp it is extremely easy yet one of the most powerful tools when programming in PHP. I can’t count the number of times regex has saved me from hours of coding difficult text functions.

An Example What would a good tutorial be without some real examples? Let’s first have a look at a simple e-mail validation function. An e-mail address must start with letters or numbers, then have a @, then a domain, ending with an extension. The regex for that would be something like this: ^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$

Let me quickly explain that regex. Basically, the first part says that it must all be letters or numbers. Then we get the @, and after that there should be letters and/or numbers again (the domain). Finally we check for a period, and then for an extension. The code to use this regex looks like this:

<?php

// Good e-mail $good = "john@example.com";

// Bad e-mail $bad = "blabla@blabla";

// Let’s check the good e-mail if (preg_match("/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$ /", $good)) { echo "Valid e-mail"; } else { echo "Invalid e-mail"; }

echo ‘<br />’;

// And check the bad e-mail if (preg_match("/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$ /", $bad)) { echo "Valid e-mail"; } else { echo "Invalid e-mail"; }

?>

The result of this would be “Valid E-mail. Invalid E-mail”, of course. We have just checked if an e-mail address is valid. If you wrap the above code in a function, you’ve got yourself a e-mail validation function. Keep in mind though that the regex isn’t perfect: after all, it doesn’t check whether the extension is too long, does it? Because I want to keep this tutorial short, I won’t give the full fledged regex, but you can find it easily via Google.

Another Example Another great example would be a telephone number. Say you want to verify telephone numbers and make sure they were in the correct format. Let’s assume you want the numbers to be in the format of xxx-xxxxxxx. The code would look something like this:

<?php

// Good number $good = "123-4567890";

// Bad number $bad = "45-3423423";

// Let’s check the good number if (preg_match("/d{3}-d{7}/", $good)) { echo "Valid number"; } else { echo "Invalid number"; }

echo ‘<br />’;

// And check the bad number if (preg_match("/d{3}-d{7}/", $bad)) { echo "Valid number"; } else { echo "Invalid number"; }

?>

The regex is fairly simple, because we use d. This basically means “match any digit” with the length behind it. In this example it first looks for 3 digits, then a ‘-’ (hyphen) and finally 7 digits. Works perfectly, and does exactly what we want.

What exactly is possible with Regular Expressions?

Regular expressions are actually one of the most powerful tools in PHP, or any other language for that matter (you can use it in your mod_rewrite rules as well!). There is so much you can do with regex, and we’ve only scratched the surface in this tutorial with some very basic examples.

If you really want to dig into regex I suggest you search on Google for more tutorials, and try to learn the regex syntax. It isn’t easy, and there’s quite a steep learning curve (in my opinion), but the best way to learn is to go through a lot of examples, and try to translate them in plain English. It really helps you learn the syntax.

In the future I will dedicate a complete article to strictly examples, including more advanced ones, without any explanation. But for now, I can only give you links to other tutorials: The 30 Minute Regex Tutorial Regular-Expressions.i nfo

About the author: Dennis Pallett is a young tech writer, with much experience in ASP, PHP and other web technologies. He enjoys writing, and has written several articles and tutorials. To find more of his work, look at his websites at http://www.phpit.net, http://www.aspit.net and http://www.webdev-articles.com

Autoresponders With PHP

Author: Robert Plank

First off, check out the URL below. You’ll learn how to make that today. http://www.jumpx.com utorials/3/signup.html

Fill out your e-mail address on the page you see. (I promise it’s not being saved anywhere.) Then, wait a minute or two and check your mail. You should get a message from Gumby (null@jumpx.com) containing a sample autoresponder message.

Today, we’re going to learn three easy things: redirection, mail sending, and form submission.

When we finish with that, you will know how to put those components together and create an autoresponder. Because if you think about it, that’s all an autoresponder does. Somebody enters in their e-mail address, are sent an e-mail message, and then are redirected to a new page.

Of course there are more complex autoresponders, like Gary Ambrose’s Opt-In Lightning, or Wes Baylock’s Mail Master Pro which handle multiple follow-ups and record the e-mail addresses of those who have signed up for the responder. But today we’re just going to focus on how to make a very basic, very simple autoresponder.

Hopefully, you’ve seen what form objects in HTML look like. Here’s some code you can use for an example:

<form action=”some-script.php” method=”post”> Enter Your E-Mail Address: <input type=”text” name=”email” size=”30″>  <input type=”submit” value=”Submit”>

Copy and paste this code into a file called “signup.html” and upload it to your web server. You’ll see a text box waiting for your visitor to enter his or her e-mail address so they can be sent that autoresponse message.

Of course, the form won’t work just yet because, if you look at the first line of that HTML code I gave you, you’ll see that the form submits to a script called “some-script.php”. And we haven’t made that just yet.

Look on the second line of “signup.html”, at the last half of the line. You should be familiar with HTML tags, but if you’re not, an HTML tag consists of two parts: the parent tag and the attributes.

The parent tag is simply the tag’s designation. For example, if you had a slice of HTML code that looked like this:

<font face=”Verdana” size=”1″>

Then the parent tag would be “font”. The rest of what’s enclosed in the tag tells the browser what to do with it. For example, in this tag the attributes are that the font should be Verdana with size 1.

Why am I telling you all this? Because it relates to the HTML code you see in signup.html.

Now, when you look at this: <input type=”text” name=”email” size=”30″>

The code tells the receiving browser that this is an “input” tag, meaning that it’s a form field. The name of this item is “email” and its size is 30, meaning this text box should be 30 characters in width.

When the form is submitted, it takes all the values of all the fields inside that form and throws it at its destination. In this case, our destination is “some-script.php”.

If you’re lost, this will all make a whole lot more sense once you try this next step.

Make a file called “some-script.php” and paste this line of code into it:

<?php echo $email; ?>

Upload the script in the same folder as signup.html, and go to “signup.html”. Type your e-mail address in and click the submit button.

You should see a new page containing just your e-mail address and nothing else.

Is this starting to make sense? You told the PHP script to dump the contents of the variable called “email” to the screen, and you just submitted a form with a text box called “email”.

If you want to try one more exercise like this, change the name of the text box to, say, “goober” in signup.html and change the $email in some-script.php to $goober. Upload both, go to signup.html, and type anything into the text box. You’ll get the same result.

This is how you’ll pass data from forms (like text fields, drop down menus, radio buttons and the like) along into the PHP scripts you create.

We’ve just covered how to submit form elements into PHP. Now let’s focus on sending mail.

PHP has a really simple function that uses whatever mail sending program is installed on your server to send messages to the outside world. If you have a crappy web server, this step might not work and you’ll have to use a different web host if you want to try this.

But if you’re on a good web host that has PHP installed *correctly*, this shouldn’t be a problem.

Up until now we haven’t used functions in PHP too much, aside from simple things like include() and header(). Today’s your lucky day, because functions work in a very similar way to HTML tags. You have the parent tag, and the attributes (or parameters).

The mail() function basically works like this:

mail(”recipient”,”subject”,”body”,”headers”);

Let’s start off by sending a simple e-mail message to yourself. We won’t need any special headers this time around, so this will be quick and painless. Copy this one line of code into “mailtest.php”:

<?php mail(”billg@microsoft.com”,”Hello”,”Hi. This is the body of my message.”); ?>

Replace “billg@microsoft.com” with your actual e-mail address, but be *sure* to keep quotes around it. Save it, and upload mailtest.php to your web server and run it in the browser. You should see a blank page. Wait a few minutes and check your mail. You should see a mysterious mail message in your box with the subject “Hello” and the message “Hi. This is the body of my message.”

If you’re using a free e-mail service or a weird ISP, the message won’t come through because a lot of mail servers these days require that certain headers are present in the message.

Let’s do that now.

What’s below isn’t important enough to explain thoroughly, but it’s just header information that is interpreted by the mail server. This data tells us that we’re sending a plain text e-mail, that the message came from your e-mail address (and gives your name), and tells us that the e-mail “client” we used was PHP.

$headers = “Content-Type: text/plain; charset=us-ascii From: $myname <$mymail> Reply-To: <$mymail> Return-Path: <$mymail> X-Mailer: PHP”;

This is the code you should have by this point, complete with the header information and the variables which tell the script what your name and e-mail address are:

<?php

$email = “billg@microsoft.com”;

$myname = “Your Name Here”; $mymail = “your@email.here”;

$headers = “Content-Type: text/plain; charset=us-ascii From: $myname <$mymail> Reply-To: <$mymail> Return-Path: <$mymail> X-Mailer: PHP”;

mail($email,”Hello”,”Hi. This is the body of my message.”,$headers);

?>

Notice how we’ve simplified things a bit by using variables in the mail() function. That way we don’t have to retype things. This method also looks better (in my opinion anyway) and is easier to tweak once you’re ready to actually customize it for yourself.

Try this out again. Believe it or not, but you just made your first autoresponder! Before we move on let’s make this look even cleaner:

<?php

$myname = “Your Name Here”; $mymail = “your@email.here”;

$subject = “Hello”; $body = “Hi. This is the body of my message. Notice how I can continue typing right on the next line!”;

$headers = “Content-Type: text/plain; charset=us-ascii From: $myname <$mymail> Reply-To: <$mymail> Return-Path: <$mymail> X-Mailer: PHP”;

if ($email != “”) { mail($email,$subject,$body,$headers); }

?>

All I did here was just make things look nicer, but notice how I removed the line that set $email to “billg@microsoft.com.” This is because the value of $email will be passed to the script from that form we made earlier.

This also sends the e-mail message ONLY if the value of $email is not blank. So if someone just hit the submit button without entering an address, the script won’t try to send the e-mail message.

Everything should be ready for you to try out now. Re-upload “some-script.php” and go to signup.html. Enter your e-mail address in the field, hit submit and wait for that mail message to arrive.

There’s only one step left to making this autoresponder complete. And that’s sending the user somewhere so they aren’t given a blank page.

Find this line in your script: if ($email != “”) { mail($email,$subject,$body,$headers); }

And paste this directly underneath it: header(”Location:http://www.jumpx.com”); die();

Try the autoresponder out. You’ll see that once the autoresponse message is sent, you’re directed to www.jumpx.com. Now, go ahead and change it to whatever URL you want to use. Or, make use it with a variable so the end result is like this:

<?php

$myredirect = “http://www.my-domain-name.com hankyou.html”;

$myname = “Your Name Here”; $mymail = “your@email.here”;

$subject = “Hello”; $body = “Hi. This is the body of my message. Notice how I can continue typing right on the next line!”;

$headers = “Content-Type: text/plain; charset=us-ascii From: $myname <$mymail> Reply-To: <$mymail> Return-Path: <$mymail> X-Mailer: PHP”;

if ($email != “”) { mail($email,$subject,$body,$headers); } header(”Location:$myredirect”); die();?>

Don’t forget to change the values above. “http://www.my-domain-name.com hankyou.html” needs to point to the URL where thankyou.html is stored.

You’re done. Don’t forget to send John feedback for me. If you’re really curious as to how to do something in PHP, I might just write an article on it.

About the author: Article by Robert Plank PHP Newsletter: http://www.jumpx.com/newsletter

Feedback? http://www.jumpx.com/feedback.php

Developing State-enabled Applications With PHP

Author: John L

Installment 1

Developing State-enabled Applications With PHP

When a user is browsing through a website and is surfing from one web page to another, sometimes the website needs to remember the actions (e.g. choices) performed by the user. For example, in a website that sells DVDs, the user typically browses through a list of DVDs and selects individual DVDs for check out at the end of the shopping session. The website needs to remember which DVDs the user has selected because the selected items needs to be presented again to the user when the user checks out. In other words, the website needs to remember the State - i.e. the selected items - of the user’s browsing activities.

However, HTTP is a Stateless protocol and is ill-equipped to handle States. A standard HTML website basically provides information to the user and a series of links that simply directs the user to other related web pages. This Stateless nature of HTTP allows the website to be replicated across many servers for load balancing purposes. A major drawback is that while browsing from one page to another, the website does not remember the State of the browsing session. This make interactivity almost impossible.

In order to increase interactivity, the developer can use the session handling features of PHP to augment the features of HTTP in order to remember the State of the browsing session. The are basically 2 ways PHP does this: 1. Using cookies 2. Using Sessions

The next installment discusses how to manage sessions using cookies…

Installment 2

Cookies

Cookies are used to store State-information in the browser. Browsers are allowed to keep up to 20 cookies for each domain and the values stored in the cookie cannot exceed 4 KB. If more than 20 cookies are created by the website, only the latest 20 are stored. Cookies are only suitable in instances that do not require complex session communications and are not favoured by some developers because of privacy issues. Furthermore, some users disable support for cookies at their browsers.

The following is a typical server-browser sequence of events that occur when a cookie is used: 1. The server knows that it needs to remember the State of browsing session 2. The server creates a cookie and uses the Set-Cookie header field in the HTTP response to pass the cookie to the browser 3. The browser reads the cookie field in the HTTP response and stores the cookie 4. This cookie information is passed along future browser-server communications and can be used in the PHP scripts as a variable

PHP provides a function called setcookie() to allow easy creation of cookies. The syntax for setcookie is: int setcookie(string name, [string val], [int expiration_date], [string path], string domain, [int secure])

The parameters are: 1. name - this is a mandatory parameter and is used subsequently to identify the cookie 2. value - the value of the cookie - e.g. if the cookie is used to store the name of the user, the value parameter will store the actual name - e.g. John 3. expiration_date - the lifetime of the cookie. After this date, the cookie expires and is unusable 4. path - the path refers to the URL from which the cookie is valid and allowed 5. domain - the domain the created the cookie and is allowed to read the contents of the cookie 6. secure - specifies if the cookie can be sent only through a secure connection - e.g. SSL enable sessions

The following is an example that displays to the user how many times a specific web page has been displayed to the user. Copy the code below (both the php and the html) into a file with the .php extension and test it out.

[?php //check if the $count variable has been associated with the count cookie if (!isset($count)) { $count = 0; } else { $count++; } setcookie("count", $count, time()+600, "/", "", 0); ?]

[html] [head] [title]Session Handling Using Cookies[/title] [/head] [body] This page has been displayed: [?=$count ?] times. [/body] [/html]

The next installment discusses how to manage sessions using PHP session handling functions with cookies enabled…

Installment 3

PHP Session Handling - Cookies Enabled

Instead of storing session information at the browser through the use of cookies, the information can instead be stored at the server in session files. One session file is created and maintained for each user session. For example, if there are three concurrent users browsing the website, three session files will be created and maintained - one for each user. The session files are deleted if the session is explicitly closed by the PHP script or by a daemon garbage collection process provided by PHP. Good programming practice would call for sessions to be closed explicitly in the script.

The following is a typical server-browser sequence of events that occur when a PHP session handling is used: 1. The server knows that it needs to remember the State of browsing session 2. PHP generates a sssion ID and creates a session file to store future information as required by subsequent pages 3. A cookie is generated wih the session ID at the browser 4. This cookie that stores the session ID is transparently and automatically sent to the server for all subsequent requests to the server

The following PHP session-handling example accomplishes the same outcome as the previous cookie example. Copy the code below (both the php and the html) into a file with the .php extension and test it out.

[?php //starts a session session_start();

//informs PHP that count information needs to be remembered in the session file if (!session_is_registered("count")) { session_register("count"); $count = 0; } else { $count++; }

$session_id = session_id(); ?]

[html] [head] [title]PHP Session Handling - Cookie-Enabled[/title] [/head] [body] The current session id is: [?=$session_id ?] This page has been displayed: [?=$count ?] times. [/body] [/html]

A summary of the functions that PHP provides for session handling are: 1. boolean start_session() - initializes a session 2. string session_id([string id]) - either returns the current session id or specify the session id to be used when the session is created 3. boolean session_register(mixed name [, mixed ...]) - registers variables to be stored in the session file. Each parameter passed in the function is a separate variable 4. boolean session_is_registered(string variable_name) - checks if a variable has been previously registered to be stored in the session file 5. session_unregister(string varriable_name) - unregisters a variable from the session file. Unregistered variables are no longer valid for reference in the session. 6. session_unset() - unsets all session variables. It is important to note that all the variables remain registered. 7. boolean session_destroy() - destroys the session. This is opposite of the start_session function.

The next installment discusses how to manage sessions using PHP session handling functions when cookies are disabled…

Installment 4

PHP Session Handling - Without Cookies

If cookies are disabled at the browser, the above example cannot work. This is because although the session file that stores all the variables is kept at the server, a cookie is still needed at the browser to store the session ID that is used to identify the session and its associated session file. The most common way around this would be to explicitly pass the session ID back to the server from the browser as a query parameter in the URL.

For example, the PHP script generates requests subsequent to the start_session call in the following format: http://www.yourhost.com/yourphpfile.php?PHPSESSID=[actual session ID]

The following are excerpts that illustrate the discussion:

Manually building the URL: $url = “http://www.yoursite.com/yourphppage.php?PHPSESSID=” . session_id(); [a href="[?=$url ?]“]Anchor Text[/a]

Building the URL using SID: [a href="http://www.yoursite.com/yourphppage.php?[?=SID ?]“]Anchor Text[/a]

About the author: This PHP scripting article is written by John L. John L is the Webmaster of The Ultimate BMW Blog! (http://www.bimmercenter.com).

PHP Scripts Don’t Have to End in .PHP

Author: Robert Plank

If you tweak your site to perform better in search rankings then you practice the science of Search Engine Optimization (SEO). It’s possible to start using PHP scripts on your site without losing that high ranking of yours.

You’ve probably noticed your site rise and fall in search engine rankings quite a bit. That’s just how it goes since search engines such as Google like to change their algorithms around.

If one day you decide to rename all the files on your site you can be sure your Google listing will moved off page 1 of your target search keyword onto the back-listings of page 67 and beyond.

When you rename a file on your site, and another site links to that file, anyone coming to your site thru that particular link will get an error. When a search engine crawler sees this, it decides your site and decides either to lower your ranking or delete the URL from its search results entirely.

Search engines don’t want to send their visitors to Not-Found pages… makes sense, doesn’t it?

Okay, so let’s say you don’t want to have a ton of broken links across your site, which will cause you to drop in the search results, but you want to tinker with PHP a little bit.

There’s an easy fix for that. You can actually name your PHP scripts so that they end in .htm or .html, and have them run as PHP scripts on your web server. So from the outside world it’ll look as if your site is full of “updated-by-hand” content.

All you have to do is add this line to your .htaccess file:

AddType application/x-httpd-php .html .htm

If you don’t have an .htaccess file, all you have to do is put that line of code up there into a new text file, save it as “.htaccess” (with the dot in front) then upload it to your web server.

As soon as you set this up, try going back to your site. Everything should look exactly the same, with the exception that your HTML pages are all now PHP-enabled.

So you could setup a simple script like the one here: http://www.jumpx.com/tutorials/1

… And put that on any HTML page of yours. It will work exactly the same as if the file ended in .php instead of .html. Neat, huh?

You could even go crazy and change that line of htaccess code to add in more weird file extensions, for example:

AddType application/x-httpd-php .html .htm .ezine

This would parse any page ending in .html, .htm, or .ezine as PHP. So you could name a file something crazy like “subscribe.ezine” and it would work as a PHP script, or in other words as an HTML file with PHP tags in any place you want them.

For thank you pages sometimes I like to make the extension .thanks or .order just to make it harder to guess.

If you wanted to go totally nuts, you could even put something like this in your .htaccess file:

DefaultType application/x-httpd-php

With that, any file without an extension (so if you named a file “download” instead of “download.php”) will be “assumed” to be a PHP file. Any unrecognized extension would default to PHP.

The reason I say you can go totally nuts with this is because now you can now name a file to something that isn’t already used — like site.blog, or form.feedback, subscriber.area or bonus.page.

About the author: Experienced PHP/JavaScript Tutor Solves 19 Of Your Most Frustrating Direct Response Sales Page Hang-Ups http://www.salespagetactics.com/Your_Clickbank_ID

(The above article may be copied as long as this resource box is included, You may rebrand the above URL with your Clickbank ID however)