22, November 2008

string comparsion - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: string comparsion
« previous next »
Pages: [1] Print

Author Topic: string comparsion  (Read 928 times)
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6439
39458 credits
Members referred : 374


It's time to use PHP5!


« on: Sep 04, 2006, 02:52:45 PM »

Hi,

I need to check an domain or sub-domain against a list of domain names like

blocked domain = domainname.com

domain to check = sub1.domainname.com or www.domainname.com Visit through proxy

I thought about string handling... but I don't get it for the moment... please point where do I have to start...


Last blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8249
42481 credits
Members referred : 3



« Reply #1 on: Sep 04, 2006, 02:55:42 PM »

If you can parse the domains for the tlds only, then you can use the in_array() function to search in the tlds.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6439
39458 credits
Members referred : 374


It's time to use PHP5!


« Reply #2 on: Sep 04, 2006, 03:00:13 PM »

that's what I have now:

Code:
<?php
$blacklisted
[] = "yoursite.com";
$ref_parts parse_url($_SERVER['HTTP_REFERER']);
if (in_array($ref_parts['host'], $blacklisted)) {
// do somthing
}

now it works fine for yoursite.com but no for sub.yoursite.com, I want to block the whole domain...


Last blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8249
42481 credits
Members referred : 3



« Reply #3 on: Sep 04, 2006, 03:05:46 PM »

That code will work this way too. The ['host'] key keeps the whole domain.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6439
39458 credits
Members referred : 374


It's time to use PHP5!


« Reply #4 on: Sep 04, 2006, 03:10:34 PM »

yes, but I want to have one blocked entry (domain.com)
but I want to check for all sub domains too

but only if there is no www in front of the blocked entry

the host variable can hold both www.domain.com Visit through proxy or only domain.com


Last blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8249
42481 credits
Members referred : 3



« Reply #5 on: Sep 04, 2006, 03:16:36 PM »

This way you will produce some overhead

You will have to strpos() foreach() $domain in the list Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6439
39458 credits
Members referred : 374


It's time to use PHP5!


« Reply #6 on: Sep 04, 2006, 04:18:38 PM »

I think thats the solution:
Code:
<?php
$blacklisted
[] = "domain.org";

function 
check_against_array($host) {
global $blacklisted;
if (in_array($host$blacklisted)) {
return true;
}
foreach ($blacklisted as $val) {
if ($val == substr($hoststrpos($host$val))) {
return true;
}
}
return false;
}

function 
test_black_listed($url) {
$full_url "http://".ltrim($url"http://");
$url_parts parse_url($full_url);
if (!empty($_SERVER['HTTP_REFERER'])) {
$ref_parts parse_url($_SERVER['HTTP_REFERER']);
return check_against_array($ref_parts['host']);
}
return check_against_array($url_parts['host']);
}

if (
test_black_listed("www.domain.org")) echo "got www.domain.org";
echo 
"<br>";
if (
test_black_listed("domain.org")) echo "and got domain.org";

Nick,
I think you are using a similar function with your referer spam script or not?


Last blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8249
42481 credits
Members referred : 3



« Reply #7 on: Sep 04, 2006, 04:22:13 PM »

I think you can replace this:

if ($val == substr($host, strpos($host, $val))) {
return true;
}

with

if ( !(strpos($host, $val) === false))
return true;

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6439
39458 credits
Members referred : 374


It's time to use PHP5!


« Reply #8 on: Sep 08, 2006, 02:55:50 PM »

I think you can replace this:

if ($val == substr($host, strpos($host, $val))) {
return true;
}

with

if ( !(strpos($host, $val) === false))
return true;

Right, it works the same, but is this much better/faster?


Last blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8249
42481 credits
Members referred : 3



« Reply #9 on: Sep 08, 2006, 03:07:58 PM »

Yeah it is much faster.

Try a benchmark to see.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6439
39458 credits
Members referred : 374


It's time to use PHP5!


« Reply #10 on: Sep 08, 2006, 05:08:55 PM »

OK thanks, I saw this function before but it's hard to understand as non-programmer Wink


Last blog : Just a better Internet portal provided by Google
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=3958
Tags : referer spam domains spam Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: string comparsion
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Nov 22, 2008, 07:39:22 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 37.734
Total Topics: 7.649
Total Members: 4.394
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: rdgoetz

23 Guests, 4 Users online :

15 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.