Domain Exclude
Hi there..
I'm trying to put together a script that will log referring domains. I want to be able to set a variable to exclude a list of domains.. example:
$nolog = "bob.com,bill.com,spankysue.com";
and have some way of saying to skip the logging process if it contains one of those names.. example skipping if spankysue.com or spankysue.com
The only way I can think of of doing this is if else and that seems pretty messy.. Is there a clean way that someone could show me?
Bane
° talkloud Network - Forums never smelled this good.
tmay posted this at 21:42 — 5th September 2001.
They have: 75 posts
Joined: Sep 2001
I'm assuming this is Perl? If you only need to search through it once, I'd stick them into an array and sift through them with a foreach statement:
@skip = qw/bob.com bill.com spankysue.com/;
$is_there = 0;
foreach $i (@skip) {
if ($i eq $domain_to_find) {
$is_there = 1;
last;
}
}
if ($is_there) { ...code not to log... }
-Troy May
PC Sympathy
Admin at HFT Online
Bane posted this at 21:44 — 5th September 2001.
They have: 3 posts
Joined: Sep 2001
I suppose I should have said with PHP Thanks for the assistance however
tmay posted this at 21:49 — 5th September 2001.
They have: 75 posts
Joined: Sep 2001
No problem. I don't know PHP though, sorry.
Good Luck!
Mark Hensler posted this at 01:30 — 6th September 2001.
He has: 4,048 posts
Joined: Aug 2000
Welcome to TWF, Bane!
I would use an array...
<?php
$dont_log = array(
\"bob.com\",with bob.com
\"bill.com\",
\"spankysue.com\"
);
if (!in_array($HTTP_REFERER, $dont_log) && !in_array(\"www.$HTTP_REFERER\",$dont_log)) {
//domain not found, log it
}
?>
You could even get more creative, and use regex..
<?php
$dont_log = array(
\"/([0-9a-zA-Z]*)bob.com$/i\"
\"/^([w\\.]*)bill.com$/\",
\"/spankysue.com/\"
);
foreach ($dont_log as $tmp) {
if (!preg_match($tmp,$HTTP_REFERER)) {
//domain not found, log it
}
}
?>
Docs: preg_match(), in_array()
Mark Hensler
If there is no answer on Google, then there is no question.
Bane posted this at 10:27 — 8th September 2001.
They have: 3 posts
Joined: Sep 2001
Thank you so much for your help! I am in your debt
Mark was nice enough to assist me and I'm happy to say my problem is not only solved but solved beyond my expectations Thank you both for your assisstance.
Bane
° talkloud Network - Forums never smelled this good.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.