CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Redirect script

 



keith2045
Deleted

Feb 20, 2001, 7:37 PM

Post #1 of 3 (232 views)
Redirect script Can't Post

I have been trying to make a redirection script where a user sign's up for an account (that is working) and then they pick up to 5 different sites to have the script redirect. Then they put that link in their homepage. (so it shows a different link every time they open their browser) I keep having problems when making the redirection script, so i was wondering if one of you could show me how you would do it. Here is the info.

I have a .userinfo file with this info in it
Their user name:email address:first site:second site:third site... (up to 5 sites)

I have been trying have the script search the file for the user name that they have which is stored in the query_string then it picks one of their links. Can someone help??? Please

Keith



rGeoffrey
User / Moderator

Feb 22, 2001, 11:01 PM

Post #2 of 3 (224 views)
Re: Redirect script [In reply to] Can't Post

I tested with a file called 'random.in' with this data...


Code
fred:fflintstone@slate.com:www.slashdot.org:www.perlguru.com:www.PlatypiVentures.com 
george:gjetson@spacely.com:www.justanotherperlhacker.org:news.perl.org:www.pm.org
homer:hsimpson@burns.com:www.perl.com:www.cpan.org:www.freshmeat.net

And here is the code...


Code
#These three variables need to be set by the programmer... 
my $user = 'george';
my $email = 'gjetson@spacely.com';
my $FILENAME = 'random.in';

print 'Location: http://', &Get_Link ($user, $email), "\n\n";

sub Get_Link
{
my ($user, $email) = @_;

open (DATA, $FILENAME) or die "Cannot read file $!";

local $/ = "$user:$email:";
my $line = <DATA>;

$/ = "\n";
$line = <DATA>;
chomp;

close DATA;

my @links = split (':', $line);

return ($links[ int (rand (scalar (@links))) ]);
}

To find the links I play with the input record separator $/ and set it to the value we expect at the beginning of the line we care about. That gets us all the data before the links we want. Then we reset $/ back to the default of "\n" and get the rest of the line and chomp off the new line.

And finally we convert the links to an array and grab one at random so we can print it for the browser.

Or if you don't know the email address yet you could use this variation but remember that the file will need to start with a blank line so the first user can be found...


Code
#These two variables need to be set by the programmer... 
my $user = 'george';
my $FILENAME = 'random.in';

print 'Location: http://', &Get_Link ($user), "\n\n";

sub Get_Link
{
my ($user) = @_;
my ($line, $email, @links);

open (DATA, $FILENAME) or die "Cannot read file $!";

local $/ = "\n$user:";
$line = <DATA>;

$/ = "\n";
$line = <DATA>;
chomp;

close DATA;

($email, @links) = split (':', $line);

return ($links[ int (rand (scalar (@links))) ]);
}

---
Sun Sep 9, 2001 - 1:46:40 GMT, a very special second in the epoch. How will you celebrate?


keith2045
Deleted

Feb 23, 2001, 2:09 PM

Post #3 of 3 (216 views)
Re: Redirect script [In reply to] Can't Post

Thank you it worked.
I changed 1 thing it was
my $user = "$ENV{'QUERY_STRING'}";

I also made a members area. And how can i tell the script who is logon. Like i want them able to update their information how do i tell the script their username? The logon method i am using is the basic where they go to http://www.mycashworld.com/members and a box pop's up asking for their user name and password

Thanks

Keith


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives