Jump to content

How To Disable An Advert Displaying Based On Usesr Search Query


Wardy_7

Recommended Posts

Hi, I am after a bit of help with some coding please (obviously), I have done a bit of searching the internet but not found any solutions as yet but imagine it must be fairly simple :happy-04:

 

One of my sites has a page that gives users results to a query that they enter, however some users enter "adult" content in to their search which is fine however what I don't want is for advertising to show up when any adult content has been searched for.

 

The format of my results page URL is shown below

mysite.com/results.php?keyword=XYZ

 

Does anyone have any code that I can add to my site that if an "adult" keyword is entered then the advertising block (google adsence) on my site does not display on it (obviosuly I know I will have to compile an "adult" list of keywords I will need it to work for.

 

Thanks in advance for any help :)

Edited by Wardy_7
Link to comment
Share on other sites

Unfortunately no-one will just create this for you.

 

Give it a go yourself and write some code, if it doesn't work then come back and we'll do our best to help out.

 

If you don't want to give it a go yourself, then you should post in the PHP Freelancing section and pay someone to complete this for you.

Link to comment
Share on other sites

Ideally, you would store the keywords in a database and use LIKE in your database query. I will just give you some quick PHP code to get you started.

 


$no_ads_keywords = array('keyword1', 'keyword2', 'keyword3');
$searched_keyword = $_GET['keyword'];

if (!in_array($searched_keyword, $no_ads_keywords)) { ?>
<!-- The keyword is OK; show advertisement here (paste Google AdSense HTML code). -->
<?php }

else {
// Adult keyword. Don't show advertisement. You don't even need this else branch.
}

Link to comment
Share on other sites

Ideally, you would store the keywords in a database and use LIKE in your database query. I will just give you some quick PHP code to get you started.

 


$no_ads_keywords = array('keyword1', 'keyword2', 'keyword3');
$searched_keyword = $_GET['keyword'];

if (!in_array($searched_keyword, $no_ads_keywords)) { ?>
<!-- The keyword is OK; show advertisement here (paste Google AdSense HTML code). -->
<?php }

else {
// Adult keyword. Don't show advertisement. You don't even need this else branch.
}

Hi guys, thanks for all the replies, they were great (sorry for my slowness to reply too, I was lazy over the Christmas time), hope you all have a great New Year! :)

I have the code now looking like this (naughty words changed)

$domain = $url;
$no_ads_keywords = array(naughtyword1, naughtyword2, naughtyword3);
if (!in_array($domain, $no_ads_keywords)) {
echo 'Advert Code';

I have been trying to add in LIKE in the array but not having any luck, is this possible to do without having to go down the MYSQL route with it?

I've been trying along these lines but I don't think it's possible to do:

if (!in_array($domain, LIKE '%$no_ads_keywords%'

The reason being just because for example is one of the naughty words is "sex" then the term "sexy" will still be classed OK currently so I was after adding in the LIKE bit to help just clear up a few extra stray ones :)

Edited by Wardy_7
Link to comment
Share on other sites

LIKE is a MySQL keyword, and has nothing to do with PHP. So if you want to use that keyword especially, then you have to use MySQL.

That said, there are other methods you can use in PHP. By reading through the PHP manual sections for arrays and strings you should be able to find at least two methods which should suit you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.