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
 
seems like you are looking for a javascript solution (which seems to be inherently insecure). Thus you are better off consulting the gurus in the javascript forum (Forum 216)
 
not according to your question.

what feherke says (and which is of course correct) is that you need to do this kind of thing server side not client side.

so you need to rethink your architecture and then try out some php coding. if you need help on php stuff post back in due course telling us what you have done and where you are stuck.
 
i would have no idea where to begin there, Oss6 (omni site secure) is something that i use to just manage my users.
I had hoped i could have this work but i would not be able to do it from scratch myself!

I thought it would be quite simple: Depending on the users login state 1 or 0 (which works by the way!) Display a or be:

If "1" display "Welcome username"

If "0" display "FORM"

 
but where is the state known?

i counsel against relying on a bit of software that you do not understand to manage your security
 
as for the software, its not really to secure anything or anything to worry about anyway, its just a way to manage my users
 
We do not know what that script does. You have not posted the code.

I suspect that this is not the right forum for you. A certain level of general expertise is assumed in forums for IT professionals. It may well be that you will get better answers at answers.com or by emoting someone through vworker or similar.
At its simplest you can use a php conditional like this

Code:
if ($condition): 
Echo 'some text';
Else:
Echo 'some other text';
Endif;
there is no reason why the text echoed cannot be HTML XML JavaScript or any other arbitrary string
 
its true that i know little to no code but i am quick to learn and have done very well so far!

Let me try to clear this up

This part clocks the user logging in and changes between 0 and 1


Code:
  __ossIsLoggedIn = 0;


This part checks /oss6/users/is_logged.php for said 0 or 1.

If 1, it welcomes the user
If 0, it asks the guest to register

Code:
<script src="[URL unfurl="true"]http://www.mysite.com/oss6/users/is_logged.php"></script>[/URL]
    <script>
if (__ossIsLoggedIn == 1) {
 document.write('hello '+__ossusername +', welcome back!<a href="[URL unfurl="true"]http://www.mysite.com/oss6/users/index.php?logoutOSS=1">-Logout</a>[/URL] ' );
}else{
 document.write('Welcome Guest, please Log In Or <a href="[URL unfurl="true"]http://www.mysite.com/sign">REGISTER</a>');[/URL]
}
  </script>



I want to replace the test "Welcome Guest, Please login or register" with a login form eg below:

Code:
<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" >
<img src="[URL unfurl="true"]http://www.realeducatorsonline.com/images/loginIcon.gif"[/URL] 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>


Individually all this code works! The problem occurs when i try to incorporate the two.

Thank you for your code but i understand that, what i cant do is add the form to it!
 
Aha! Sorted! Thanks to Vacunita (JS Forum)!

I knew it was fairly straight forward.


Code:
 <script src="[URL unfurl="true"]http://www.mysite.com/oss6/users/is_logged.php"></script>[/URL]
    <script>
if (__ossIsLoggedIn == 1) {
 document.write('hello '+__ossusername +', welcome back to Temp!<a href="[URL unfurl="true"]http://www.mysite.com/oss6/users/index.php?logoutOSS=1">-Logout</a>[/URL] ' );
}else{
 document.write('<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" >');
document.write('<img src="[URL unfurl="true"]http://www.mysite2.com/images/loginIcon.gif"[/URL] width="25" height="29" /></span> &nbsp;&nbsp;&nbsp;&nbsp;');
document.write('<label>Username</label>');
      document.write('<input name="username" type="text" id="f_username" />');
      document.write('<label>Password</label>');
      document.write('<input name="password" type="password" id="f_password" />');
      document.write('<input name="login" type="submit" id="LoginButton" value="login" title="Login" class="_test" />');
    document.write('</form>');}
  </script>
 
To all future readers: DO NOT use JavaScript or any client side method to secure your site, authenticate your users or authorize their activity. JavaScript provides no security layer over which you may exercise control.

The methodology discussed by the poster in this thread should not be used for any purpose other than to experiment with why it is a bad idea.

All security, authentication and authorization should only ever take place within a domain where the credentials provider has end-end control.
 
Just to clarify, that's what I said in the Js forum. But since all the TC needed was management rather than security it was an option. Not a good one though.



----------------------------------
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.
 
Hi Phil, I saw that in the other thread but was concerned that future readers in this forum might not get the full story.
 
Understandably so Justin.

----------------------------------
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top