52 Replies - 2436 Views - Last Post: 10 June 2010 - 08:11 AM
#1
Login Detection
Posted 04 June 2010 - 06:19 PM
If your not logged in. I want it to have two text boxes one for email and password. Then something telling you to register. If your logged in I want it to have three tabs saying "View Profile" "Edit Profile" "Log Out". I can code the login script and stuff I just don't know how to change the header depending on if your logged in or not. My website is http://envxsoftware.com/. Thanks in advance.
Replies To: Login Detection
#2
Re: Login Detection
Posted 04 June 2010 - 06:43 PM
VB.Terry, on 04 June 2010 - 05:19 PM, said:
If your not logged in. I want it to have two text boxes one for email and password. Then something telling you to register. If your logged in I want it to have three tabs saying "View Profile" "Edit Profile" "Log Out". I can code the login script and stuff I just don't know how to change the header depending on if your logged in or not. My website is http://envxsoftware.com/. Thanks in advance.
It depends how you do your login.
It is basicly :
if(isLoggedIn()) {
$extraHeaderContent = <<<EOD
<ul>
<li><a href="">View profile</a></li>
<li><a href="">Edit profile</a></li>
<li><a href="">Log out</a></li>
</ul>
EOD;
}
else {
$extraHeaderContent = <<<EOD
<form>
<!-- log in form -->
</form>
<a href="">Register</a>
EOD;
}
and in your header :
<?php print $extraHeaderContent; ?>
isLoggedIn maybe something like :
function isLoggedIn() {
if($_SESSION['logged_in'] === true)
return true;
return false;
}
This post has been edited by webpeater: 04 June 2010 - 06:46 PM
#3
Re: Login Detection
Posted 04 June 2010 - 06:49 PM
i'm having the same trouble with a similar application.
Please have a look at my site, which is a project for college: http://www.relativit...Zone/index.html
It's using $_SESSIONs to identify a login or new user
I've just posted the problem, so maybe there'll be feedback for the both of us.
george
#4
Re: Login Detection
Posted 04 June 2010 - 06:51 PM
basically just check if session is set. If session isset, "Show tabs", else , "show login box"
Here is my code from my dummy site.
<div id="login_box_content">
<?php
if (!isset($_SESSION['username'])){
include('includes/login_box.php');
}else{
echo "Welcome" . " " . $_SESSION['username'] . "<br />" ;
echo "Your last log in was" . " <br />" . $_SESSION['last_login'];
}
?>
</div>
May not be the most efficient way but it works for me.
#5
Re: Login Detection
Posted 04 June 2010 - 06:52 PM
georgehowell, on 04 June 2010 - 07:49 PM, said:
i'm having the same trouble with a similar application.
Please have a look at my site, which is a project for college: http://www.relativit...Zone/index.html
It's using $_SESSIONs to identify a login or new user
I've just posted the problem, so maybe there'll be feedback for the both of us.
george
If your wondering on how to keep a person logged in on every web page. Insert
session_start();which should work.
#6
Re: Login Detection
Posted 04 June 2010 - 06:52 PM
The method I'm using is a database logged in or out query.
$query = "SELECT * FROM {$dbprefix}members WHERE username = '$checkUser' AND disable = '0'";
So, if this returns true, the database would put on that member's row 1 for logged in.
$query = "UPDATE {$dbprefix}members SET lastlogin = '$time', loggedin = '1', ipnum = '$ip' WHERE username = '$membername'";
The header file then does a Boolean from 1 or 0. 0 meaning no one logged in from that IP and it can simply use the username and password boxes.
While, 1 would make PHP echo:
<center>You are logged in</center><br> <b>Rank:</b> $memrank<br> //This is a Battle.Net clan. <b>User:</b> $filterUsername<br><br> <center><a href='console.php'>View Console</a> | <a href='index.php?p=Logout'>Logout</a></center> //This can of course add one more tab.
#7
Re: Login Detection
Posted 04 June 2010 - 07:05 PM
adgarci, on 04 June 2010 - 05:52 PM, said:
The method I'm using is a database logged in or out query.
$query = "SELECT * FROM {$dbprefix}members WHERE username = '$checkUser' AND disable = '0'";
So, if this returns true, the database would put on that member's row 1 for logged in.
$query = "UPDATE {$dbprefix}members SET lastlogin = '$time', loggedin = '1', ipnum = '$ip' WHERE username = '$membername'";
The header file then does a Boolean from 1 or 0. 0 meaning no one logged in from that IP and it can simply use the username and password boxes.
While, 1 would make PHP echo:
<center>You are logged in</center><br> <b>Rank:</b> $memrank<br> //This is a Battle.Net clan. <b>User:</b> $filterUsername<br><br> <center><a href='console.php'>View Console</a> | <a href='index.php?p=Logout'>Logout</a></center> //This can of course add one more tab.
It is not realy efficient to store this in a database. The less interactions with your database, the faster your site.
When you store the login-status of your users in your database, you always have to check your database, when you want to know if a user is logged in or not.
Storing it in a session like aklo and georgehowell do above is less heavy to the server and faster.
#8
Re: Login Detection
Posted 04 June 2010 - 07:08 PM
webpeater, on 04 June 2010 - 07:43 PM, said:
VB.Terry, on 04 June 2010 - 05:19 PM, said:
If your not logged in. I want it to have two text boxes one for email and password. Then something telling you to register. If your logged in I want it to have three tabs saying "View Profile" "Edit Profile" "Log Out". I can code the login script and stuff I just don't know how to change the header depending on if your logged in or not. My website is http://envxsoftware.com/. Thanks in advance.
It depends how you do your login.
It is basicly :
if(isLoggedIn()) {
$extraHeaderContent = <<<EOD
<ul>
<li><a href="">View profile</a></li>
<li><a href="">Edit profile</a></li>
<li><a href="">Log out</a></li>
</ul>
EOD;
}
else {
$extraHeaderContent = <<<EOD
<form>
<!-- log in form -->
</form>
<a href="">Register</a>
EOD;
}
and in your header :
<?php print $extraHeaderContent; ?>
isLoggedIn maybe something like :
function isLoggedIn() {
if($_SESSION['logged_in'] === true)
return true;
return false;
}
I get another error now. You can see it at http://envxsoftware.com/. Here is how I put the code you gave me together:
<?php
function isLoggedIn() {
if($_SESSION['logged_in'] === true)
return true;
return false;
if(isLoggedIn()) {
$extraHeaderContent = <<<EOD
<ul>
<li><a href="">View profile</a></li>
<li><a href="">Edit profile</a></li>
<li><a href="">Log out</a></li>
</ul>
EOD;
}
else {
$extraHeaderContent = <<<EOD
<form>
</form>
<a href="register.php">Register</a>
EOD;
}
?>
#9
Re: Login Detection
Posted 04 June 2010 - 07:21 PM
#10
Re: Login Detection
Posted 04 June 2010 - 07:24 PM
It was the principal, it was not real code ready to use in your case.
You said you did know how to do the login (proces) itself, is that correct ?
You could check in a way if a user is logged in or not, I expect.
If you use sessions to store the login-state it maybe like
You set in the login proces $_SESSION['logged_in'] to TRUE
Then you could easy conditionally print the right text (links when logged in / form and register link otherwise)
<?php
if($_SESSION['logged_in']) {
?>
<!-- HTML for logged in user -->
<?php
} //end logged in
else {
?>
<!-- HTML for not logged in user -->
<?php
} //end not logged in
?>
This is more easy than the printing of strings i used above.
You get the idea ?
#11
Re: Login Detection
Posted 04 June 2010 - 07:43 PM
You are now logged in. Go to home.
When you press home it still shows that url telling to register. I'm not sure how to fix it.
I tried including the header.php file in the login_data.php file using
isLoggedIn === true;
After
$_SESSION['email'] = $email;
And it don't work.
#12
Re: Login Detection
Posted 04 June 2010 - 07:51 PM
VB.Terry, on 04 June 2010 - 06:43 PM, said:
You are now logged in. Go to home.
When you press home it still shows that url telling to register. I'm not sure how to fix it.
I tried including the header.php file in the login_data.php file using
isLoggedIn === true;
After
$_SESSION['email'] = $email;
And it don't work.
We will need some more info. We don't know what header.php, login_data.php are for.
How do you mean using ?
isLoggedIn == true;
You mean if(isLoggedIn === true) ??
We don't know where $_SESSION['email'] = $email is located, which file, ...
#13
Re: Login Detection
Posted 04 June 2010 - 08:05 PM
webpeater, on 04 June 2010 - 08:51 PM, said:
VB.Terry, on 04 June 2010 - 06:43 PM, said:
You are now logged in. Go to home.
When you press home it still shows that url telling to register. I'm not sure how to fix it.
I tried including the header.php file in the login_data.php file using
isLoggedIn === true;
After
$_SESSION['email'] = $email;
And it don't work.
We will need some more info. We don't know what header.php, login_data.php are for.
How do you mean using ?
isLoggedIn == true;
You mean if(isLoggedIn === true) ??
We don't know where $_SESSION['email'] = $email is located, which file, ...
email and $email thing is one of the fields on my database. So is password and $password. That is the information your going to use to login.
I'll provide the code for the header.php and login_data.php.
header.php
<?php
session_start();
function isLoggedIn() {
if($_SESSION['logged_in'] === true)
return true;
return false;
}
if(isLoggedIn()) {
$extraHeaderContent = <<<EOD
<ul>
<li><a href="">View profile</a></li>
<li><a href="">Edit profile</a></li>
<li><a href="">Log out</a></li>
</ul>
EOD;
}
else {
$extraHeaderContent = <<<EOD
<table width="200" border="0" div="login">
<form>
<tr>
<td>Email:</td>
<td><input type="text" name="email" maxlength="32"/></td>
<td>Password:</td>
<td><input type="text" name="password" maxlength="32"/></td>
<td><input type="submit" name="submit" value="Login"/></td>
</tr>
</form>
</table>
<a href="register.php">Register</a>
EOD;
}
?>
login_data.php
<?php
session_start();
include_once("header.php");
$email = $_POST['email'];
$password = $_POST['password'];
include_once("connect.php");
if($email && $password)
{
$queryget = mysql_query("SELECT * FROM myMembers WHERE email='$email' AND password='$password'")or die(mysql_error())
;
$numrows = mysql_num_rows($queryget);
if ($numrows != 0)
{
$_SESSION['email'] = $email;
echo "You are now logged in. Go to<a href='http://envxsoftware.com/index.php'> home</a>.";
}
else
echo "Your username was not found.";
}
else
{
echo "You are either not a registered member of Env X or did not fill out you information correctly.";
}
?>
The header.php is to change the appearance of the header image depending on if your logged in or logged out. the login_data.php handles all of the data the user sends to log them in.
I got the login box to show up on each page now. But I can't position it. I tried using CSS, but I don't know how to use CSS with PHP.
Here is the header.php file again
<?php
session_start();
function isLoggedIn() {
if($_SESSION['logged_in'] === true)
return true;
return false;
}
if(isLoggedIn()) {
$extraHeaderContent = <<<EOD
<ul>
<li><a href="">View profile</a></li>
<li><a href="">Edit profile</a></li>
<li><a href="">Log out</a></li>
</ul>
EOD;
}
else {
$extraHeaderContent = <<<EOD
<table width="200" border="0" div="login">
<form>
<tr>
<td>Email:</td>
<td><input type="text" name="email" maxlength="32"/></td>
<td>Password:</td>
<td><input type="text" name="password" maxlength="32"/></td>
<td><input type="submit" name="submit" value="Login"/></td>
</tr>
</form>
</table>
<a href="register.php">Register</a>
EOD;
}
?>
#14
Re: Login Detection
Posted 04 June 2010 - 08:12 PM
You put between <head></head>
<link href="yourStyleSheet.css" rel="stylesheet" type="text/css" />
And in the stylesheet you style your form, like you always do.
But you still have a problem with de logged in/not logged in header content ?
#15
Re: Login Detection
Posted 04 June 2010 - 08:14 PM
webpeater, on 04 June 2010 - 09:12 PM, said:
You put between <head></head>
<link href="yourStyleSheet.css" rel="stylesheet" type="text/css" />
And in the stylesheet you style your form, like you always do.
But you still have a problem with de logged in/not logged in header content ?
I'm not using <head></head>, <html></html>, or <body></body> tags in the header.php document. Yes I'm still unable to get in/out logged in header content.
|
|

New Topic/Question
Reply




MultiQuote







|