Trying to write form of registration.
<?php
include_once 'core.php';
if (User::IsAuthorization()) {
header("Location: /");
}
if(!is_null($_POST["Registration"])){
User::Registration($_POST["login"], $_POST["password"]);
$user = new User();
$user->Authorization($_POST["login"], $_POST["password"]);
$user->SetSession();
header("Location: /");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Регистрация</title>
</head>
<body>
<form action="registration.html" method="POST">
<input type="text" name="login" placeholder="login">
<input type="password" name="password" placeholder="password">
<input type="submit" value="Регистрация" name="Registration">
</form>
</body>
</html>
This form works correctly on my friend's laptop. But in my case, the output contains come code of php. I use denwer as local server.
it contains this code(but it doesn't have to):
Authorization($_POST["login"], $_POST["password"]); $user->SetSession(); header("Location: /"); } ?>
Link to picture: http://s23.postimg.org/5vv204qor/Capture.png
Simply start your server and use localhost to show it on webpage.
It should shows the same page as the one being shown on your fd's laptop.
If it does not, it probably forgot to include or change html to php in the file name.
Thanks
Related
newbie here...
so yeah, i already tried searching all those page-related about my question, but im still stuck...
anyway, my problem is that i always keep getting back at my login page, which is my index.php
oh btw, im still using PHP version 4.4.8
here is my code for my problematic main page, main.php
<?php
session_start();
include '../config.php';
if(!isset($_SESSION['admin'])){
header("location:index.php");
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>KSP Setia Finance</title>
</head>
<body>
<h1>test page</h1>
</body>
</html>
and here is my login page code, which is index.php
<?php
session_start();
include '../config.php'; ?>
<!DOCTYPE html>
<html >
<head>
<title>Login Form</title>
</head>
<body>
<div class="login">
<h1>Login</h1>
<form action="login_act.php" method="post">
<input type="text" name="username" placeholder="Username" required="required" />
<input type="password" name="password" placeholder="Password" required="required" />
<button type="submit" name="login" value="Login" class="btn btn-primary btn-block btn-large">Log In</button>
</form>
</div>
<script src="js/index.js"></script>
</body>
</html>
since everyone asking, here my login_act.php, already inserted with session_start
<?php
session_start();
include('../config.php');
if(isset($_POST['login'])){
$user = mysql_real_escape_string(htmlentities($_POST['username']));
$pass = mysql_real_escape_string(htmlentities(md5($_POST['password'])));
$sql = mysql_query("SELECT * FROM user WHERE username='$user' AND password='$pass'") or die(mysql_error());
if(mysql_num_rows($sql) == 0){
echo 'User not found';
}else{
$row = mysql_fetch_assoc($sql);
if($row['level'] == 1){
$_SESSION['admin']=$user;
echo '<script language="javascript">alert("u are Login as Admin!"); document.location="index.php";</script>';
}else
echo 'sorry, u cant access this one';
}
}
?>
print value of $_SESSION on main.php and check if there is any key as 'username' and check login.php, what values are you storing in $_SESSION array
so i recently asking my friends, and here is the results:
all i need is just put those $SESSION_START above all, or make another php and link them all. so here my latest result that worked :
main.php
<?php
include 'access.php';
?>
<!DOCTYPE HTML>
<html>
<head>
<title>KSP Setia Finance</title>
</head>
<body>
<h1>test page</h1>
</body>
</html>
access.php
<?php
session_start();
if(!isset($_SESSION['admin'])){
echo '<script language="javascript">alert("you must Login!"); document.location="../index.php";</script>';
}
?>
and last, config.php
<?php
session_start();
mysql_connect("localhost","root","");
mysql_select_db("koperasi");
?>
i deleted that broken login_act.php, and making all the page i had to be linked directly with the access.php, which make it easier to manage the session. thank you to all that bear with my php problem and stupidity. hope this all gonna help those who still wandering and asking the same question.
Hi guys i have three simple php pages login.php,process.php and login_success.php.The problem is that login.php and process.php is present in my localhost:8080 but login_success.php is present at 192.168.1.36:8080 but on same lan.I am perfectly accessing my login.php but on clicking button it is not displaying login_success.php.I am using XAMPP server and it is installed in both the systems.The other thing is that i am accessing logout_success.php through url directly for e.g. http://192.168.1.36/xampp/logout_success.php. My code is very simple All my code is as follows:
Login.php:
<form action="process.php" method="POST">
username:<input type="text" name="username"/>
<br/>
password:<input type="password" name="pass"/>
<br/>
<input type="submit" value="Login!"/>
</form>
Process.php:
<?php
$username = $_POST['username'];
$password = $_POST['pass'];
if($username == 'test' AND $password == 'test')
{
header('Location : http://192.168.1.36/xampp/logout_success.php');
}
else
{
echo "You have not logged in,username or password is incorrect!";
}
?>
Login_success.php:
<html>
<body>
Logout Success<br>
Thanks for using the Captive Portal...
</body>
</html>
Can anyone tell me how to access login_success.phppage.Any help would be greatly appreciable.
Got a white space within the header call.
Change
header('Location : http://192.168.1.36/xampp/logout_success.php');
to
header('Location: http://192.168.1.36/xampp/logout_success.php');
Entire Code:
index.php
<form action="process.php" method="POST">
username:<input type="text" name="username"/>
<br/>
password:<input type="password" name="pass"/>
<br/>
<input type="submit" value="Login!"/>
</form>
process.php
<?php
$username = $_POST['username'];
$password = $_POST['pass'];
if($username == 'test' AND $password == 'test')
{
header('Location: login_success.php');
}
else
{
echo "You have not logged in,username or password is incorrect!";
}
?>
login_success.php
<html>
<head></head>
<body>
Logout Success<br>
Thanks for using the Captive Portal...
</body>
</html>
Make sure the file names are right (lowercase). I have tried it on my test server and it seems to work. (http://jagmit.co.uk/test/php_login/)
Also, i just would like to remind you that this is a bad example of how NOT to implement a login security system.
Use relative paths
header('Location : ./logout_success.php');
Hello, I am having trouble with some of my code. Even my teacher can't help me, and I don't know where else to go. When my foreach loop is activated and the password and username are the same as the hard-coded strings, it is still redirecting to loginerror.php. When I remove header("Location: loginerror.php"), it functions fine. Why is the last line of my code still activated, when it should load a new page?
<?php session_start(); ?>
<html>
<header></header>
<body>
<form action="login.php" Method="post">
Username: <input type="text" name="Username"> </br></br>
Password: <input type="password" name="Password"> </br></br>
<input type="submit" value="Login"></br></br>
</form>
<?php
$username=$_POST["Username"];
$password=$_POST["Password"];
if($username == NULL){print("Enter a Username please");}
else {
$users= array
(
"Bourne"=>"postcode",
"Unidan"=>"pincode",
"yoda"=>"sith"
);
foreach($users as $user=>$password_value)
{
if(($user==$username)&&($password_value==$password))
{
$_SESSION['login?']=1;
header("Location: calculation.php");
}}
$_SESSION['login?']=0;
header("Location: loginerror.php");
}
?>
</body>
</html>
Per the PHP Docs:
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called.
Reference: Header Documentation
Move your PHP code to the top of the file and it should solve your problem:
<?php
session_start();
$username=$_POST["Username"];
$password=$_POST["Password"];
if ($username == NULL) {
print("Enter a Username please");
} else {
$users= array("Bourne"=>"postcode", "Unidan"=>"pincode", "yoda"=>"sith");
foreach($users as $user=>$password_value) {
if(($user==$username)&&($password_value==$password)) {
$_SESSION['login?']=1;
header("Location: calculation.php");
// Add this to terminate the script immediately and redirect.
exit();
}
}
$_SESSION['login?']=0;
header("Location: loginerror.php");
// Add this to terminate the script immediately and redirect.
exit();
}
?>
<html>
<header></header>
<body>
<form action="login.php" Method="post">
Username: <input type="text" name="Username"> </br></br>
Password: <input type="password" name="Password"> </br></br>
<input type="submit" value="Login"></br></br>
</form>
</body>
</html>
Header's must be sent before any output, including HTML output.
exit so no other code is executed after the redirect:
header("Location: calculation.php");
exit;
Changing your code structure to something like this may help you.
Note: this is not code correction.
<?php
session_start();
$username=$_POST["Username"];
$password=$_POST["Password"];
if($username == NULL){
print("Enter a Username please");
}
else {
$users= array
(
"Bourne"=>"postcode",
"Unidan"=>"pincode",
"yoda"=>"sith"
);
foreach($users as $user=>$password_value)
{
if(($user==$username)&&($password_value==$password))
{
$_SESSION['login?']=1;
header("Location: calculation.php");
exit;
}
}
$_SESSION['login?']=0;
header("Location: loginerror.php");
exit;
}
?>
<html>
<header></header>
<body>
<form action="login.php" Method="post">
Username: <input type="text" name="Username"> </br></br>
Password: <input type="password" name="Password"> </br></br>
<input type="submit" value="Login"></br></br>
</form>
</body>
</html>
Like it was mentioned prior. You are already outputting prior to sending headers.
You need to wrap this in a conditional or have a second script checking the password.
You could wrap the code in if/else $_POST as well as break operation in foreach after the condition was met.
i have login page if my username and password is incorrect it will display the error message using different page. i am using separate page for that. how can i display error message in login page itself.
login
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<html>
<head>
<title> PHP Login </title>
</head>
<body>
<center>
<form method=”post” action=”login.php”>
<table>
<tr><td>Username:</td><td><input type=”text” name=”usr”></td></tr>
<tr><td>Password:</td><td><input type=”password” name=”pswd”></td></tr>
<tr><td><input type=”submit” name=”login” value=”Login”></td>
<td><input type=”reset” name=”reset” value=”Reset”></td></tr>
</table>
</form>
</center>
</body>
</html>
Controller
<?php
session_start();
if($_REQUEST['usr']==”ABC” && $_REQUEST['pswd']==”123″){
$_SESSION['usr'] = “ABC”;
$_SESSION['pswd'] = “123″;
header(“Location: content.php”);
}
else{
header(“Location: niceform.php”);
}
?>
Your code contained invalid double-quotes.
I replaced all instances of “ and ” with " (standard double-quotes).
The cause is usually the result from copying/pasting code taken from the Web.
See reformatted code below.
To show an error message in login page, you can use any of the following:
Replace header("Location: niceform.php"); with echo "Sorry, no access;"
or with die("Sorry, no access"); or exit("Sorry, no access");
Sidenote:
You can use include 'content.php'; to include a file instead of redirecting with header()
This code has been tested and working.
HTML Form:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> PHP Login </title>
</head>
<body>
<center>
<form method="post" action="login.php">
<table>
<tr><td>Username:</td><td><input type="text" name="usr"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pswd"></td></tr>
<tr><td><input type="submit" name="login" value="Login"></td>
<td><input type="reset" name="reset" value="Reset"></td></tr>
</table>
</form>
</center>
</body>
</html>
login.php:
<?php
session_start();
if($_REQUEST['usr']=="ABC" && $_REQUEST['pswd']=="123"){
$_SESSION['usr'] = "ABC";
$_SESSION['pswd'] = "123";
header("Location: content.php");
// include 'content.php'; // optional, but delete the line above if using it.
}
else{
header("Location: niceform.php");
// include 'niceform.php'; // optional, but delete the line above if using it.
}
?>
Would you try this way
ob_start();
session_start();
if($_REQUEST['usr']==”ABC” && $_REQUEST['pswd']==”123″){
$_SESSION['usr'] = “ABC”;
$_SESSION['pswd'] = “123″;
header(“Location: content.php”);
}
else{
header(“Location: niceform.php”);
}
<?php
ob_start();
// First we execute our common code to connection to the database and start the session
define('MyConst', TRUE);
include('../database.class.php');
include('../table.class.php');
include('../user.class.php');
include('../loginattempts.class.php');
include('../timer.class.php');
include('../characters.class.php');
include('../weapontype.class.php');
include('../objects/weapons/weaponobject.class.php');
include('../objects/weapons/bowieknife.class.php');
include('../npc/enemy.class.php');
include('../npc/skinhead.class.php');
include('../npc.class.php');
include('../npctype.class.php');
include('../functions.php');
include('../loginf.php');
include('locationf.php');
$dbo = database::getInstance();
$dbo -> connect("***************", "********", "********", "***************", array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
secSessionStart();
// At the top of the page we check to see whether the user is logged in or not
if(empty($_SESSION['user']))
{
// If they are not, we redirect them to the login page.
header("Location: login.php");
// Remember that this die statement is absolutely critical. Without it,
// people can view your members-only content without logging in.
die("Redirecting to login.php");
}
$_SESSION['currentlocation'] = "combat.php";
?>
<?php
if($_POST['formSubmit'] == "Submit")
{
$varMovie = $_POST['formMovie'];
echo $varMovie;
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="index.php" method="post">
Which is your favorite movie?
<input type="text" name="formMovie" maxlength="50">
<input type="submit" name="formSubmit" value="Submit">
</form>
</body>
</html>
Ok...so its supposed to echo out some text. Instead it just reloads the form! I'm not sure what else to write and it won't allow me to post so i'm just going to repeat what i've wrote until i reach the limit.
Add an ELSE part in the HTML, that will either show the form OR the answer, but keeps the header etc intact.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
if($_POST['formSubmit'] == "Submit")
{
$varMovie = $_POST['formMovie'];
echo $varMovie;
}
else {
?>
<form action="index.php" method="post">
Which is your favorite movie?
<input type="text" name="formMovie" maxlength="50">
<input type="submit" name="formSubmit" value="Submit">
</form>
<?php } ?>
</body>
</html>
I would tend to use:
<?php
if (array_key_exists("formSubmit",$_POST) && !strcmp($_POST["formSubmit"],'Submit'))
{
$varMovie = $_POST['formMovie'];
echo "Movie=(${varMovie})<br>\n";
}
:
:
Also comment out all the includes etc. above this, check it's giving you the contents of formMovie then add the other stuff back in gradually until it fails (or not).
Cheers.