herbal enlargement magna herbal penis size pill rx

just another regularban.info web blog

MEMBERS:

Reusing Code in Web Sites and Applications Part 1 - Using Include() and Require()

Reusing pieces of HTML code is a common way of making web sites (or web applications) more consistent, reliable, and more manageable. Even a small web site consisting of perhaps 20 or 30 web pages can benefit from reusing code for header and footer sections, for example. If the same header or footer is used across all the pages on the site, it makes sense to put the header and footer code in separate files, and then call those files to insert their contents where required.

PHP offers two statements that can be used for inserted the contents of one file inside another: include() and require(). These two statements are virtually identical, with the only real difference being that if require() fails, it gives a fatal error, whereas if include() fails it just gives a warning. For this reason I tend to use the include() statement as it just seems slightly more friendly.

So, to include the contents of a file called header.inc inside a web page called index.php, you would just need to insert the following line of code (wrapped in PHP opening and closing tags) inside index.php.

Include 'header.inc';

As PHP takes no notice of the extension used for the included file, you can use whatever extension you want to. Be careful though, if you put passwords inside an include file with a .inc extension, they will be visible. You can get around this by putting include files that contain sensitive information outside the document tree to prevent people from browsing to them.

In Part 2 we'll look at the use of functions when developing web sites and applications.

About the Author: John Dixon is a web developer working for http://www.MyQuestionsMatter, a company that helps users of the health service to ask the right questions in their dealings with health professionals. John is also interested in computer history, and maintains http://www.computernostalgia.net, a site dedicated to the history of the computer. John also provides web development services to large and small clients via his own company John Dixon Technology Limited.

 


Using Functions

Functions are used to perform a well defined task that is normally repeated at various places within a web site, web application, or other software application. The function sometimes needs certain information before performing its task, and sometimes returns a value to the calling page or program.

An example of how to use a simple function in PHP:

 function showMessage() {

echo "{$_SESSION["message"]}"; }

The above example shows a very simple function that displays the contents of a session variable called 'message'. The idea being that while a user is using a web site, etc, various messages are generated and stored in the 'message' session variable. Whenever the showMessage function is called, the contents of the session variable are displayed. So, for example, when the user logs on, you could display a message saying that they have done so. Likewise, when they log off, a different message could be displayed.

Calling a function

To call the showMessage function, you would just need to include the line:

showMessage()

in the web page (wrapped in php tags to distinguish it from normall HTML).

Passing values to a function

Often, a function requires one or more input values in order to perform its task. For example, take the following example that takes two numbers as input, and adds them together. The result is then returned to the calling web page or program.

function addNumbers($number1,$number2) {

$answer = $number1 + $number2;

return $answer; }

In the calling program we would have something similar to the following:

$number1 = "5";
$number2 = "6";
$sumOfNumbers = addNumbers($number1,$number2);
echo "$sumOfNumbers";

Obviously, in a real program you would not have the numbers hardcoded like this, but they would be obtained from user input or by some other means. Notice also that although the name of the returned variable is $answer, the calling program makes no reference to that. We could, if we wanted to, change the calling program to:

$answer = addNumbers($number1,$number2);
echo "$answer";

which might make things slightly easier to understand.

About the Author: John Dixon is a web developer working for My Health Questions Matter, a company that helps users of the health service to ask the right questions when discussing their medical condition with health professionals. John is also interested in computer history, and maintains http://www.computernostalgia.net, a site dedicated to the history of the computer. John also provides web development services to large and small clients via his own company John Dixon Technology Limited.

 


301 Redirects - When and How to Use Them

Just what is a 301 Redirect?

There seems to be a lot of confusion as to what to do when you move, delete, or want to redirect incoming web traffic from an 'old' web page to a 'new' web page. A 301 redirect is the most efficient method for web page redirection from an old web page to a new web page location. There is also some confusion as to how to handle the complete move or redirection from one web domain to another web domain. According to Google, "If you need to change the URL of a page as it is shown in search engine results, we recommended that you use a server-side 301 redirect instead."

How to Set Up a 301 Redirect

Depending on your web environment, there are several methods to set up a 301 redirect. A 301 redirect is not that hard to implement and it should preserve your search engine rankings for that particular page or web domain.

.htaccess 301 Redirection

The .htaccess file needs to be placed in the root directory of your old website. In this example, we are redirecting incoming web traffic from an old domain to a new domain.

Options +FollowSymLinks

RewriteEngine on

RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

The .htaccess file is the most common method used for 301 web site redirection.

PHP 301 Redirection

You would place this code in a file at the old location.

Header( "HTTP/1.1 301 Moved Permanently" );

Header( "Location: http://www.new_location.com" );?>

Of course with any code, you will want to test this.

IIS 301 Redirection

  • In Internet Services Manager, you need to right click on the file or folder you wish to redirect
  • Select the radio button titled "a redirection to a URL".
  • Enter the redirection web page
  • Check "The exact URL entered above" and the "A permanent redirection for this resource"
  • Click on 'Apply'

That is all there is to it.

There are other methods in addition to set up a 301 redirection which include coding for ASP, ASP.NET, Java, CGI, Cold Fusion and Ruby on Rails. The above are the most common that I've encountered. When set up correctly, a 301 redirect will preserve your search engine rankings when it is necessary to move files around or switch, or consolidate, domain names.

Jason Perry

Two great SEO tools which can help track the success of your web site are Web Position Gold 4 and Hits Link. Both which you can try for free.

 


Pages 
* About

Archives
    * February 2008
    * January 2008

Categories:
* Uncategorized

Last Updated:

regularban.info is proudly powered by WordPress MU running on  regularban.info.
Create a new blog and join in the fun!
Entries (RSS) and Comments (RSS).