Solved

User Name appears on all pages

Posted on 1997-12-05
20
339 Views
Last Modified: 2013-12-25
I *think* this is a CGI question.  From some responses I received on newsgroups, it can't be done in Java or in regular html.

I've seen some sites where after the user enters their name in a form then their name appears (nicely formatted) at the top of various subsequent pages.

Well, here's what "I" need.

The scenereo:

1.  The person arrives at index.htm.  They are prompted for a five digit number.  The person enters "1234".  This sends the person to 1234.htm   But at the same time, I need the numbers "1234" to be stored so that later, the numbers "1234" can appear anywhere on any subsequent page, anywhere I want them to.  

2.  Just to make sure my request is clear, when another person later arrives at index.htm, and they enter THEIR passnumber, which is "5678", they are sent to "5678.htm", and at the same time the number "5678" is stored, so it can be used on subsequent pages, anywhere I want them to.  

Perhaps a cookie is involved, but there is no need for the cookie to remember the person's visit past once they leave the site.

Again, no other imput from the person other than those four numbers.  No user name.  Just those four numbers.

Thanks for any thoughts, suggestions -- and solutions!


Rowby
0
Comment
Question by:Rowby Goren
  • 9
  • 6
  • 3
  • +2
20 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1831505
<input type=hidden name=user value=5678>
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 1831506
Okay  That looks easy enough!  But I'm not quite sure how to impliment it.  I don't know anyting about CGI.  For example, how do I then get that 1234 to pop up on a subsequent page?   Is there some kind of an anchor I place?

And will you solution work on all the usual servers?  I am using TABnet and can I simply show them your answer -- and then they can tell me if it will work on their system.  In other words, will they understand your rather "brief" answer and give me a "yes" I can use it on their server.  (I hope I am making myself clear!)

THanks!
0
 
LVL 84

Expert Comment

by:ozo
ID: 1831507
#!/usr/bin/perl
use CGI qw(:standard);
print header;
if( param('user') ){
        param('page',$page = param('page')+1);
        print start_html("Page $page");
        print h1("You are number ".param('user')),
          start_form,
          hidden(-name=>'user'),
          hidden(-name=>'page'),
          submit(-name=>'next page'),
          end_form;
}else{
        print start_html('Title'),
          start_form,"What's your number?",textfield('user'), p,
          submit, end_form;
}
print end_html;

0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 9

Author Comment

by:Rowby Goren
ID: 1831508
Well I don't know CGI but looking at your response, I guess that answers my question.

I will forward your answer to my provider, and, if they respond positively I will award you the points!

In the meantime, if you feel you need to further respond to the question, don't hesitate.

I'll send the response to them Saturday!

By the way, just to make sure, will the script you provided also take the person "1234", when he pushes the submit button, to page "1234.htm" at the same time as it is storing the number 1234 for later use?  
0
 
LVL 84

Expert Comment

by:ozo
ID: 1831509
Actually, it takes the person back to the same cgi prog, since it wants to keep writing
<input type=hidden name=user value=1234>
on all subsequent pages.
You might have done something like

if( param('user') ){
       if( open(HTML,"<".param('user').".htm") ){
                print <HTML>;
       }else{        
                print("Can't open ".param('user').".htm because $!");
       }
}else{
..etc...
}

With the assumption that 1234.htm will contain
<input type=hidden name=user value=1234>

0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 1831510
Okay I guess you did it!  And I will provide all of your replies to my ISP.

One more thing.  (Have I gone to the well once too often).  What if the person enters a number which does NOT correspond to any of my "X.htm" pages.  For example if they arrive at index.htm and they enter  "2134" and there is NO "2134.htm" page.  I would like them to be sent to "error.htm".

Can you add that code to your CGI code.  And to show you how I appreciate your continued help, I have just increased the points to....149!

Regards,


Rowby
0
 
LVL 1

Expert Comment

by:twexperts
ID: 1831511
Well, rather than using Perl, you could actually use JavaScript, What you would do is simply set up a single frame document the parent would be hidden behind a child of width 100% within the parent you would have a variable named something like name=0;
Then when the user types in their login/password you can set this variable (name) to their specific number, then you can reference this number in any of your normal html pages by referencing the variable in the following way:
<ScriptLanguage="JavaScript"><!--
document.write(parent.name)
// --></SCRIPT>
which will print the number exactly as if you had just typed the number into the html document.
Much easier, and server efficient than using a CGI script for doing something like this...
JS can also be coded to detect when a page does not exist.
Hope this provides an alternative answer, I'll post up the
main source that you need to acomplish all of this if you find this as an acceptable answer.
Robin (twexperts)
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 1831512
Well that sounds interesting!

And because I don't understand everything you're saying, please let me make sure that your solution will handle all of my needs.

Scenereo:

User 1234 arrives at index.html

User types in 1234 into an imput box and then clicks on a submit button.

Two things happen:
1 -- the user is taken to 1234.html
2 -- the number 1234 (and, now that I think about it, possibly his name...if that is no problem -- but please, the user would only type in 1234 -- and somehow there would be an easily updatable external "database" or text file which would associate 1234 with the following data which would be outputted onto the any page I desire: "John Doe, Member 1234". -- but if that complicates things too much, then the inclusion of the name is not absolutely necessary.)

Now, one more thing.  And I don't think it changes anything.  I would not necessarily want his number/name on every page.  Only on certain pages.  And, it would be nice if I could position that name at any point on that page, and also nice if I could select the font size and color.  Looking over your solution, it appears you have provided for all of this.

Is that too much of a request?!


Thanks!

Rowby

0
 
LVL 1

Expert Comment

by:maholt
ID: 1831513
To give a more exact answer.  Could you give the web server and hardware platform you are using?
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 1831514
I have forwarded your question to Tabnet's tech support department.  While waiting for their response, the following may or may not help. It is from tabhet (www.tabnet.com)'s FAQ regarding CGI scripts:

*******************************************************
"With a Virtual Server account you have full use of the Operating System and can run CGI connecting to: server-side includes, Perl, C, and C++. You can create your own  CGI-BIN and run your own CGI programs."
********************************************************

I know nada regarding Perl, C, C++ CGI or Unix.  But perhaps the above gives you a clue!  I can tell you this, I am not running Front Page.

Thanks,


Rowby
0
 
LVL 1

Expert Comment

by:twexperts
ID: 1831515
This is what I can do for you....
> 1 -- the user is taken to 1234.html
No problem what so ever.
 
> 2 -- the number 1234 (and, now that I think about it, possibly his name...if that is no problem --
This can be done, however, how about having the user's information hidden within their associated html page, eg 1234.html would contain all detailed information about the user 1234 which would then be stored in a hidden frame once accessed?
Otherwise you would more than likely need a perl/cgi script which accesses a more secure database of user information.
Also note that using JavaScript would mean that about 3% of net users would not be able to use the page, however all the main browsers can use it (IE,NN etc etc.).
The font and size can be anything you want at all, even an image file if you want a picture of the person. And you can deside which pages do and do not display any or all of the information about the user.
Just on another thought, have you considered using cookies? If the user is only going to access the site from the same browser each time, then you could use cookies, that way the page can detect who the user is without the user even typing in anything at all, and so the user could be taken directly to their associated page. This is would be a low security solution, and
the user would have to have their browser to accept cookies, which most default to yes anyway...
Hope this gives you a bit more insight.
Robin(twexperts)

0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 1831516
I don't need a secure database for this site.  Security just isn't an issue with the people who I am dealing with.  So your java solution seems the way to go -- I guess!

ANd I like your suggestion about having all the information regarding the user on the associated hidden page.

I don't mind about losing the 3 percent who don't have Java. No problem there.

Because different people will be accessing the site from assorted computers, cookies would not work in this case.

Your solution sounds very exciting!  I can't wait to see it.

In case YOU need information regarding the web server and platform (I don't think you do, for your solution) I just spoke with my server, it's TABnet and they inform me that they are using an Intel Platform with BSDI Unix version 3.  It's Apache web server.  They think it's version  1.3.

Looking forward to seeing your solution!!


Rowby
0
 
LVL 1

Expert Comment

by:twexperts
ID: 1831517
Ok then, I'll manufacture the code to do all this and post up the code and a demo url for you to take a look at later tonight/tomorrow morning.
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 1831518
Great!  Thank you for what looks like a very creative solution to my question.  

I am looking forward to seeing your code and its results!

I appreciate your help -- as well as the help of the others who have commented on my Question.

Rowby Goren
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 1831519
To further respond to Maholt (and anyone else who needs this information, the following is a portion of Email I just received from Tabnet in response to Maholt's request for platform informaiton:

****************************************************
Hello,

We run Intel platforms with BSDI Unix Ver. 3 and Apache webserver (httpd)
Ver. 1.3

The sendmail is at:  /usr/sbin/sendmail   and perl is at:  /usr/bin/perl
or  /usr/bin/perl5

**********************************************


Rowby
0
 
LVL 1

Accepted Solution

by:
twexperts earned 140 total points
ID: 1831520
Ok here's the demo url, source, and instructions on how to implement it all.
demo url: http://www.twexperts.com/demo5
I've tested it on NN3,NN4, and IE4, works the same in all cases.
In the index.html file there are two variables:
validuser (=9999). Use this value as the maximum user number if you assign each user a number above the previous user.
Alternatively
validusr (=new Array(1000,1001,2050)). Use this array if you
assign each user a random login number, just add the number to
the end of the list, separated by commas. The script will
search this array to see if the number entered is valid.
I've also written a small function to make getting the info
a bit easier, look at the 3rd source file for implementation
of it.
That should be all, email me with any and all questions that you have: robin@twexperts.com
It's been a fun one,
Robin (twexperts)

Here's the source:
********index.html - main driving source
<HTML><TITLE>Demo - Remember Me!!!!</TITLE><HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
f_name="none";
s_name="none";
number=0;
address1="none";
address2="none";
city="none";
state="none";
zip="none";
defcolor="black";
defaultfont="Verdana";
defsize="7";
userpage="none";
validuser=9999;
validusr=new Array(1000,1001,2050);
function writeinfo(inforeq,font,size,color) {
t=document.frames[0].document;
   if(font=="") { font=defaultfont; }
   if(size=="") { size=defsize; }
   if(color=="") { color=defcolor; }
   t.write("<FONT SIZE="+size+" COLOR="+color+" FACE='"+
      font+"','"+defaultfont+"'>"+inforeq+"</FONT>");
}
function processid() {
   number=document.frames[0].document.form1.idnumber.value;
   if(number=="") {
   write_error();
   return;
   }
   if(number>validuser) {
   write_error();
   return;
   }
   validids=new String(validusr.join(","));
   if(validids.indexOf(number)==-1) {
   write_error();
   return;
   }
   userpage=number+".html";
   document.frames[0].document.location.href=userpage;
}
function write_error() {
   document.frames[0].document.open();
   document.frames[0].document.write("<HTML><HEAD></HEAD><BODY><CENTER>");
   document.frames[0].document.write("<H2>You Entered an invalid ID number</H2><BR>");
   document.frames[0].document.write("<A HREF='main.html'>Try again!</A>");
   document.frames[0].document.write("</CENTER></BODY></HEAD>");
}
// --></SCRIPT>
</HEAD>
<FRAMESET COLS="*,0" BORDER=0>
<FRAME SRC="main.html" NAME="MAIN">
</FRAMESET></HTML>

*******main.html - login page
<HTML><HEAD></HEAD><BODY>
<CENTER><P>
Beyond this point please do not hit your browsers reload, or back button.<BR>
<FORM ACTION="#" NAME="form1">
<TABLE WIDTH=370 BORDER=0 CELLSPACING=0 CELLPADDING=0 MARGIN=0>
<TR><TD><CENTER>Please input your ID number:</TD><TD><CENTER>
<INPUT TYPE="TEXT" SIZE=4 MAXLENGTH=4 NAME="idnumber"></TD><TD>&nbsp;&nbsp;
<INPUT TYPE="BUTTON" NAME="next" VALUE="---- Enter ----" onClick="parent.processid()">
</TD></TR></TABLE></FORM></P></CENTER></BODY></HTML>

******1000.html - Sample user's file page
<HTML><TITLE></TITLE><HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
parent.f_name="Robin";
parent.s_name="Fuller";
parent.address1="Some Apartment Number";
parent.address2="Some Street Adress";
parent.city="Minneapolis";
parent.state="Minnesota";
parent.zip="55403";
//  --></SCRIPT>
</HEAD><BODY>
Hello User
<SCRIPT LANGUAGE="JavaScript"><!--
parent.writeinfo(parent.number+" (","Helvetica","5","blue");
parent.writeinfo(parent.f_name+") ","Helvetica","5","blue");
//  --></SCRIPT>
How are you today?<BR>
<P>We have just sent an order to your address as listed below.</P>
(note the font, font size, and color freedom)<BR><P>
<SCRIPT LANGUAGE="JavaScript"><!--
parent.writeinfo(parent.f_name,"Helvetica","6","blue");
document.write(" ");
parent.writeinfo(parent.s_name,"Times","6","blue");
document.write("<BR>");
parent.writeinfo(parent.address1,"Times","4","black");
document.write(", ");
parent.writeinfo(parent.address2,"Helvetica","4","red");
document.write("<BR>");
parent.writeinfo(parent.city,"Times","4","green");
document.write("<BR>");
parent.writeinfo(parent.state,"Times","5","");
document.write("<BR>");
parent.writeinfo(parent.zip,"Helvetica","3","blue");
document.write("<BR>");
//  --></SCRIPT>
</P>
If this is not the correct address please send us an email at:
<A HREF="mailto:admin@somehost.com">admin@somehost.com.</A>
<HR>
<P>Just for demo purposes, you can also insert this information into
any generic page common to all users</P>
<A HREF="generic.html">Generic page link</A>
<BR>
<A HREF="main.html">Log on as a different user</A>
</BODY></HTML>


0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 1831521
Thanks for your solution, however I am
having a problem with a Java error message both
when trying to make it work at your url and when
trying to make it turn on my own at my test URL.

At your site it returns a Javascript error on line
41.

"Window.document.frames has no property indexed by
"0"."

I'm using Netscape 3.4 gold

Any thoughts?


Thanks, Rowby

P.S. For some reason, my email addressed to robin@twexperts.com was returned as undeliverable.
0
 
LVL 1

Expert Comment

by:twexperts
ID: 1831522
Strange,
try it again at my url, and press the web-button rather than the return key first. Thanks for the info on the email address, you should be able to send it to me now.
I'll do some more refining of it tonight, see if I can trim off the rough edges....
I'm sorry it didn't work for you, it really does work great...
0
 
LVL 1

Expert Comment

by:twexperts
ID: 1831523
Ok, got it fixed, and running properly for NN3 :)
only a minor change, in the index.html document replace all document.frames[0] with frames[0] that's all, silly mistake really. here's the updated url again:
http://www.twexperts.com/demo5/index.html
Valid user id's are 1000,1001,2050
Have fun,
Robin(twexperts)
0
 
LVL 5

Expert Comment

by:Christian_Wenz
ID: 1831524
hmmm, looks good. I think twexperts deserves his points :-)
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question