Wardy_7 Posted December 27, 2012 Share Posted December 27, 2012 (edited) 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 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 December 27, 2012 by Wardy_7 Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted December 27, 2012 Share Posted December 27, 2012 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. Quote Link to comment Share on other sites More sharing options...
Manixat Posted December 27, 2012 Share Posted December 27, 2012 I remember there was something like that back in the day, google profanity filter and look for plugins Quote Link to comment Share on other sites More sharing options...
Christian F. Posted December 27, 2012 Share Posted December 27, 2012 Just wrap the ads code in an IF test, and test against the "adult" keyword. It really is that simple. Quote Link to comment Share on other sites More sharing options...
Andy123 Posted December 27, 2012 Share Posted December 27, 2012 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. } Quote Link to comment Share on other sites More sharing options...
Wardy_7 Posted January 2, 2013 Author Share Posted January 2, 2013 (edited) 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 January 2, 2013 by Wardy_7 Quote Link to comment Share on other sites More sharing options...
Christian F. Posted January 2, 2013 Share Posted January 2, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.