Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Thursday, April 30, 2009

Display copyright with the current year

To display copyright with the current year:
&copy; Copyright 2008 - <?php echo date("Y") ?>

Monday, August 18, 2008

9 ways to hide affiliate links

These codes are useful for hiding the affiliate links. However, please read the affiliate program terms of service, so that you won’t go against it.

For all except the last way (.htaccess redirect), create the respective file for each affiliate link with the code for the chosen redirect style. Replace ‘http://your-affiliate-link-goes-here’ with the URL of the affiliate link.

For example, if you choose to use the PHP redirect, first create a PHP file. Copy and paste the PHP redirect code into that file. Replace ‘http://your-affiliate-link-goes-here’ with the affiliate link URL.

Every time you want to link to the affiliate link, just link to that file.

You have to create new file for each affiliate link.

HTML redirect

<html>
<head>
<title>HTML Redirect</title>
<meta http-equiv="refresh" content="0;
url=http://your-affiliate-link-goes-here">
</head>
<body>
Please wait. Redirecting...
</body>
</html>


PHP redirect

<?php header("Location: http://your-affiliate-link-goes-here"); ?>


ASP redirect

<%@ Language=VBScript %>
<% Response.AddHeader "Location","http://your-affiliate-link-goes-here" %>


ASP.NET redirect

<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.AddHeader("Location","http://your-affiliate-link-goes-here");
}
</script>


Coldfusion redirect

<.cfheader name="Location" value="http://your-affiliate-link-goes-here">


JSP redirect

<% response.setHeader( "Location", "http://your-affiliate-link-goes-here" );
response.setHeader( "Connection", "close" ); %>


cgi Perl redirect

$q = new CGI; print $q->redirect("http://your-affiliate-link-goes-here");


Ruby on Rails redirect

def old_action redirect_to "http://your-affiliate-link-goes-here" end


Apache .htaccess on Linux

Add this code to the end of .htaccess file. Replace ‘http://your-affiliate-link-goes-here’ with the affiliate link URL. To have more than one affiliate link, just add another RewriteRule.
RewriteEngine on RewriteRule ^affliate.php$
http://your-affiliate-link-goes-here [R]

Wednesday, June 25, 2008

Nuffnang vs Advertlets at random

This tutorial will show on how to make Nuffnang and Advertlets ads to display at random (not at the same time on each page).

First you need to put this code in the header.php file.
<?php
global $x;
$x = rand(1,2);
?>
This code will generate a random number of 1 and 2, and then substitutes it to the global variable x.

Next, insert the nuffnang and advertlets inside the code below.
<?php
if ($GLOBALS['x'] == 1) { ?>
<!--nuffnang--> <?php } else {?>
<!--advertlets--> <?php } ?>
Now, just copy the code and paste it into the template, as many as desired.

The code will show one or more nuffnang or advertlets ads at random with a chances of 50%.

Saturday, June 14, 2008

Create a Rotating Ads

If you run more than one ads, but lack of space to put the ads, you can actually rotate the ads.

The code below will create a random number from 1 to 10. Since I want both ads to be shown with a probability of 50%, I put the condition if (x > 5). However, you can change this number.

<?php $x = rand(1,10); ?>
<?php if ($x > 5) { ?>

<!--your first ad code-->

<?php } else {?>

<!--your second ad code-->

<?php } ?>
You can read more about PHP rand() function here.