Programming, website development forum Get latest updates by RSS Follow TechnicalTalk on Twitter Follow TechnicalTalk on Facebook 
HomeSearchRecent PostsLoginRegisterContact Us

Username  
Password    
  Forgot your password?  

Pages: [1]   Go Down
 
  Email this topic  |  Print
0 Members and 1 Guest are viewing this topic.

How to make a login session in php?

 
webmaster forum
singam  Offline
Activity
0%
 
Regular Coder
Posts: 50
Topics: 19
July 18, 2010, 09:58:32 PM

How to make a login session in php?
The user should only be allowed to access a page after login i have a page called news.html and signin.html. I am new in php I want the user to login in to access to news.html page. Any sugesstion. Give example in codes
« Last Edit: May 08, 2011, 10:28:47 PM by Admin »
 
webmaster forum
Admin  Offline
*
 
Code Guru
Location: India
Gender: Male
Posts: 1387
Topics: 105
NaviBuster NaviBuster
WWW
July 19, 2010, 12:45:00 AM

You can check this thread on this forum Login Code in PHP.

Hope this helps you.
 
webmaster forum
zeceffron  Offline
Activity
0%
 
New Poster
Posts: 4
Topics: 0
July 30, 2010, 05:31:32 AM

When the user are login in a site.  The user name and password are post in a another form.  Both value are stored in a session variable.  like $uname=$_SESSION['username '] and  $pass=$_SESSION['password'].   Finally start the session with session_start() . With the help of both variable value are stored in a session variable $uname and $pass.
 
webmaster forum
Admin  Offline
*
 
Code Guru
Location: India
Gender: Male
Posts: 1387
Topics: 105
NaviBuster NaviBuster
WWW
July 30, 2010, 08:53:57 AM

@zeceffron:

There is some typo in your code above.

To store a value in session one should write:

$_SESSION['username'] = $uname;
$_SESSION['password'] = $pass;


To retrieve/fetch the values from session on should write:

$uname=$_SESSION['username'];
$pass=$_SESSION['password'];



 
webmaster forum
polas  Offline
Activity
33.33%
 
Code Guru
Gender: Male
Posts: 1399
Topics: 85
WWW
August 01, 2010, 06:17:26 AM

In safe mode PHP can sometimes mess with what you can see in terms of session vars. So you may need to disable safe mode if your having problems at all

Mesham Type Oriented Parallel Programming Language, Free online technical support
 
webmaster forum
Activity
0%
 
Skilled Coder
Posts: 125
Topics: 0
January 23, 2011, 10:21:27 PM

If you want to create login Session than First, create a text file called config. php and add in the following code into that textpage.  In that File You have to enter normal Lgon code and in addition you have to use following:

if ($username=="$uname")  {
session_register("username");
session_register("password");
echo "user is $uname, and password is $pword
<br> <a href=\"?m=1\" >unreg</a>";
}
else echo "nope";
}
if ($m==1) {
session_unregister("username");
session_unregister("password");
}
?>

Network Management Service
 
webmaster forum
Life Is Good!
Activity
0%
 
Professional Coder
Gender: Female
Posts: 242
Topics: 3
WWW
April 10, 2011, 05:53:28 AM

you should put on top of all your codes..

<?php

session_save_path(temp);
session_start();

?>

this is before you do session manipulation..

then put this at the bottom of your codes..

<?php

session_destroy();

?>

Affordable Custom Web Design Services
 
webmaster forum
ShaunWd  Offline
Activity
0%
 
New Coder
Real name: Shaun
Posts: 34
Topics: 0
WWW
April 13, 2011, 10:25:24 AM

Three things are required to create session login first DataBase , Connection with DB, and last Session Variables.
Create a Database according to requirements
CREATE TABLE member (
id int NOT NULL auto_increment,
username varchar(20) NOT NULL default '',
password char(32) binary NOT NULL default '',
cookie char(32) binary NOT NULL default '',
session char(32) binary NOT NULL default '',
ip varchar(15) binary NOT NULL default '',
PRIMARY KEY (id),
UNIQUE KEY username (username)
);

Connection with DB is normal code
 and at end Session Variables
function session_defaults() {
$_SESSION['logged'] = false;
$_SESSION['uid'] = 0;
$_SESSION['username'] = '';
$_SESSION['cookie'] = 0;
$_SESSION['remember'] = false;
}

... with a check like:

if (!isset($_SESSION['uid']) ) {
session_defaults();
}

SEO Forum , PHP Forum
 
webmaster forum
Activity
0%
 
New Coder
Real name: Michelle Jorgen
Posts: 42
Topics: 2
WWW
April 29, 2011, 12:18:00 AM


Nice post its really work
« Last Edit: May 21, 2011, 11:25:10 AM by Admin »

Lexington Taxi , Hire Taxi Lexington
 
webmaster forum
annyphp  Offline
Activity
0%
 
New Poster
Posts: 3
Topics: 1
WWW
May 08, 2011, 07:01:07 PM

Recommend a good php script:
Code:
class Login_Ban
011 {
012
013
014
015
016    /**
017    * The number of attempts
018    *
019    * @var  int
020    */
021    
022    var $Limit_attempts = '3';
023    
024    /**
025    * The time of ban (Minutes)
026    *
027    * @var  int
028    */
029    
030    var $Ban_time = '15';
031
032    /**
033    * Constructor.
034    * @param    Limit attemps to ban
035    * @param    time of ban (Minutes)
036    */
037
038    function Login_Ban($Limit_attempts = '3', $Ban_time = '15')
039    {
040    $this->Limit_attempts = $Limit_attempts;
041    $this->Ban_time = $Ban_time;
042    }
043    
044    /**
045    * Add the cookies
046    * @param    the name if cookie
047    * @param    the value
048    */
049    function SetCookies($CookiesName, $Value)
050    {
051    setcookie($CookiesName, $Value,time() + 60 * 60 * 24 * 30, NULL ,NULL, NULL, TRUE);
052    }
053    
054    /**
055    * Add new attemp.
056    */
057
058    function Set_Attemp()
059    {
060    if(! isset($_COOKIE['login_attemp']))
061    {
062    $this->SetCookies('login_attemp', '1');
063    $this->SetCookies('attemp_date', time());
064    } elseif(isset($_COOKIE['login_attemp']))
065    {
066    $this->SetCookies('login_attemp', $_COOKIE['login_attemp'] + 1);
067    $this->SetCookies('attemp_date', time());
068    }
069    }
070    
071    
072    /**
073    * To verify that it has been banned
074    *
075    */
076    
077    function Banned()
078    {
079    if(! isset($_COOKIE['login_attemp']))
080    {
081    return false;
082    } elseif(isset($_COOKIE['login_attemp']))
083    {
084    if(($_COOKIE['login_attemp'] == $this->Limit_attemps || $_COOKIE['login_attemp'] > $this->Limit_attemps))
085    {
086    if($this->Ban_time * 60 + time() == $_COOKIE['attemp_date'] || $this->Ban_time * 60 + time() * 60 > $_COOKIE['attemp_date'])
087    {
088    return true;
089    } else
090    {
091    return false;
092    }
093    } else
094    {
095    return false;
096    }
097    }
098    }
099    
100    /**
101    * Delete the attemper cookies.
102    */
103    
104    function mkempty()
105    {
106    $this->SetCookies('login_attemp', '');
107    $this->SetCookies('attemp_date', '');
108    }
109    
110
111 }
112
113
114
115
116 ?>
« Last Edit: May 08, 2011, 10:28:33 PM by Admin »
 
  Email this topic  |  Print
Pages: [1]   Go Up
 
Jump to:  



Powered by SMF 1.1.15 | SMF © 2011, Simple Machines


Google visited last this page February 03, 2012, 02:49:22 PM