PDA

View Full Version : PHP Stuff idk ;x



Jojee
11-27-2008, 09:06 PM
I'm using Toxic Goblin referrer script.

This is the code of the click.php:


if(isset($_REQUEST["id"]) || isset($_REQUEST["site"]))
{
include('config.php');
include($full_path.'functions.php');

$tgdb = mysql_connect($tgdbHost, $tgdbUser, $tgdbPass) or die(mysql_error());
mysql_select_db($tgdbName, $tgdb);

if(preg_match('!^[0-9]+$!', $_REQUEST["id"]))
{
$click_result = mysql_query("select hit_id, url from tg_ref_hits where hit_id='".$_REQUEST["id"]."'");
}
elseif(!empty($_REQUEST["site"]))
{
$url = addslashes($_REQUEST["site"]);
$click_result = mysql_query("select hit_id, url from tg_ref_hits where url='$url' order by hit_id desc limit 1");
}
else
{
$click_result = null;
}

$click = mysql_fetch_object($click_result);
if(is_object($click))
{
mysql_query("update tg_ref_hits set hits_out = hits_out+1 where hit_id = '".$click->hit_id."'");
$url = stripslashes($click->url);

$forward_result = mysql_query("select forward from tg_ref_approved where url = '$url'");
$forward_row = mysql_fetch_array($forward_result);
if ($forward_row['forward'] != "")
{
$url = $forward_row['forward'];
}
}
else
{
if (isset($_REQUEST["site"]))
{
$url = $_REQUEST["site"];
}
else
{
$url = &$_SERVER['SERVER_NAME'];
}
}
}
else
{
$url = &$_SERVER['SERVER_NAME'];
}

header("Location: http://$url");
exit;
?>

It works great - when you click out from my top links, it goes to where it's supposed to. Example:
Your Cute Design Resource ~ Neskaya.Net (http://neskaya.net)

But I have my top links section also in subdomains, and it tries to access subdomain.neskaya.net/click.php?id=whatever instead of neskaya.net/click.php?id=whatever, and then it doesn't work.
Example:
88x31 Cute Pixel Bunny Button Maker [88 x 31] (http://dressupgames.neskaya.net/88x31buttonmaker_bunny.php)

If you click under top links there, it doesn't work.

How do I fix the code so that it always goes to http://neskaya.net/referrers/click.php?id=whatev and doesn't include the subdomain?

Thanks :3

o_O
11-27-2008, 10:27 PM
Ok, basically, here's what's happening. neskaya.net and subdomain.neskaya.net use separate virtual hosts in the configuration of the webserver. Each virtual host has its own "DocumentRoot" directive, which means that / refers to a different folder on the server, depending on whether it's called from the subdomain or otherwise. Example:


NameVirtualHost *
<VirtualHost *>
ServerName "neskaya.net"
DocumentRoot "C:/htdocs/neskaya"
</VirtualHost>

<VirtualHost *>
ServerName "subdomain.neskaya.net"
DocumentRoot "C:/neskaya/subdomain"
</VirtualHost>

Let say you have a link with the href attribute: "/referrers/click.php". In the main site, the webserver will serve the file from C:/htdocs/neskaya, while in the subdomain it will try to serve from C:/neskaya/subdomain. I can think of a couple of solutions for the problem, though neither is particularly elegant.

The first and most obvious of the two is to include a full path in the href attribute of the links in the subdomain, i.e. have href="http://neskaya.net/referrers/click.php" in the problematic anchor tags. This way, you're disregarding the domain it comes from, but the potential drawback is that it makes it easier to be called from any domain. Why someone would want to do that is totally beyond me though and by looking at the current source, one can fairly easily figure out where the actual click.php file is hosted if they use their heads a little, so it's pretty much irrelevant. :p

The second solution is to write yourself a little redirect script and host it on the subdomain. You'd need to handle the referrer based on GET or POST variables and fairly heavily modify that referrer script, so it's probably not even worth it. :p

Jojee
11-28-2008, 12:46 AM
I want to do the first solution, but I don't know where to replace it at. xD Which part of the code should I be replacing with neskaya.net/referrers ? *.*

o_O
11-30-2008, 11:17 AM
In the PHP document which contains the code for the "Top links" section of your site you should change the href attribute of all of the links so that they point to neskaya.net/referrers/click.php?id=[id].

Jojee
12-01-2008, 09:50 AM
Oooh, it's in a different file, that makes so much more sense. xD I was trying to find it in this one and getting all confused. Fixed now! Thanks.