I was trying to make a website that authenticates with the local unix accounts of the server but pam_auth always returns false i.e. I always get Welcome error when I submit the form.
Here is my code:
<html>
<body>
<form id="a" method="post" action="welcome.php">
<input name="user" type="text">
<input name="pass" type="password">
<button type="submit">
</form>
</body>
</html>
welcome.php:
<html>
<body>
<p>Welcome
<?php
if(pam_auth($_POST['user'], $_POST['pass'])) {
echo $_POST['user'];
} else {
echo "error";
}
?></p>
</body>
</html>
Any replies are much appreciated.
Related
I wrote my index.php file, its this:
<?php // index.php
if(isset($_SESSION['login_user'])) {
header("location: profile.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Bejelentkezés</title>
</head>
<body>
<div>
<div>
<h1>Wellis adatok</h1>
<div>
<h2>Bejelentkezés</h2>
<form action="login.php" method="post">
<label>Felhasználó neve :</label>
<input id="name" name="userName" placeholder="név" type="text"></br></br>
<label>Jelszó :</label>
<input id="password" name="password" placeholder="**********" type="password" style="width: 80px"></br></br>
<input name="submit" type="submit" value=" Login ">
<span><?php echo $error; ?></span>
</form>
</div>
</div>
</div>
<p>
</br>
Listák megtekintése:
<?php
include("functions.php");
welcome();
?>
</p>
</body>
</html>
Also there is an other: functions.php, where are lots of functions. One of those is this:
<?php // functions.php
function welcome() {
echo "Welcome here ...";
}
...
?>
I wanna run that welcome() method there. This is only sample but orhers are same like this. I wanna see welcome message below login fields and submit button.
The page is hungarian but the page works well except this probleme.
Thanks for quick help ...
I'm pretty new to php and have been trying to create a site using it. I have created a login page and am trying to provide the option to create a new user by inserting a username & pass into the DB. I feel like this is something simple that I'm missing but i'm not sure so hopefully someone can help :)
php ~
<?php
session_start();
unset($_SESSION["currentUser"]);
unset($_SESSION["currentUserID"]);
if (isset($_POST["action"]) && $_POST["action"]=="create") {
$formUserC=$_POST["name"];
$formPassC=$_POST["pword"];
include("dbConnect.php");
$dbQuery=$db->prepare("select * from users");
$newAcc = "INSERT INTO users (username, password) VALUES ('$formUserC', '$formPassC')";
if($newAcc){
echo "<p>Your account was successfully created.";
}
else{
echo "<p>Error</p>";
}
}
if (isset($_POST["action"]) && $_POST["action"]=="login") {
$formUser=$_POST["username"];
$formPass=$_POST["password"];
include("dbConnect.php");
$dbQuery=$db->prepare("select * from users where username=:formUser");
$dbParams = array('formUser'=>$formUser);
$dbQuery->execute($dbParams);
$dbRow=$dbQuery->fetch(PDO::FETCH_ASSOC);
if ($dbRow["username"]==$formUser) {
if ($dbRow["password"]==$formPass) {
$_SESSION["currentUser"]=$formUser;
$_SESSION["currentUserID"]=$dbRow["id"];
if (isset($_SESSION["homePage"]))
header("Location: addToBasket.php");
else header("Location: homePage.html");
}
else {
header("Location: login.php?failCode=2");
}
} else {
header("Location: login.php?failCode=1");
}
} else {
?>
html (mostly) ~
<html >
<head>
<meta charset="UTF-8">
<title>Flat HTML5/CSS3 Login Form</title>
<link rel="stylesheet" href="css/loginstyle.css">
</head>
<body>
<div class="login-page">
<div class="form">
<form class="register-form" name="create" method="post" action="login.php">
<input type="text" name="name" placeholder="name"/>
<input type="password" name="pword" placeholder="pword"/>
<input type="hidden" name="action" value="create">
<input type="submit" value="create"/>
<p class="message">Already registered? Sign In</p>
</form>
<form name="login" method="post" action="login.php">
<input type="text" name="username" placeholder="username"/>
<input type="password" name="password" placeholder="password"/>
<input type="hidden" name="action" value="login">
<input type="submit" value="login"/>
<p class="message">Not registered? Create an account</p>
</form>
<?php
if (isset($_GET["failCode"])) {
if ($_GET["failCode"]==1)
echo "<h3 style='color:red;'>Invalid username entered</h3>";
if ($_GET["failCode"]==2)
echo "<h3 style='color:red;'>Invalid password entered</h3>";
}
?>
</div>
</div>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="js/loginindex.js"></script>
</body>
</html>
<?php
}
?>
P.S. some of it's code I nabbed from others. Thanks in advance.
I do apologise in advance for my lack of knowledge in PHP and HTML. I have scoured the internet for 3/4 days trying to create what is probably a simple system. I need the user to enter a digit before the next page is loaded. I have an IF statement on my page.
1.php
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/reset.css" rel="stylesheet" type="text/css" />
<div id="container">
<div id="authorise">
<form action="2.php" method="post">
<!--Product Comment Box--><br>
<p>Please enter your 4<br> digit authorisation code:<br> <br>
<input type="text" name="digits" />
<input type="submit" name="submit" />
</form>
</div>
</div>
2.php
<?php
if ($_POST['digits'] === '210392')
{echo 'https://www.facebook.com/'
?>
But I need a form first which the user would input the code '210392' and press submit. Then the if statement can take place. I know how to do a form but dont know how to assign that form a variable name 'digits'. All help is appreciated.
A basic form:
<form action="your_file.php" method="post">
<input type="text" name="digits" />
<input type="submit" name="submit" />
</form>
Then in your_file.php:
<?php
if ($_POST['digits'] === '210392') {
// etc.
$_POST is a superglobal array that has all data POSTed to your script. digits in this case is an index in that array. It comes from the name of the input field.
<form action="check.php" method="POST">
<input type="text" name="digits" />
<input type="submit" value="click here" />
</form>
//in check.php
if (isset($_POST['digits']) and $_POST['digits'] == 12345){
header("Location: http://google.com");
}
else {
echo " error !!";
}
study html from w3school
http://www.w3schools.com/html/html_forms.asp
and php
http://www.w3schools.com/PhP/php_forms.asp
<form action="https://scm-intranet.tees.ac.uk/users/l1071039/bobbin/admin.php" method="post">
Password : <input type="password" name="pwd" />
<input type="submit" name="send">
</form>
// admin.php
<?php
if( isset($_POST['pwd']) ){
$pwd = $_POST['pwd'];
}
?>
You first need to create an input with the very important name attribute which you'll use later.
<form method="post">
<input type="password" name="mypassword" />
<button type="submit">Go</button>
</form>
PHP:
//Post method access with $_POST variable:
if ($_POST['mypassword'] == 'my-password') { //Oh, you should probably use SSH and hash the password
//Hooray!
}
Instead of echo, use header.
<?php
if ($_POST['digits'] === '210392')
{
header (loaction:https://www.facebook.com/);
}
?>
I have a log-in form on a webpage and I want users to be able to log-in or register. At the top of the page I have the PHP script with the conditional testing for which submit button was pressed. The Log-in portion works fine. The "Register" portion works (meaning, it gets into the if-statement), but it doesn't redirect to my register.php site. Any thoughts?
I've tried changing the order of the if/elseif statements but to no avail. I get no warnings from this script, but it just reloads the page rather than redirecting to register.php.
To see the actual webpage, go here.
<?php
$error = '';
session_start();
ob_start();
if (isset($_POST['register'])) {
header("http://www.mynextbit.com/authenticate/register.php");
}
elseif (isset($_POST['login'])) {
session_start();
$username = trim($_POST['username']);
$_SESSION['user'] = $username;
$password = trim($_POST['pwd']);
// location to redirect on success
$redirect = 'http://www.mynextbit.com/Pages/newtemplateTEST.php';
require_once('../includes/authenticate_mysqli.inc.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
...
And, the HTML FORM...
<?php
if ($error) {
echo "<p>$error</p>";
}
if (!$_SESSION['user']) { ?>
<font color="red"><i><userlogin>Please Log In</userlogin></i></font><br />
<form id="form1" method="post" action="" style="margin-left: 15px">
<label for="username" ><font size="-1">Username:</font></label>
<input type="text" name="username" id="username">
<br />
<label for="pwd"><font size="-1">Password:</font></label>
<input type="password" name="pwd" id="pwd">
<br />
<input name="login" type="submit" id="login" value="Log in" style="display:inline"> or
<input name="register" type="submit" id="register" value="Register" style="display:inline">
</form>
<?php } ?>
Check out here. http://php.net/manual/en/function.header.php
Use the header with the location as like this header('Location: http://www.example.com/');
header('Location:http://www.mynextbit.com/authenticate/register.php');
It should work.
Thanks
Try this:
if (isset($_POST['register'])) {
header("Location:http://www.mynextbit.com/authenticate/register.php");
}
See Reference
Perhaps, from what I see from the PHP documentation, the function HEADER must have a "location" like such?
<?php
header("Location: http://www.example.com/"); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
That should fix your problem, I tried it and it actually redirects :P
Also (not really needed, but sometimes recommended), you may use HEREDOCS if you don't want to have too many php tag openers and closers.
Example for your code:
<?php
if ($error) {
echo "<p>$error</p>";
}
if (!$_SESSION['user']) {
echo <<<FORM
<font color="red"><i><userlogin>Please Log In</userlogin></i></font><br />
<form id="form1" method="post" action="" style="margin-left: 15px">
<label for="username" ><font size="-1">Username:</font></label>
<input type="text" name="username" id="username">
<br />
<label for="pwd"><font size="-1">Password:</font></label>
<input type="password" name="pwd" id="pwd">
<br />
<input name="login" type="submit" id="login" value="Log in" style="display:inline"> or
<input name="register" type="submit" id="register" value="Register" style="display:inline">
</form>
FORM;
}
?>
I am new to PHP (in-fact I am learning it). I am trying to get the value of textbox defined in HTML and print it on HTML page through PHP code. I am able to send the value of textbox to another page using form post and getting it using $_POST['name'] on other page.
I am not able to print the value of textbox on same page.
Here is my code:
<html>
<head>
<?php
function myfunction()
{
printf($_POST['fname']);
}
?>
</head>
<body>
Name: <input type="text" name="fname" />
<input type="button" onClick="myfunction()" value="Click" />
</body>
</html>
First of all it's not required to write php function within <head> tags. Second,
you can't POST data without <form> tags. try this
<?php
if(isset($_POST['submit']) && $_POST['submit']=='Submit'){
$name=$_POST['fname'];
echo $name;
}
else {
?>
<html>
<head>
</head>
<body>
<form method="POST" action="<?=$_SERVER["PHP_SELF"]?>">
Name: <input type="text" name="fname" />
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>
<?php } ?>
you can not call PHP function by button's click event...
if you want to print on same page then you can do by below code..
<html>
<?php
if(count($_POST)>0){
echo $_POST['fname'];
}
?>
<body>
<form method='post'>
Name: <input type="text" name="fname" />
<input type="submit" value="Click" />
</form>
</body>
</html>
hope you will get what you want by my answer..