Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Some Guidance Please

Status
Not open for further replies.

bont

Programmer
Joined
Sep 7, 2000
Messages
200
Location
US
I have been through a few books of PHP now, and have done a lot of research, but I am torn. I have always been anti-cookie, but I love the features it gives. I have recently been given the task of building a login area for our web.

Can I still use session ID for everyone?

Can anyone point me to a sample php script that performs login using mysql, but doesn't use anything fancy? No Cookies.

Can anyone point me to a sample php script that may allow for both cookies, and for those that don't have cookies at all?
 
Hi, a sample script using SESSION. It does not use cookies..
I going to put you an example I made to undestarnd -time ago- the sessions (no DB, sorry, but you can modify it).

Code:
1. ---------- login.html ------------------
<html>
<head>
<title>Login Page</title>
</head>
<body>
<form method=post action=login.php>
User:
<input type=text name=user>
<br>
Password:
<input type=password name=pwd>
<br>
<input type=submit value=&quot;Login!&quot;>
</form>
</body>
</html>

2. ----------- login.php ------------------
<?php
    session_start();
    $user=$_POST&quot;user&quot;;
    $pwd=$_POST&quot;pwd&quot;;

    if (($user == &quot;Chacal&quot;) && ($pwd == &quot;admin&quot;))
    {
        $_SESSION['nombre']=&quot;Victor Cuevas D.&quot;;
        $_SESSION['logged']=&quot;Si&quot;;
        header(&quot;Location: index.php&quot;);
    } else
        header(&quot;Location: login.html&quot;);
?>

3. ------------ index.php ----------------
<?php
    session_start();
    
    include_once(&quot;control.php&quot;);

    if (!is_logged())
    {
        header(&quot;Location: login.html&quot;);
        exit(0);
    }
    echo &quot;Hola we'on..&quot; . $_SESSION&quot;nombre&quot; .&quot;<br>\n&quot;;
    echo &quot;<hr>\n&quot;;
    echo &quot;<a href='page2.php'>Vamos a la otra páginas</a><br>\n&quot;;
    echo &quot;<a href='salir.php'>A salgamos de esta weá</a><br>\n&quot;;
        
?>

4. ---------- control.php ---------------------
<?php
    function is_logged(){
        if ((!isset($_SESSION&quot;logged&quot;)) || ($_SESSION&quot;logged&quot;!=&quot;Si&quot;))
            return FALSE;
        else
            return TRUE;
    }
?>

5. ------------ page2.php ------------------
<?php
    session_start();
    
    include_once(&quot;control.php&quot;);
    
    if (!is_logged())
    {
        header(&quot;Location: login.html&quot;);
        exit(0);
    }
    echo &quot;Hola we'on..<br>\n&quot;;
    echo &quot;<hr>\n&quot;;
    echo &quot;<a href='index.php'>Vamos a la página 1</a><br>\n&quot;;
    echo &quot;<a href='salir.php'>A salgamos de esta weá</a><br>\n&quot;;
        
?>

6. -------------- salir.php (get_out.php inenglish)----
<?php
    session_start();
    $_SESSION[]=array();
    session_destroy();
    header(&quot;Location: login.html&quot;);
?>
I going to put you an example I made to undestarnd -time ago- the sessions (no DB, sorry, but you can modify it).


1. ---------- login.html ------------------
<html>
<head>
<title>Login Page</title>
</head>
<body>
<form method=post action=login.php>
User:
<input type=text name=user>
<br>
Password:
<input type=password name=pwd>
<br>
<input type=submit value=&quot;Login!&quot;>
</form>
</body>
</html>

2. ----------- login.php ------------------
<?php
    session_start();
    $user=$_POST&quot;user&quot;;
    $pwd=$_POST&quot;pwd&quot;;

    if (($user == &quot;Chacal&quot;) && ($pwd == &quot;admin&quot;))
    {
        $_SESSION['nombre']=&quot;Victor Cuevas D.&quot;;
        $_SESSION['logged']=&quot;Si&quot;;
        header(&quot;Location: index.php&quot;);
    } else
        header(&quot;Location: login.html&quot;);
?>

3. ------------ index.php ----------------
<?php
    session_start();
    
    include_once(&quot;control.php&quot;);

    if (!is_logged())
    {
        header(&quot;Location: login.html&quot;);
        exit(0);
    }
    echo &quot;Hola we'on..&quot; . $_SESSION&quot;nombre&quot; .&quot;<br>\n&quot;;
    echo &quot;<hr>\n&quot;;
    echo &quot;<a href='page2.php'>Vamos a la otra páginas</a><br>\n&quot;;
    echo &quot;<a href='salir.php'>A salgamos de esta weá</a><br>\n&quot;;
        
?>

4. ---------- control.php ---------------------
<?php
    function is_logged(){
        if ((!isset($_SESSION&quot;logged&quot;)) || ($_SESSION&quot;logged&quot;!=&quot;Si&quot;))
            return FALSE;
        else
            return TRUE;
    }
?>

5. ------------ page2.php ------------------
<?php
    session_start();
    
    include_once(&quot;control.php&quot;);
    
    if (!is_logged())
    {
        header(&quot;Location: login.html&quot;);
        exit(0);
    }
    echo &quot;Hola we'on..<br>\n&quot;;
    echo &quot;<hr>\n&quot;;
    echo &quot;<a href='index.php'>Vamos a la página 1</a><br>\n&quot;;
    echo &quot;<a href='salir.php'>A salgamos de esta weá</a><br>\n&quot;;
        
?>

6. -------------- salir.php (get_out.php inenglish)----
<?php
    session_start();
    $_SESSION[]=array();
    session_destroy();
    header(&quot;Location: login.html&quot;);
?>

Try it and analyze it, if you have questions, let us know!

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top