Logo
Check If User Is Logged In
Online Now: 0
Snippet Code
This Snippet will check and see if if a user is logged in or not.

functions.php


<?php
function loggedIn(){
    
//Session logged is set if the user is logged in
    //set it on 1 if the user has successfully logged in
    //if it wasn't set create a login form
    
if(!$_SESSION['loggd']){
        echo
'<form action="checkLogin.php" method="post">
        <p>
            Username:<br>
            <input type="text" name="username">
        </p>
        <p>
            Password:<br>
            <input type="password" name="username">
        </p>
        <p>
            <input type="submit" name="submit" value="Log In">
        </p>
        </form>'
;
        
//if session is equal to 1, display 
        //Welcome, and whaterver their user name is
    
}else{
        echo 
'Welcome, '.$_SESSION['username'];
    }
}
?>

index.php


<?php
//Start the session
session_start();

//This is a simplified HTML Document
?>
<html>
<head>
<title>My Page</title>
</head>
<body>
    <?php
    
//Call the functions file
    
require_once("functions.php");
    
//Display either the user's name, or the login form
    //This can be placed on many pages without having
    //to re-write the form everytime, just use this function
    
logedIn();
    
?>
</body>
</html>
 
Snippet Comments

Add Your Comment

Austin Real Estate
2011-05-31 06:31:07
you are doing good work by sharing such valuable in formations with people keep doing this nice work.
Sheryl Crow Tickets
2011-05-20 00:37:07
Intimately, the post is really the greatest on this worthwhile topic. I match in with your conclusions and can eagerly look forward to your next updates.
wastewater treatment
2011-05-10 09:49:31
I have use zend studio to develop php application. Here the code is not running in local server. Will it to be run in internet server. I have hosting server in HostGador. How I can run it with Apace server?
instant site launcher
2011-05-08 17:07:06
A very useful PHP script! I've been trying to display list of numeric values and this will help a lot.
colopure cleanse reviews
2011-05-06 01:13:20
I’ve been looking everywhere for this! Thank goodness I found it on Bing.Thx
acai berry diet
2011-05-06 01:12:11
It's great to hear from you and see what you've sent up to. All of the projects look great! You make it so simple to this.Thanks!
Van Insurance Comparison
2011-04-05 04:52:20
This is great a login script, I'm really struggling to find this in the net.
php scripts
2010-09-14 00:01:04
cooool. thx for your share lol
Search Engine Optimization
2008-08-28 00:00:00
I'm still learning php so any information I find is great. Thanks for the great post.
pedantic arse
2008-08-27 00:00:00
its logged not loged

Add Your Comment

 
Snippet Tools
Rate this Snippet:

Rate the difficulty level:

Request Snippet Update


Suggested Difficulty Level: Professional
Current Score: 2.85
Total votes: 304
Total Views: 14565

Other top snippets by admin:

1. JPEG to ASCII Converter
2. Add (th, st, nd, rd, th) to the end of a number
3. Dynamic Page Content From Links
4. AJAX Quickie
5. Simple Image CAPTCHA

Search
Search for:







User Panel

User name:

Password:

Register And Post Your Own Snippets

New Snippets

1.  Shorten text and (4 of 1)

2.  file-based simple guest (0 of 0)

3.  adding an entry (0 of 0)

4.  integer to currency (1.33 of 3)

5.  Aggregate IP addresses (0 of 0)

6.  file handling (0 of 0)

7.  testing system with (0 of 0)

8.  Make an php (1 of 1)

9.  allow download in (5 of 1)

10.  redirect in 3 (0 of 0)

11.  live clock with (0 of 0)

12.  visit counter (3.5 of 2)

13.  contact form with (4 of 1)

14.  show a specific (0 of 0)

15.  The & sign (0 of 0)

16.  static variable in (0 of 0)

17.  multiplication table with (0 of 0)

18.  function with multiplicationt (0 of 0)

19.  php generated menu (0 of 0)

20.  drawing a table (0 of 0)

21.  embedded array (one (0 of 0)

22.  checks the week (0 of 0)

23.  put links on (4.5 of 2)

24.  Directory Image Gallery (0 of 0)

25.  TOS (4 of 1)

Home | Forum | Free PHP Web Hosting | Contact | Terms & Conditions |  
Donate
PHPSnips.com - ©2012 Amethyst Creative