cf_member
11-14-2012, 11:31 PM
I have created a login page with PDO connection for db.
Then i got 5 files index.php, login.php, securedpage.php,
user.php, connection.php, and the style.css.
And now submitting my login form which is in login.php.
Instead securedpage.php, it will display the index.php
after submission. I wonder why it won't redirect to
securedpage.php. Can anyone give advice on why and how.
This is my securedpage.php
<?php
// Inialize session
session_start();
// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['username'])){
header("Location: index.php");
}
?>
<html> body goes along after this line.
And my user.php to process the login.
<?php
include_once('connection.php');
class User{
private $db;
public function __construct(){
$this->db = new Connection();
$this->db = $this->db->dbConnect();
}
public function Login($name, $pass){
if(!empty($name) && !empty($pass)){
$st = $this->db->prepare("select * from user where username=? and password=?");
$st->bindParam(1, $name);
$st->bindParam(2, $pass);
$st->execute();
var_dump($st->rowCount());
if($st->rowCount() == 1){
header('Location: securedpage.php');
}else {
echo "Incorrect username and password";
}
}else{
echo "Please enter username and password";
}
}
}
I feel there is something missing on these part.
Can anyone give an advice.
Thanks advance. :)
Then i got 5 files index.php, login.php, securedpage.php,
user.php, connection.php, and the style.css.
And now submitting my login form which is in login.php.
Instead securedpage.php, it will display the index.php
after submission. I wonder why it won't redirect to
securedpage.php. Can anyone give advice on why and how.
This is my securedpage.php
<?php
// Inialize session
session_start();
// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['username'])){
header("Location: index.php");
}
?>
<html> body goes along after this line.
And my user.php to process the login.
<?php
include_once('connection.php');
class User{
private $db;
public function __construct(){
$this->db = new Connection();
$this->db = $this->db->dbConnect();
}
public function Login($name, $pass){
if(!empty($name) && !empty($pass)){
$st = $this->db->prepare("select * from user where username=? and password=?");
$st->bindParam(1, $name);
$st->bindParam(2, $pass);
$st->execute();
var_dump($st->rowCount());
if($st->rowCount() == 1){
header('Location: securedpage.php');
}else {
echo "Incorrect username and password";
}
}else{
echo "Please enter username and password";
}
}
}
I feel there is something missing on these part.
Can anyone give an advice.
Thanks advance. :)