Solved

User Name appears on all pages

Posted on 1997-12-05
20
332 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
Comment Utility
<input type=hidden name=user value=5678>
0
 
LVL 9

Author Comment

by:Rowby Goren
Comment Utility
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
Comment Utility
#!/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
 
LVL 9

Author Comment

by:Rowby Goren
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Expert Comment

by:twexperts
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
hmmm, looks good. I think twexperts deserves his points :-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
This article will show, step by step, how to integrate R code into a R Sweave document
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now