I would think that trying to get others to implement php for your links would not be a great idea, and a big hassel for most. I thought that maybe an inline frame may work because search engines would see that (however the links would come from your own domain).
Just have the users to edit the domain=ENTER_REFERRING_DOMAIN_HERE to domain=www.domain.com
HTML Code:
<iframe src="http://www.website.com/link.php?domain=ENTER_REFERRING_DOMAIN_HERE" width="100%" height="25" scrolling="no" frameborder="0">
<a href="http://www.website.com/">000</a>
</iframe>
I reconstructed your php script. I don't understand why you would use a random number id rather than using a incremented id value. It would stop having to require iterating finding a integer that was not being used, and the rows would be easily sorted in order as they were originally created.
PHP Code:
<?php $db = @mysql_connect('localhost', 'username', 'password') OR die('error connecting to db'); mysql_select_db('db_name', $db) OR die('error selecting the db'); // Set vars to be used: $domain = ''; $link_id = 0; // Check if domain was defined as a parameter: if (isset($_GET['domain']) AND preg_match('/^www\.[A-Z-_]+\.[A-Z]{2,}$/i', $_GET['domain'])) { $domain = strtolower($_GET['domain']); } // Check referrer if domain was not defined (used as a backup resource): if (!$domain AND isset($_SERVER['HTTP_REFERER']) AND !empty($_SERVER['HTTP_REFERER'])) { if (preg_match('@^.*(://)?(www\.[A-Z-_]+\.[A-Z]{2,})/.*$@i', $_SERVER['HTTP_REFERER'], $match)) { $domain = strtolower($match[2]); } } if ($domain) { // Check if referrer exists in the db: $db_query = mysql_query(" SELECT num FROM links WHERE page = '" . mysql_real_escape_string($domain) . "' "); if (mysql_num_rows($db_query) > 0) { // Link does exist: $db_result = mysql_fetch_array($db_query); $link_id = $db_result['num']; } else { // Link does not exist - create it: while (true) { srand(time()); $link_id = (rand()%99999)+1; $db_query = mysql_query(" SELECT COUNT(*) AS count FROM links WHERE num = $link_id "); $db_result = mysql_fetch_array($db_query); if (!$db_result['count']) { mysql_query(" INSERT INTO links (num, page) VALUES ($link_id, '" . mysql_real_escape_string($domain) . "') "); break; } } } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> </head> <body> <a href="http://www.website.com/<?php if ($domain) echo $link_id; ?>"><?php echo ($domain) ? $link_id : '000'; ?></a> </body> </html>
__________________
<mgraphic /> - I don't have a solution but I admire the problem.
Last edited by mgraphic; 05-14-2009 at 09:12 PM..
|