3 ms·
Assuming he uses Apache, why not just use a RewriteCond for that referrer and redirect to such a page? Executing that regex on every page is a performance hit,
by erlanger 18y ago
Assuming he uses Apache, why not just use a RewriteCond for that referrer and redirect to such a page? Executing that regex on every page is a performance hit, and generally I prefer to use Apache for stuff like this.
If you do use the supplied PHP code on your website, I recommend using strpos() or strstr() instead of preg_match().
- tjogin 18y agoMaybe he knows what kind of performance margins he has.
- erlanger 18y agoWhat do you mean by that? At the very least, most PHP devs know that strpos/strstr are much, much faster than a regular expression.
- cakeface 18y agoUnless page load times are affecting your browsing experience, why bother optimizing when a regular expression is so clear and simple.
- erlanger 18y agoYou know what, you're right. I was thinking of something like: if (strpos('http://digg.com/', $_SERVER['HTTP_REFERER'])) header('Location: whateverPage'); But that would block all traffic from Digg, including links in comments, etc. To perform the same check as the regex would require much more code. However, I stand by my Apache recommendation as the best option.
- narag 18y agoDidn't Apache use regular expresions for mod_rewrite?
- erlanger 18y agoYes, but I've never heard of RewriteConds/Rules affecting scalability. It's common knowledge to only use preg_match, etc. in PHP if you're performing a very complex search. Of course, this is not a huge deal, but I feel that if you're advising others to use such a simple piece of code, it should be as perfect as possible.