PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Gonik
Forum Newbie
Posts: 19 Joined: Fri Aug 30, 2002 7:39 am
Location: Somewhere Around Nothing
Post
by Gonik » Mon Oct 18, 2004 1:11 pm
hello ppl... I have a regex problem.
Let's say i want to match a specific string from the HTTP_REFERER var. I use this code:
Code: Select all
<?php
if(preg_match("/^(http:\/\/)www\.domain\.com\/new\/site\/disp/i", getenv("HTTP_REFERER")) {
// code to allow download goes here
}
?>
The pages that the above regex must match are:
so i want one regex to match all... But it doesn't work
any suggestions?
Thanx in advance,
Nick
neophyte
DevNet Resident
Posts: 1537 Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota
Post
by neophyte » Mon Oct 18, 2004 1:20 pm
Code a switch for each of the four possible scenarios.....?
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Mon Oct 18, 2004 1:30 pm
Maybe:
Code: Select all
if(preg_match("/^[htp\:\/]*www\.domain\.com\/new\/site\/disp[a-zA-Z0-9\.]*/i", getenv("HTTP_REFERER")) {
// code to allow download goes here
}
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Oct 18, 2004 1:32 pm
Word to the wise: don't bank on the variable being set.
As for your regex...
Code: Select all
preg_match('#^https?://(www\.)?domain\.com/new/site/disp\.(freeware|shareware|gamedemos|freewaregames)\.php$#i', $_SERVERї'HTTP_REFERER'])or similar..
Gonik
Forum Newbie
Posts: 19 Joined: Fri Aug 30, 2002 7:39 am
Location: Somewhere Around Nothing
Post
by Gonik » Tue Oct 19, 2004 8:39 am
thanx, i'll try all of them and i'l get back to you