I want to create login page for admin and worker, and each of them will have different content table in their page once they logged in.
I’ve installed insert php
plugin to write code in page directly.
I am using session for login and I want to use record set to create custom table in each page.
I created a code in dreamweaver then post it in page text.
I have created this code but it didn’t work as php and didn’t logged in and shows code in the page.
[insert_php]
error_reporting(E_ALL);
session_start(); // Starting Session
$error=''; // Variable To Store Error Message
if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "Username or Password is invalid";
} else {
// Define $username and $password
$username=$_POST['username'];
$password=$_POST['password'];
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysqli_connect("localhost", "lujcarwa", "lcarwash2015");
// To protect MySQL injection for Security purpose
$username = stripslashes($username);
$password = mysqli_real_escape_string($password);
// Selecting Database
$db = mysqli_select_db("login", $connection);
// SQL query to fetch information of registerd users and finds user match.
$query = mysqli_query("select * from login where password='$password' AND username='$username'", $connection);
$rows = mysqli_num_rows($query);
if ($rows == 1) {
$_SESSION['login']=$username; // Initializing Session
header("location: profile.php"); // Redirecting To Other Page
} else {
$error = "Username or Password is invalid";
}
mysqli_close($connection); // Closing Connection
}
}
error_reporting(E_ALL ^ E_DEPRECATED);
include('login.php'); // Includes Login Script
if(isset($_SESSION['login'])){
header("location: profile.php");
}
error_reporting(E_ALL ^ E_DEPRECATED);
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysqli_connect("localhost", "lujcarwa_washer", "dj0P7]w4S]");
// Selecting Database
$db = mysqli_select_db("lujcarwa_washer", $connection);
session_start();// Starting Session
// Storing Session
$user_check=$_SESSION['login'];
// SQL Query To Fetch Complete Information Of User
$ses_sql=mysqli_query("select username from login where username='$user_check'", $connection);
$row = mysql_fetch_assoc($ses_sql);
$login_session =$row['username'];
if(!isset($login_session)){
mysql_close($connection); // Closing Connection
header('Location: index.php'); // Redirecting To Home Page
}
[insert_php/]
<head>
<title>Login</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="main">
<h1> Login </h1>
<div id="login">
<form action="" method="post">
<p>
<label>UserName :</label>
</p>
<p>
<br />
<input id="name" name="username" placeholder="username" type="text">
<br />
<label>
<br>Password</label>
<br />
<input id="password" name="password" placeholder="**********" type="password">
<input name="submit" type="submit" value=" Login ">
</p>
</form>
</div>
</div>
</body>
I’m not known with the [insert_php] plugin but it looks like it’s a issue with not closing you [insert_php] tag like this [/insert_php] at the end of your php.
Edit:
You are closing it like:
Hope this helps you out.
Edit:
I just took a look at the plugin description and saw this in the FAQ:
Why can’t I set cookies or do a browser redirect?
With PHP, cookies are set in the web page header lines, before any page content is processed. Redirects, too, are done in the header lines. When PHP code is within a post or a page, all the header lines have already been sent, along with part of the content. At that point, it is too late to set cookies or redirect with PHP
So it looks like you can’t use this plugin to redirect the user at login.
I would suggest just to write the php in your template folder in a custom page template or header file.
Hope this helped!