Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i display login form if user is not logged in?

Status
Not open for further replies.

dennisbrittv

Technical User
Jan 2, 2011
11
0
0
GB
Hi and thank you for looking at this!

I am trying to display a welcome note if the user is logged in and a login form if they are on a html page.

Now i know that this works:

<form action=" method="post" name="OSScLoginForm" class="search" id="OSScLoginForm" onSubmit="if (document.__ValJsLoaded) { return ValidateLoginEx();}else return true" >
<img src=" width="25" height="29" /></span> &nbsp;&nbsp;&nbsp;&nbsp;
<label>Username</label>
<input name="username" type="text" id="f_username" />
<label>Password</label>
<input name="password" type="password" id="f_password" />
<input name="login" type="submit" id="LoginButton" value="login" title="Login" class="_test" />
</form>
<script src=" <script>
if (__ossIsLoggedIn == 1) {
document.write('hello '+__ossusername +', welcome back!<a href=" ' );
}else{
document.write('Welcome Guest, please Log In Or <a href="}
</script>






But i want this to work:


<script src="<script>
if (__ossIsLoggedIn == 1) {
document.write('hello '+__ossfirstname+','+__osslastname+', your username is '+__ossusername +' !');
}else{
document.forms(<form action=" method="post" name="OSScLoginForm" class="search" id="OSScLoginForm" onSubmit="if (document.__ValJsLoaded) { return ValidateLoginEx();}else return true" >);
document.forms ('<img src=" width="25" height="29" />')
document.forms (<label>Username</label>)
document.forms (<input name="username" type="text" id="f_username" />)
document.forms (<label>Password</label>)
document.forms (<input name="password" type="password" id="f_password" />)
document.forms (<input name="login" type="submit" id="LoginButton" value="login" title="Login" class="_test" />)
document.forms (</form>)
}
</script>


Please help if you can. I want to display this on a html page.

Thank you
 
Hi

That is conceptually wrong. Do not involve client-side scripts in such things.

Including or not the login form should be done by the server-side script which generates the HTML document. As your site seems to be powered by PHP, ask in forum434 in case you need help on that.


Feherke.
 
If you don't require more protection as feherke explains you could do this in Js though its not something I'd suggest.

document.forms is an element collection, and can't really be used that way. document.write is what is used to output html which would be what you want.

Code:
document.[red]write[/red]([COLOR=white blue]'[/color]<form action="[URL unfurl="true"]http://www.mysite.com/oss6/users/login.php?ce=0&amp;group=58&amp;url=http://www.mysite.com/members/index.html&amp;clogin=0"[/URL] method="post" name="OSScLoginForm" class="search" id="OSScLoginForm" onSubmit="if (document.__ValJsLoaded) { return ValidateLoginEx();}else return true" >[COLOR=white blue]'[/color]);

Change all your document.form calls to document.write and make sure your quotes are correctly placed to wrap around the html you want to output.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Nice one!! I knew it would be simple enough! I did try that but it was my quotes that were off! Your a star!!

Thank You!

Just one last question; Why exactly is it advised i dont do it this way?

Thanks again!!!
 
Because its easily circumvented. There are many ways to alter your __ossIsLoggedIn variable to appear logged in.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
i see what your saying. Most of my users would have no use in such activity. As i said, im not really trying to secure anything, just member management.

Thank you again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top