Page 1 of 1
REgexing URL perl
Posted: Sat Nov 25, 2006 8:55 pm
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

Posted: Sat Nov 25, 2006 9:53 pm
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");
}
Posted: Sun Nov 26, 2006 7:09 am
by a94060
oh yea

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
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]
Posted: Sun Nov 26, 2006 11:29 am
by John Cartwright
did you try it?
Posted: Sun Nov 26, 2006 1:35 pm
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.
Posted: Sun Nov 26, 2006 1:44 pm
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
Posted: Sun Nov 26, 2006 8:12 pm
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?
Posted: Mon Nov 27, 2006 12:11 am
by John Cartwright
the http referrer isn't guaranteed to be sent.. it is an optional argument.
Posted: Mon Nov 27, 2006 5:08 am
by a94060
so then how do i make it sent? doesnt php usually send the http referer?
Posted: Mon Nov 27, 2006 1:36 pm
by feyd
PHP has no reason to send such a header. The referrer header is for requests only.
Posted: Mon Nov 27, 2006 2:22 pm
by a94060
ok,so then the question would be: How will i be able to accomplish what i am trying to?
Posted: Mon Nov 27, 2006 2:26 pm
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.
Posted: Mon Nov 27, 2006 2:32 pm
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?
Posted: Mon Nov 27, 2006 2:34 pm
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.
Posted: Mon Nov 27, 2006 2:43 pm
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?