REgexing URL perl

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

REgexing URL perl

Post by a94060 »

Hi,

Im pretty sure that this may have been answered like a million times but:

how can i match the URL https://XXXX/index.php to a perl regex?

This is what i have tried so far:

Code: Select all

#! /usr/bin/perl
use LWP::Simple;
my $ReferFrom = "$ENV{'HTTP_REFERER'}";
if ($ReferFrom =~ m/^http:\/\/www\.XXXX\.no\-ip\.info\/index.php/){
<!--#include VIRTUAL="place.cgi" --> 
}
else {
	print "You have reached here by accident.";
}
print $ReferFrom;
thanks anyone who helps :D
Last edited by a94060 on Mon Mar 30, 2015 9:08 pm, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

:?: Why do you need a regular expression to match a static string?

Code: Select all

if ( "https://avinash.no-ip.info/index.php" eq $ReferFrom ) {
	print("match");
}
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

oh yea 8O your right,i never did think of that,that will not match with https://XXXX.no-ip.info right? or anything else? If it doesnt(which i think so) then thank you. i just dont know perl well to do all this,i like being in php(even though i know the 2 have common stuff)

cheers :lol:


EDIT-Would i be able to

Code: Select all

if ( "https://XXXX.no-ip.info/index.php" eq $ReferFrom ||  $ReferFrom eq "https://XXXX.no-ip.info/index.php/cgi-bin/secret/nph-proxy.cgi") {
        print("match");
}
that would make sense right?[/syntax]
Last edited by a94060 on Mon Mar 30, 2015 9:08 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

did you try it?
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

well not yet,im not at home but 9 out of 10 times,i spend 5hours trying to do a simple thing and then it never works.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

a94060 wrote:well not yet,im not at home but 9 out of 10 times,i spend 5hours trying to do a simple thing and then it never works.
try it first, then post here
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

Well,i tried what i had in a script which was this :

Code: Select all

$ReferFrom = $ENV{HTTP_referer}; 
print $ReferFrom;
if ( "https://XXXX.no-ip.info/" eq $ReferFrom ||  $ReferFrom eq "https://XXXX.no-ip.info/cgi-bin/secret/nph-proxy.cgi") { 
#LOTS AND LOTS OF PERL CODE
}
else {
	print "YOu lose.";
        print $ReferFrom;
}
and i access it via https://XXXX.no-ip.info/cgi-bin/secret/nph-proxy.cgi and it still shows me You Lose.The referer also does not show up. Now what can i do?
Last edited by a94060 on Mon Mar 30, 2015 9:09 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

the http referrer isn't guaranteed to be sent.. it is an optional argument.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

so then how do i make it sent? doesnt php usually send the http referer?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

PHP has no reason to send such a header. The referrer header is for requests only.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

ok,so then the question would be: How will i be able to accomplish what i am trying to?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There's very little you can do the make sure the request is coming from a valid location. The only thing I've seen even come close is by setting some predictable or known session variable and cross match it with an allowance in a database record.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

is there a way that i can make my script send a mandatory header out? Also,i thought that php has the $_SERVER['HTTP_REFERER'] option in it? wouldnt that mean that it gets sent along between scripts even though it is not used?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It's not sent between scripts. The BROWSER sends it, if at all. Since it is an optional header, there are many systems that will remove it well before the server receives a request, and many browsers have settings to disable it as well. Do not under any circumstances rely on it existing or you will create a potentially horrible user experience.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

Would i be able to install this onto my perl interpreter?
http://search.cpan.org/~miyagawa/PHP-Se ... Session.pm
Could that do what im looking for?
Post Reply