...

View Full Version : Header and Location



Unknown
05-09-2004, 06:25 PM
Hey,
I have google ads on my website and in the TOC it says I can't have them on registration pages. I'm trying to create a script where if the address bar contains the word register then the ads won't show here is what I have so far:

<?php

$urrl = header('Location:');
$urrlpos = strrpos($urrl,"register");


if ($urrlpos < 0 ) {
echo '<script type="text/javascript">';
echo 'google_ad_client = "a secret";';
echo 'google_ad_width = 728;';
echo 'google_ad_height = 90;';
echo 'google_ad_format = "728x90_as";';
echo 'google_ad_channel ="";';
echo 'google_color_border = "B4D0DC";';
echo 'google_color_bg = "ECF8FF";';
echo 'google_color_link = "0000CC";';
echo 'google_color_url = "008000";';
echo 'google_color_text = "6F6F6F";';
echo '</script>';

echo '<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>';

}

?>



How come its not working?!?!??!

raf
05-09-2004, 06:44 PM
How come its not working?!?!??!
Because your condition is
if (False < 0){ etc.
and because the first lime does a redirect to nothing
$urrl = header('Location:');

If you need to now if the filename contains 'register', then replace

$urrl = header('Location:');
$urrlpos = strrpos($urrl,"register");
if ($urrlpos < 0 ) {

by

if (!strpos($_SERVER['PHP_SELF'],'register')) {

Unknown
05-09-2004, 07:28 PM
That works. But I have another problem :P. It still won't work. Now it shows the ads on all pages even the register pages. (i'm using phpBB)

raf
05-09-2004, 08:22 PM
How come?
I just tryed it out by creating a file with this content


<?php
if (!strpos($_SERVER['PHP_SELF'],'register')) {
echo 'The pages name or virtual adress does not contain "register"';
}else{
echo 'The pages name or virtual adress does contain "register"';
}
?>

and then naming it testregister.php and loading it in the browser. Then renaming it to test.php an loading that in the browser. And as i expected, it worked just perfectly. So this code is perfectly capable of detecting "register" in an url (except for the domainname)

So maybe you copied it incorrectly or the rest of your code has some bug. But with the info you give, it's impossible to say.

Unknown
05-09-2004, 08:39 PM
Well the problem is prolly that I'm using phpBB and the only time I don't want it to show is when a person is registering. To get to the registering page a person clicks on a link and that link does this :
profile.php?mode=register...
So I don't know why its not working.

raf
05-09-2004, 08:52 PM
I already feared you'd not needed to only test against the script-adress, but also the querystring (hence i explicitily mentioned it). So if you also need to search the querystring, then it becomes

if ((!strpos($_SERVER['PHP_SELF'],'register')) and (!strpos($_SERVER['QUERY_STRING'],'register'))) {

but this means that a user could get rid of the adverts on every page by just adding it to the querystring...

SmArTaSs
05-09-2004, 09:28 PM
<?php
if(!strpos($_SERVER["REQUEST_URI"], "profile.php?mode=register")){
//show ads
}
?>

Unknown
05-10-2004, 03:34 AM
Thanks Matt... That worked fine

We miss you @ phpbb-host.org :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum