Regex question..

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

Post Reply
User avatar
Gonik
Forum Newbie
Posts: 19
Joined: Fri Aug 30, 2002 7:39 am
Location: Somewhere Around Nothing

Regex question..

Post by Gonik »

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 :)
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Hmmm

Post by neophyte »

Code a switch for each of the four possible scenarios.....?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

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
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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&#1111;'HTTP_REFERER'])
or similar..
User avatar
Gonik
Forum Newbie
Posts: 19
Joined: Fri Aug 30, 2002 7:39 am
Location: Somewhere Around Nothing

Post by Gonik »

thanx, i'll try all of them and i'l get back to you
Post Reply