Authentication area

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
killingbegin
Forum Newbie
Posts: 20
Joined: Sun Feb 08, 2009 5:07 am

Authentication area

Post by killingbegin »

i tried understand how sessions work on secured area but cant.


I have 2 pages

secure1.php
secure2.php

what is the part of php that you will include in that 2 pages
that do

if (the user have set the username and password and they are right)
you can see the rest of that page
else
access denied
you must fill your username and pass on that form
<form>....</form>

i tryed to make an auth.inc.php
that have that code but ofc dont do what i want

Code: Select all

 
<?php
session_start();
$name = "user";
$pass = "pass";
 
if($_POST){
  $_SESSION['username']=$_POST["username"];
  $_SESSION['password']=$_POST["password"];  
}
 
if($_SESSION['username'] == "user" AND $_SESSION['password'] == "pass")
{
    $_SESSION['sec'] = "yes";
    header("Location: secure1.php");
    
}
else
{
?>
</head>
<body>
<form id="form1" name="form1" method="post" action="<?PHP echo $PHP_SELF; ?>">
  <p>username:
    <label>
    <input type="text" name="username" id="username" />
    </label>
</p>
  <p>password:
    <label>
    <input type="text" name="password" id="password" />
    </label>
  </p>
  <p>
    <label>
    <input type="submit" name="submit" id="submit" value="Submit" />
    </label>
  </p>
</form>
</body>
</html>
<?php
}
exit; 
?>
 
ofcourse that code dont work and its refresh my page all time liek a counter

i hope you can understand what is my point here.thnx in advanced
Post Reply