on my http://localhost/qconsolidated/login_controller/login this error appears:
Object not found!
The requested URL was not found on this server. The link on the
referring page seems to be wrong or outdated. Please inform the author
of that page about the error.
I always get this error everytime i click the submit button on my form. I have checked my it back and forth for 2 days now, and still could't get it right. please help me. Here are the codes that I made:
login_controller.php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login_controller extends CI_Controller {
public function index(){
$this->load->view('template/header');
$this->load->view('login_view');
$this->load->view('template/footer');
}
public function login(){
echo "<script> alert('Working!'); </script>";
}
login_view.php
<div class="container">
<form class="form-login" method="post" action="/login_controller/login">
<img src="<?php echo base_url(); ?>public/img/q_logo.png">
<label class="sr-only">Email address</label>
<input type="email" name="email" class="form-control" placeholder="Email address" required autofocus>
<label class="sr-only">Password</label>
<input type="password" name="password" class="form-control" placeholder="Password" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Log in</button>
</form>
</div>
Please help me
change your action url.
<form class="form-login" method="post" action="<?php echo base_url()?>/login_controller/login">
change form action.Use something like this
<form class="form-login" method="post" action="<?php echo site_url('login_controller/login');?>">
you can also achieve this by using form_open('login_controller/login');
Try like this used base_url
<form class="form-login" method="post" action="<?php echo base_url("login_controller/login");">
Related
I have a made a simple website with login. My users sql table is as shown below:
my login form is like below:
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="login-panel panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">Sign In</h3>
</div>
<div class="panel-body">
<form role="form" method="post" action="login.php">
<fieldset>
<div class="form-group" >
<input class="form-control" placeholder="E-mail" name="email" type="email" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Password" name="pass" type="password" value="">
</div>
<input type="submit" value="login" name="login" >
i want to restrict some users from entering some pages. i have made the access column for this. I have added the following code to the protected page
session_start();
if($_SESSION["access"]!=0)
{
header('Location: login.php');
}
there are some problems with this coode i guess. when the access=0,the page is shown even if the user is not logged in and shows like Undefined index: access in C:\xampp\htdocs\nurse\index.php on line 12
when the access is set to 1 ,its redirected to login page. can anyone help me?
You need to check session is set or not like this
if(isset($_SESSION["access"])) {
if($_SESSION["access"] !=0) {
header('Location: login.php');
}
}
suppose i have this post a job page
<?php include_once "session.php" ;?>
<div id="wraper">
<?php include_once 'header.php'; ?>
<?php include_once 'navigationjp.php'; ?>
<div id="main">
<div id="content">
<div >
<form class="form" action="" method="post" >
<div class="lbl"><label><h2>Job Title: </h2></label></div>
<input class="inpu" type="input" name="title" required placeholder="HR Manager" /><br>
<div class="lbl"><label><h2>Degree: </h2></label></div>
<input class="inpu" type="input" name="degree" placeholder="MBA (HR)" /><br>
<div class="lbl"><label ><h2>Posts: </h2></label></div>
<input class="inpu" type="input" name="posts" placeholder="03" /><br>
<div class="lbl"><label><h2>Company: </h2></label></div>
<input class="inpu" type="input" name="company" required="" placeholder="Diamond Pvt Ltd Company" /><br>
<div class="lbl"><label><h2>Contact No: </h2></label></div>
<input class="inpu" type="text" name="contact" id="contact" required placeholder="0423121212" /><br><br>
<div class="lbl"><label><h2> </h2></label></div>
<input class="inpu" type="submit" name="submit" value="Post job" />
</form>
</div>
</div>
<?php include_once 'sidebar.php'; ?>
</div>
<?php include_once 'footer.php'; ?>
</div>
and i want that when someone click on form to write something it should check either user is signed in or not , if not signed in then i want to show an alert to user to login first if user is not signed in. how can i do it by using jquery or php ? can somebody tell me the example code please i don't know how to do it?
Well, you have 2 ways to do it, first is check this when the user enter the page above with php, something like this:
<?php if (!$user) { >?
<script>alert("Please log in first")</script>
<?php }?>
this will check the user right after he entered the page, you should provide us with more info about your login method and code so we can help you more specifically.
if you want to check if he is logged in after he already visited the page, you will need to use AJAX for that, php runs once after the page is loaded, so your way to talk with the php code after the page is loaded is with AJAX.
<script>
$("input.inpu").click(function() { //when the user clicked on the input
//do your ajax here.
});
</script>
you should read more about ajax here: http://api.jquery.com/jquery.ajax/
HTML Code:
<form class="form-inline signup" role="form" action="script.php" method="post">
<div class="form-group">
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter your email address" name="email" >
</div>
<button type="submit" class="btn btn-theme">Get notified!</button>
</form>
PHP Code:
<?php
if (!empty($_POST["email"]))
file_put_contents("emails.txt", file_get_contents("emails.txt") . "\n" . $_POST["email"]);
?>
I tried several methods before asking here but none works.
When the button is click it loads the php code and shows a blank page on the browser.
You have to do a lot of things before you can start.
Set the action attribute of the form to a .php file.
<form class="form-inline signup" role="form" action="write.php" method="post">
Give a name attribute to the <input /> element.
<input type="email" class="form-control" id="exampleInputEmail1"
placeholder="Enter your email address" name="email" />
In the write.php (or whatever PHP file you use), actually write to the file.
<?php
if (!empty($_POST["email"]))
file_put_contents("emails.txt", file_get_contents("emails.txt") . "\n" . $_POST["email"]);
?>
Last but not least, please run this on the server and not in browser:
http://localhost/file.php
I have an area made up in a navigation by bar some PHP code that either shows a inline login form or the users username. The login form is submit using jQuery so no page load is required to set the users session variables etc. but how can I get around not having to refresh the page so that the correct text is shown (i.e. the users username rather than the inline form)?
At the moment the login works seamlessly without having to refresh the page but I need to somehow update that area also.
<div id="divLogin">
<?php if (!logged_in()) { ?>
<div class="form-group">
<input type="text" placeholder="Email" class="form-control" id="user">
</div>
<div class="form-group">
<input type="password" placeholder="Password" class="form-control" id="pass">
</div>
<button type="button" class="btn btn-success" id="login">Sign in</button>
<button type="button" class="btn btn-primary" id="register">Register</button>
<?php } else { ?>
<div class="form-group">
<p>You are logged in as <strong><?php echo $_SESSION['user']; ?></strong></p>
</div>
<?php } ?>
</div>
You can do that using load() function or by using AJAX.
$('.your_button').on('click', function(){
$('#divLogin').load('your_page_url_here');
});
I have a demo-employee.php page that retrieves all the users of the system alongside specific actions that can be performed:
<td><table>
<tr>
<td><i class="fa fa-pencil-square-o"></i></td>
<td></i></td>**
<td><i class="fa fa-trash-o"></i></td>
</tr>
</table>
</td>**
I am using data-featherlight to pop up the page demo-change-passowrd.php, upon clicking the link the user gets this form:
<form id="changePwd" name="formPwd" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" accept-charset="UTF-8">
<p>Please fill all the mandatory (*) fields.</p>
<div class="question">
<input type="password" name="new_pwd" pattern="^.*(?=.{6,})(?=.*[a-zA-Z])[a-zA-Z0-9]+$" title="Your new Password is required" required/>
<label><?php echo "<font color='red'>New Password(*):</font>" ?></label>
</div>
<div class="question">
<input type="password" name="confirm_pwd" pattern="^.*(?=.{6,})(?=.*[a-zA-Z])[a-zA-Z0-9]+$" title="Confirm Password field is required" required/>
<label><?php echo "<font color='red'>Confirm Password(*):</font>" ?></label>
<span class="required" id="doesNotMatch"></span>
</div>
<center>
<input type="submit" name="submit" onclick="checkPwdMatch();" onsubmit="return closeSelf(this);" value="Submit" />
<input type="hidden" name="user_id" id="user_id" value="<?php echo $user_id; ?>" />
</center>
</form>
I have a method to check if the pwdmatches, and upon successfully submitting the form, it should close with this method which is appended # the bottom of the page
function closeSelf(f){
f.submit()
window.close();
}
Also I moved this from the button to the form onsubmit="return closeSelf(this);", still no luck. Upon submitting the form, it just stays on the demo-change-passowrd.php. I also used window.location.replace to the demo-employeed page instead of window.close(), no luck as well. Can someone help please, I did
$("#myform").submit(function(e) {
//prevent Default functionality
e.preventDefault();
window.close();
Still no luck? am I missing something please?
I added an onsubmit attribute to form that would call 'click' on the close button (which has the class featherlight-close).
<form ... onsubmit="$('.featherlight-close').click()">