Jump to content

Login Form Help


jassikundi

Recommended Posts

hi everyone, I'm creating a login box on my home page to allow users to login without going to members page, in other words it displays on all pages. are there any tutorials on this? I've tried goggle but no luck :(

 

Here my original code used on the members page, could anyone point out what I would need to do?

 

[pre]<?

include("include/session.php")

/**

* User has already logged in, so display relavent links, including

* a link to the admin center if the user is an administrator.

*/

if($session->logged_in){

  echo "<h1>Logged In</h1>";

  echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"

      ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>]   "

      ."[<a href=\"useredit.php\">Edit Account</a>]   "

  ."[<a href=\"quote/quote.php\">Quote</a>]   "

  ."[<a href=\"../retrivequote.php\">Retrieve Quote</a>]   ";

      if($session->isAdmin()){

      echo "[<a href=\"admin/admin.php\">Admin Center</a>]   ";

  }

  echo "[<a href=\"process.php\">Logout</a>]<br><br>";

}

else{

?>

<h1>Login</h1>

<?

/**

* User not logged in, display the login form.

* If user has already tried to login, but errors were

* found, display the total number of errors.

* If errors occurred, they will be displayed.

*/

if($form->num_errors > 0){

  echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>";

}

?>

<form action="process.php" method="POST">

<table align="left" border="0" cellspacing="0" cellpadding="3">

<tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>

<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr>

<tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>>

<font size="2">Remember me next time     

<input type="hidden" name="sublogin" value="1">

<input type="submit" value="Login"></td></tr>

<tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr>

<tr><td colspan="2" align="left"><br>Not registered? <a href="register.php">Sign-Up!</a></td></tr>

</table>

</form>

 

<?

}[/pre]

 

Kind Regards

Jassi

Link to comment
Share on other sites

You'll need a login form...check it against the username and password...if it checks good...it redirects the user using header() to whateverpage.php all you have to do is set the session on the pages you want blocked from non members. Then create a logout.php and when logged in users click on that it kills the session so they're logged out.

 

Guessing that's what you want

Link to comment
Share on other sites

hi thanks yup thats what I want to do I have everything done already session page, logout page etc just unaware of how to redirect the user.

 

would I need to somehow use a code like this:

 

[pre]if($session->logged_in){

  if (([redirect] != "main.php"))

{

}

//redirects the user

header("Location:$_SESSION[redirect]");

}

else{[/pre]

 

I know that is incorrect but some1 show me the light :D

Link to comment
Share on other sites

If you want it to redirect you have to edit it with your required information, but it would look something like:

 

It depends too on if you want it to redirect to different locations. Like if you want members to get re-directed to one URL, and admin staff to get redirected to a different URL

 

witch($ROW['checkaccessleve']){

case 1:

#header("Location: /index.php");

echo "window.location = 'pilots/index.php';\n";

break;

 

case 2:

#header("Location: /admin/index.php");

 

I dont know if that will help, but thats my input, hard to give any advice - be more specific in what ya need. But basically do what the guy said above, verify the username and password in the db, and if correct re-direct to a different URL

Link to comment
Share on other sites

Hi thanks will give it ago, yeh the following code checks if the user is resisted and logs them into to view the following: I would like to remove the "echo "<h1>Logged In</h1>" and up to logout and insert the redirect there. I'll give your code a go. thanks.

 

[pre]<?

include("include/session.php")

/**

* User has already logged in, so display relavent links, including

* a link to the admin center if the user is an administrator.

*/

if($session->logged_in){

  echo "<h1>Logged In</h1>";

  echo "Welcome $session->username, you are logged in.

 

"

      ."[<a href=\"userinfo.php?user=$session->username\">My Account[/url]]   "

      ."[<a href=\"useredit.php\">Edit Account[/url]]   "

      ."[<a href=\"quote/quote.php\">Quote[/url]]   "

      ."[<a href=\"../retrivequote.php\">Retrieve Quote[/url]]   ";

        if($session->isAdmin()){

      echo "[<a href=\"admin/admin.php\">Admin Center[/url]]   ";

  }

  echo "[<a href=\"process.php\">Logout[/url]][/pre]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.