Gossamer Forum
Home : General : Perl Programming :

ID Referal

Quote Reply
ID Referal
I'm making a referal program and have everything done except one thing doesn't work. I wanted to store the number after "ID=" in the url, so I put this in the script:

$ENV{'QUERY_STRING'} =~ /ID=(.+)$/;
$id = $1;

and then I mailed $id to me.
the e-mail worked but it didn't e-mail me the info. Is that the right script to write? If not, what is?
Quote Reply
Re: ID Referal In reply to
I would use something like:

if ($ENV{'QUERY_STRING'} =~ /ID=(.+)/) {
$id = $1;
}
else {
$id = 'NOT DEFINED!';
}

That way in your mail you can see what's going on.

Hope that helps,

Alex
Quote Reply
Re: ID Referal In reply to
I put in what you said, and got the message "Not Defined" for the ID. What could be wrong? Also, the script only works in IE, not netscape for some reason. Can you help? I will e-mail you a copy of the script.
Quote Reply
Re: ID Referal In reply to
I am using cgi-lib.pl
If you want to see the script, I will e-mail it to you.
Quote Reply
Re: ID Referal In reply to
Your pattern matching isn't probably up to speed. From what I can tell, you probably should change the match to something like:

/ID=[/s]+/

Personally, I would suggest that you use cgi.pm or cgi-lib.pl to do the parsing of the data for you, then simply assign $id to the value from the module's parse:

use CGI;

$query = new CGI;
$id = $query->param('ID');

This is much easier than doing all the parsing yourself, and its the reason why Perl is so popular. Most of what you can imagine doing has already been done, and is available for free for you to use.

Hope this helps, if you don't have access to CGI.pm on your server (for whatever reason) use cgi-lib.pl, it does about the same types of things, just in a different method.



------------------
Fred Hirsch
Web Consultant & Programmer