Regarding this well-known quote, often attributed to Pedro Graca's famous
"26 May 2004 11:10:46 GMT" speech:
Boris ©avc wrote: I have a page and a sponsor. Every time a user click on a banner from our
sponsor their webpage is opened. I'd like to reward these users, but how to
check who clicked on a banner. I can't do anything on sponsor's webpage?
Instead of
<a href="http://sponsor.com/"><img src="sponsor.png"/></a>
do
<a href="sponsor.php?url=http://sponsor.com/"><img src="sponsor.png"/></a>
and in sponsor.php redirect to the sponsor page after updating your user
information, for example:
<?php //sponsor.php
$user_id = 0; // ir your code get it from where you have it stored
$sql = "update user set clicks=clicks+1 where id=$user_id";
// do sql
header('Location: ' . $_GET['url']);
// some browsers may not follow the redirect
exit('Redirected <a href="' . $_GET['url'] . '">here</a>');
?>
For a more robust solution, I'd recommend having some sort of table linking
individual banners or sponsors to their sites, be it an external MySQL
table or a simple hash array. Limiting the script to a finite number of
approved URLs it can redirect to will stop cross-site scripting attacks and
other illegitimate uses of your site's script.
http://us3.php.net/manual/en/language.types.array.php
<?php
// Remember! Nothing comes before the ?php tag, or the
// redirect won't work!
$my_home_page = "http://www.somewhereorother.com";
$banners = array(
"example1" => "http://www.example.com/",
"example2" => "http://www.example.com/superwebvalues",
"phpnet" => "http://www.php.net/"
);
// Set up a hash array with codenames => URLs
// (See
http://us3.php.net/manual/en/language.types.array.php )
if ($banners[$_GET['banner']]) { // if the banner they requested exists...
// (Do some MySQL or something HERE to increment the codename's counter)
// ...
// Then redirect to the proper page
// (See
http://us3.php.net/manual/en/function.header.php )
header("Location: " . $banners[$_GET['banner']]);
}
else {
// If there isn't a banner with that codename,
// just redirect to the homepage
header("Location: " . $my_home_page);
}
?>
--
-- Rudy Fleminger
--
sp@mmers.and.evil.ones.will.bow-down-to.us
(put "Hey!" in the Subject line for priority processing!)
--
http://www.pixelsaredead.com