How to make a redirect using PHP?


Today we live in the website age where we see millions of websites coming up every day with some new goods and services that will help us in some way or the other. The dotcom industry has been flourishing since the advent of internet as this piece of technology has not only shrunk the world, it has also provided opportunities for those who have entrepreneurial skills but have very little money to invest. New entrepreneurs and other website owners develop their own business domain from where they do their business with less of investments.

These days more people prefer to use PHP websites rather than the normal HTML ones because it is very simple to use and does not need complex scripting and coding languages which may confuse those who are beginners in the field of cyberspace. One of the other reasons why PHP website are on demand is because it is an open source scripting language and available freely on many websites. PHP code is directly inserted into the HTML that makes up a website. Hence, when a visitor comes to the website, the code is executed in the background because PHP is a server side technology, the user does not need any special browser or plug-ins to see the PHP in action.

Normally, if you have a website and you are working with another affiliate program or any other website that you want to promote on your website or provide the link of that website on your website than using a redirect option will be the best one. However, you need to be thorough on how exactly to redirect your visitors to that another site or link in a smart way. Also, most of the affiliate sites provide you payments if visitors have visited their site from the link on your site hence you also need to set a track record of how many visitors were redirect from your site. Many a times the redirect link is very long and that would create doubt in the mind of visitors hence you need to shorten it well.

Basically you have to create a new php file that will contain the affiliate link and some additional code, save it with a unique name, and use the new file name when referring to that affiliate link.

1. Open Notepad or your favorite code editor
2. Type in the following code as you see it below, replacing the red text with your affiliate link.
<?php
$url = "http://affiliate.link.code";
Header("location:$url");
exit();
?>
3. Save the file as keywordxyz.php (you come up with a file name that makes sense)
4. Upload the new php file to your web server.
5. When linking to your affiliate link, you can now use:
<a href=http://www.domain.com/keywordxyz.php>affiliate link</a>
Once you are done with redirecting a site or a link using PHP you will be able to organize your website better and you will not have to search for affiliate links everytime you need to look for them.

If you want to hide the referer URL you can use this redirect PHP code :
<?php
$url = "http://affiliate.link.code";
header("Refresh: 0; URL= $url");
?>

This however doesn't work 100% of the times. Some browsers from Mac OS will still send the referer URL to the new website.



Posted by James on 2009-10-25 in the category " php "