Login Detection

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »

52 Replies - 3334 Views - Last Post: 10 June 2010 - 08:11 AM Rate Topic: -----

#1 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Login Detection

Posted 04 June 2010 - 06:19 PM

Hello. I know this question is stupid. I know the rules of this forum (I'm not showing any code). I just want a guide. I want to make my header for my website to show different information depending on if you logged in or not. I want to be able to do this in PHP.

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.

Is This A Good Question/Topic? 0
  • +

Replies To: Login Detection

#2 webpeater  Icon User is offline

  • D.I.C Head

Reputation: 26
  • View blog
  • Posts: 95
  • Joined: 04-June 10

Re: Login Detection

Posted 04 June 2010 - 06:43 PM

View PostVB.Terry, on 04 June 2010 - 05:19 PM, said:

Hello. I know this question is stupid. I know the rules of this forum (I'm not showing any code). I just want a guide. I want to make my header for my website to show different information depending on if you logged in or not. I want to be able to do this in PHP.

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

Was This Post Helpful? 1
  • +
  • -

#3 georgehowell  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 10
  • Joined: 23-April 10

Re: Login Detection

Posted 04 June 2010 - 06:49 PM

Hi Terry,
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
Was This Post Helpful? 0
  • +
  • -

#4 aklo  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 229
  • Joined: 23-January 09

Re: Login Detection

Posted 04 June 2010 - 06:51 PM

I haven't done anything "real" before...but for my dummy site I did to practice php, I used session.

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.
Was This Post Helpful? 0
  • +
  • -

#5 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: Login Detection

Posted 04 June 2010 - 06:52 PM

View Postgeorgehowell, on 04 June 2010 - 07:49 PM, said:

Hi Terry,
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.
Was This Post Helpful? 0
  • +
  • -

#6 adgarci  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 96
  • Joined: 26-August 09

Re: Login Detection

Posted 04 June 2010 - 06:52 PM

I'm working on something much like this. (Logging in at least)

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. 


Was This Post Helpful? 0
  • +
  • -

#7 webpeater  Icon User is offline

  • D.I.C Head

Reputation: 26
  • View blog
  • Posts: 95
  • Joined: 04-June 10

Re: Login Detection

Posted 04 June 2010 - 07:05 PM

View Postadgarci, on 04 June 2010 - 05:52 PM, said:

I'm working on something much like this. (Logging in at least)

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.
Was This Post Helpful? 1
  • +
  • -

#8 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: Login Detection

Posted 04 June 2010 - 07:08 PM

View Postwebpeater, on 04 June 2010 - 07:43 PM, said:

View PostVB.Terry, on 04 June 2010 - 05:19 PM, said:

Hello. I know this question is stupid. I know the rules of this forum (I'm not showing any code). I just want a guide. I want to make my header for my website to show different information depending on if you logged in or not. I want to be able to do this in PHP.

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;
}
?>

Was This Post Helpful? 0
  • +
  • -

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,662
  • Joined: 23-August 08

Re: Login Detection

Posted 04 June 2010 - 07:21 PM

You're missing the closing } on your function.
Was This Post Helpful? 0
  • +
  • -

#10 webpeater  Icon User is offline

  • D.I.C Head

Reputation: 26
  • View blog
  • Posts: 95
  • Joined: 04-June 10

Re: Login Detection

Posted 04 June 2010 - 07:24 PM

Did you use exactly this code ?
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 ?
Was This Post Helpful? 0
  • +
  • -

#11 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: Login Detection

Posted 04 June 2010 - 07:43 PM

I've gotten the login script to finally work. When you login it sends you to a page that says

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.
Was This Post Helpful? 0
  • +
  • -

#12 webpeater  Icon User is offline

  • D.I.C Head

Reputation: 26
  • View blog
  • Posts: 95
  • Joined: 04-June 10

Re: Login Detection

Posted 04 June 2010 - 07:51 PM

View PostVB.Terry, on 04 June 2010 - 06:43 PM, said:

I've gotten the login script to finally work. When you login it sends you to a page that says

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, ...
Was This Post Helpful? 0
  • +
  • -

#13 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: Login Detection

Posted 04 June 2010 - 08:05 PM

View Postwebpeater, on 04 June 2010 - 08:51 PM, said:

View PostVB.Terry, on 04 June 2010 - 06:43 PM, said:

I've gotten the login script to finally work. When you login it sends you to a page that says

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;
}
?>

Was This Post Helpful? 0
  • +
  • -

#14 webpeater  Icon User is offline

  • D.I.C Head

Reputation: 26
  • View blog
  • Posts: 95
  • Joined: 04-June 10

Re: Login Detection

Posted 04 June 2010 - 08:12 PM

You just a CSS like there was nog PHP

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 ?
Was This Post Helpful? 0
  • +
  • -

#15 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: Login Detection

Posted 04 June 2010 - 08:14 PM

View Postwebpeater, on 04 June 2010 - 09:12 PM, said:

You just a CSS like there was nog PHP

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.
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »