Click to See Complete Forum and Search --> : URL generates a $VARIABLE on HTML page?
pwharff
05-07-2004, 07:00 PM
How can I have someones full name displayed on an HTML page through the use of an URL having their name in it. That way I can have the webpage greet them, such as:
"Welcome, Paul Wharff" on the Web Page
By using some kind of URL like:
http://www.example.com/username=Paul%20Wharff
Using BASH or Perl is fine with me. Any idea's would help.
--Paul
bryan.6
05-07-2004, 07:33 PM
serch for CGI and perl. for what I understand, that's what you want.
i'm not going to reem you for not searching, because i can't stand it when people say something like that and i think, "i would have had better results if i would have known what to search for," but here's one of the first links on a google search for CGI perl:
http://stein.cshl.org/WWW/software/CGI/
so what you are trying to do, code like this would probably work:
#!/usr/local/bin/perl
use CGI qw(:standard);
$username = param("username");
print header;
print <<HTML;
<html>
<head><title>Example Title</title></head>
<body>
Hello, $username<br>
...
rest of html<br>
...
blah blah blah<br>
...
</body>
</html>
HTML;
by the way, i didn't test that code, so if somebody wants to confirm or deny that, that would be great.
pwharff
05-08-2004, 12:41 PM
Thanks for your help. I'm just barely learning Perl and don't know enough to get a certain deadline done. I hope to learn more real soon and maybe someday I'll be helping someone else.
I understand your current perl script, but how do I make this script get the variable $username from a URL. That way if the URL was something like this:
http://www.example.com/username=Paul%20Wharff
It would print Welcome Paul Wharff in the HTML page. I guess what I'm trying to say is, how would the URL look to include someones full name and have this data/variable "Paul Wharff" passed to the perl script?
pwharff
05-10-2004, 09:14 PM
FYI, I found this through Google and I think this might be exactly what I need:
http://www.webxpertz.net/faqs/jsfaq/passvars.php
Any ideas on how this might be easier? I've never really done any Java Script and am not sure if this is the most efficient way?
Also, I'm still not sure how to take the above code and have it get's its variable from the URL?
sharth
05-10-2004, 09:36 PM
http://www.example.com/?username=Paul%20Wharff
probably need that question mark in there.
pwharff
05-10-2004, 10:54 PM
Originally posted by sharth
http://www.example.com/?username=Paul%20Wharff
probably need that question mark in there.
Yeah, but how do I use that in-conjunction with the above mentioned perl script? BTW, when I run it, I get this:
Bareword found where operator expected at test.cgi line 22, near "EOF"
(Might be a runaway multi-line << string starting on line 9)
syntax error at test.cgi line 22, near "EOF"
Execution of test.cgi aborted due to compilation errors.
bryan.6
05-10-2004, 11:07 PM
try the second HTML without a semicolon. if that doesn't work, put the semicolon back, and try the first HTML without a semicolon. i wasn't sure about that part when i typed it up.
pwharff
05-11-2004, 12:13 AM
Originally posted by bryan.6
try the second HTML without a semicolon. if that doesn't work, put the semicolon back, and try the first HTML without a semicolon. i wasn't sure about that part when i typed it up.
Thank you soooo much!!!! It worked like a charm!
pwharff
05-11-2004, 01:15 AM
Actually I have one more question (sorry I'm usually just a shell scripter). I know that when I'm scripting in BASH, I redirect a variable to another file by doing this:
echo $username >> log
I thought I could be smart and try to figure it out on my own with perl, with this:
print $username >> log;
But I was wrong, all it does is prints "0" and never even redirects into the "log" file. Any help or thoughts?