Hi,
I need to hide the login screen of my web site whenever a customer has logged in..It should be done with javascript right??
Any suggestions?? Can someone help me to do this??
Thanks....:)
Hi,
I need to hide the login screen of my web site whenever a customer has logged in..It should be done with javascript right??
Any suggestions?? Can someone help me to do this??
Thanks....:)
Or you just have a different site layout depending on if he's logged in or not, this is done by having a simple if-statement on the session variable. The way you describe it must the login procedure be done with AJAX which often isn't needed.
Can you please describe me how to do it with the if statement on the session variable..
It would be great since im really new to web developing...
Thanks alot...
Hopefully you are working with PHP on the server since it's the only server language I know except Java which I never use for websites x)
Either you redirect the user to another page like facebook have done. They have a login page and when you are logged in you get redirected to your profile's "home"-page. So at the end of the login script, simply put:
header("location: userIsLoggedIn.php");
Or if you do it by just removing the login-box:
if ($_SESSION['login']){ //If the session variable "login" is true...
//load this content
}
else { //If the user isn't logged in yet
//Show the login-box
}
I hope that will get you on your way :)
Can we straight away use like in the index page,
if ($_SESSION['login']){ //If the session variable "login" is true...
//load this content
}
or do we need to create a session variable called "login" before somewhere else??
It must be done in your login-script. When the user submits the information in the login-form the information must be sent to a script where the info is verified with a corresponding entry in your database. If it is, you set $_SESSION=true otherwise keep it unset. If you don't know how to do this you can see an example at this site:
http://www.phpeasystep.com/phptu/6.html
On second thought does that script look a bit old :) read there how you create the login-form then use this script for login-verification:
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
if (isset($_POST['login_form'])){ //First check if the login-form has been submitted at all
$username = mysql_real_escape_string($_POST['username']);
$password = sha1(mysql_real_escape_string($_POST['password']); //Hash the password with SHA1, this is more secure than MD5. But this also means that the database column for passwords must also be hashed with SHA1.
$result = mysql_query("SELECT * WHERE username='$username' AND password='$password'") or die(mysql_error());
if (mysql_num_rows($result) == 1){
$_SESSION['user'] = $username;
$_SESSION['login'] = true;
header("location: pageToViewWhenTheUserHasBeenLoggedIn.php");
}
else {
header("location: loginHasFailed.php");
}
}
I haven't actually tried this piece of code but it should work if you set all the variables and form-field names correctly. Let me know if you get somekind of error! :)
A logout script would look like this:
if (isset($_POST['logout')){
session_destroy();
}
I might as well write the code for the corresponding html login-form as well:
<form name="login_form" method="post" action="checklogin.php">
<table>
<tr>
<td>Username: </td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Login"></td>
</tr>
</table>
</form>
If I remember correctly then when you check if the correct form has been submitted in the beginning of the login verification is should be form name which is checked, if it doesn't work then try to check the submit name, because I can't remember exactly x)
Thanks alot...Ill try ...:)
If you get it to work, remember to mark the thread as solved :)
Hopefully you are working with PHP on the server since it's the only server language I know except Java which I never use for websites x)
Either you redirect the user to another page like facebook have done. They have a login page and when you are logged in you get redirected to your profile's "home"-page. So at the end of the login script, simply put:
header("location: userIsLoggedIn.php");
Or if you do it by just removing the login-box:
if ($_SESSION['login']){ //If the session variable "login" is true... //load this content } else { //If the user isn't logged in yet //Show the login-box }
I hope that will get you on your way :)
redirecting to another page works fine...:)
but i need to remove the login box and direct to the index page itself...How should I do it..If you dont mind can you please tell me that too...In your post you have put a comment saying "load this content"..I need to know how to load that needed content after loging...Please help me..:)
redirecting to another page works fine...:)
but i need to remove the login box and direct to the index page itself...How should I do it..
If you dont mind can you please tell me that too...In your post you have put a comment saying "load this content"..I need to know how to load that needed content after loging...Please help me..
You simply echo the html content which should be there.
if ($_SESSION['login']){ //If the session variable "login" is true...
echo '<p> you are logged in!</p>';
}
else { //If the user isn't logged in yet
echo '<form name="login_form" method="post" action="checklogin.php">
<table>
<tr>
<td>Username: </td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Login"></td>
</tr>
</table>
</form>';
}
To make it easier to edit the content you can include separate files instead which contains what should be shown:
if ($_SESSION['login']){ //If the session variable "login" is true...
include "loginForm.php";
}
else { //If the user isn't logged in yet
include "userLoggedIn.php";
}
Hope it'll work!
Heyy Thanks a lot for helping me..Yeah it works fine...:)
Great :) good luck!
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.