Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
i want display all with session what i enter into input.. but only one shows .. i want display past results too with session.. here my codes;
<form method="post">
isim gir
<input type="text" name="isim" id="isim[]" />
<input type="submit" name="gir" value="sözler" />
</form>
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if(isset($_POST["gir"])){
$isim=$_POST["isim"];
echo $_SESSION["name"]=$isim;
}
?>
Create a search_history session variable that contains an array of all the searches.
if (!isset($_SESSION['search_history'])) {
$_SESSION['search_history'] = array();
}
if (isset($_POST['gir'])) {
$isim = $_POST['isim'];
$_SESSION['search_history'][] = $isim;
}
session_start() should be placed first thing in your code, and if you want to print everything in the array of $_SESSION you can do:
echo "<pre>",print_r($_SESSION),"</pre>";
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$sanitize_post = filter_input_array(INPUT_POST);
if(!empty($sanitize_post)){
$_SESSION['input'][] = $sanitize_post;
}
function reducer($acc, $val)
{
return $acc .= $val;
}
function allUserInput()
{
# Extract user input from session.
if(empty($_SESSION)) return;
foreach ($_SESSION['input'] as $key) {
echo "<li>".array_reduce($key, 'reducer', '')."</li>";
}
}
?>
<form method="POST">
<ul><?php echo allUserInput(); ?></ul>
<input type="text" name="isim" id="isim" />
<input type="submit" name="gir" value="sözler" />
</form>
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 months ago.
Improve this question
I don't know PHP and have downloaded this code that works perfectly fine.
I add this code on top of any *.php file and it makes that page, password protected that only opens up if you type the password which in this case is 1234.
Now, I want to add 3 passwords instead of 1. I just don't know where to edit this code.
<?php
session_start();
if(isset($_POST['submit_pass']) && $_POST['pass'])
{
$pass=$_POST['pass'];
if($pass=="1234")
{
$_SESSION['password']=$pass;
}
else
{
$error="Incorrect Pssword";
}
}
if(isset($_POST['page_logout']))
{
unset($_SESSION['password']);
}
?>
<?php
if($_SESSION['password']=="1234")
{
?>
<form method="post" action="" id="logout_form">
<input type="submit" name="page_logout" value="Logout">
</form>
<?php
}
else
{
?>
<form method="post" action="">
<div>Protected Content</div>
<br />
<input type="password" name="pass" placeholder="Type your password">
<input type="submit" name="submit_pass" value="Login">
<br /><br />
<div><?php echo $error;?></div>
</form>
<?php
}
?>
Where should I, add what, to be able to have 3 possible passwords?
For this, you may edit password checking line like this:
<?php
session_start();
if(isset($_POST['submit_pass']) && $_POST['pass'])
{
$pass=$_POST['pass'];
$available_passwords = ['12345','pass123','myOtherPassword'];
if(in_array($pass,$ava_passwords))
{
$_SESSION['password']=$pass;
}
else
{
$error="Incorrect Pssword";
}
}
if(isset($_POST['page_logout']))
{
unset($_SESSION['password']);
}
?>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
im trying to make a basic login script that requires the correct input to be used in order to login. I also want my script to bring up an error if the wrong details are input.
I have looked around but i can't seem to find a fix for this as i don't want to use MySQL.
I want to stick to html/PHP also.
I have the basic display of the login script:
<p><b>Please Login</b></p>
<form action="useraccess.php" method="post">
Username: <input type="text" name="username"/></br>
Password: <input type="password" name="pass"/></br>
<input type="submit" value="login"/>
</form>
If anyone could help me out here that would be greatly appreciated!
cheers.
This is simple. Something like that:
<p><b>Please Login</b></p>
<form action="useraccess.php" method="post">
Username: <input type="text" name="username"/></br>
Password: <input type="password" name="password"/></br>
<input type="submit" name="submit"/>
</form>
<?php
session_start();
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
if($username === 'admin' && $password === 'password'){
$_SESSION['loginsuccess'] = true;
header('location:accesssite.php');
die();
}
}
useraccess.php
session_start();
$username = 'admin';
$password = 'pass';
$error = '';
if($_POST['username'] != $username) $error .= 'Wrong username!<br>';
if($_POST['pass'] != $password) $error .= 'Wrong username!<br>';
if(!empty($error) {
$_SESSION['error'] = $error;
header('Location:form.php'); //your login script
}
...
continue as logged user
then in form.php (your login script)
<?php
session_start();
if(!empty($_SESSION['error'])) echo $_SESSION['error']; ?>
....
....
Your login script
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Creating a Client Login area. I have my log in form in a clientLogin.html:
<form name="ClientLogin" method="post" action="login.php"> <br>
<p>
<label for='Username'>Username</label> <br>
<input type="text" name="username" />
</p>
<p>
<label for='Password'>Password</label> <br>
<input type="password" name="password" />
</p>
<br>
<input type="submit" value="Submit" />
</form>
If the username & password combination are incorrect I want to redirect to this page adding a message saying "incorrect username/ password please try again". This is the code from login.php:
<?php
//Connect to the database
require('db.php');
$user = mysql_real_escape_string($_POST["username"]);
$pass = mysql_real_escape_string($_POST["password"]);
$clientdata = mysql_query("SELECT * FROM Users WHERE username='$user' and password='$pass'")
or die (mysql_error());
$data = mysql_fetch_array($clientdata, MYSQL_ASSOC);
if(mysql_num_rows($clientdata) == 1){
session_start();
$_SESSION['username'] = $user;
header('Location: profile.php');
}else{
header('Location: clientLogin.html');
}
I expect the clientLogin.html files needs changing to a .php file. other than that I am stumped. Any guidance would be greatly appreciated.
You can set a SESSION flag and when calling ClientLogin.
$_SESSION['loginerror'] = 1;
in ClientLogin.php
if ($_SESSION['loginerror'] > 0) {
/* Display Appropriate Error message */
}
You need to change extension of clientLogin.html from .html to .php
Change header('Location: clientLogin.html'); to header('Location: clientLogin.php');
Add this part of code at the top of your clientLogin.php page:
<?php
session_start();
if(empty($_SESSION['username'])) {
echo 'incorrect username/ password please try again.' ;
}
?>
you should use exit(); after redirecting to other file like..
header('Location: profile.php');
exit();
you please use mysqli instead of mysql .its not going to be supported by
new version of php.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm tried to put ajax form in while element, but not work.
Probably can not be repeated id in ajax form.
<?php while(..){ ?>
<form id="cancel-server" action="process.php" method="POST">
<input type="hidden" name="task" value="cancel-server" />
<input type="hidden" name="serverid" value="<?php echo $row['sid']; ?>" />
<button type="submit" id="ah">
<i class="icon-remove"></i> Otkaži narudžbinu
</button>
</form>
<?php } ?>
jquery:
$('#cancel-server').ajaxForm({
success: function(result){
var result=trim(result);
if(result=='success'){
$.poruka('', 'Success!');
}else{
$.poruka('', result);
}
}
});
php:
case 'cancel-server':
$serverid = $_POST['serverid'];
query_basic("DELETE FROM `serveri_naruceni` WHERE `id` = '".$serverid."'");
echo 'success';
break;
try to use the following snippt of code :
<script>
function _Submit(form){
$('#cancel-server'+form.id).ajaxForm({ }););
return false;
}
</script>
<form id="cancel-server<?php echo $row['id']; ?>" action="process.php" method="POST" onsubmit="javascript: return _Submit(this);">
...
</form>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
If the login code is validated, I should go into the member page otherwise I should say on the same page..I am not sure how to write a navigation link to another page..I have seen couple of answers using headers but I didn't get it.
login.php
if($username==$dbusername&&$password==$dbpassword)
{
// If this condition is true I should go into member page
}
else
{
echo "incorrect password!"; //should stay in the same page
}
form action= "member.php" method="post"
Username: input type="text" name="username"<br/>
Password: input type="password" name="password"<br/>
input type="submit" value="LogIn"><br/><br/>
Simply use header like this:
if($username==$dbusername&&$password==$dbpassword)
{
header("location:member.php");
}
If you want a delay in the redirect you can use this:
header("Refresh: 5;url=klanten.php");
(this will wait 5 seconds before redirecting)
What you want to do can be achieved by posting to the same page, login.php
Before any html, check:
if (isset($_POST['username'])) {
if($username==$dbusername && $password==$dbpassword) {
header("location: member.php");
}
}
header("location: member.php") simply redirects to member.php if condition true.
So the form would look something like this:
form action="login.php" method="post">
Username: <input type="text" name="username" />
Password: <input type="password" name="password" />
<input type="submit" value="LogIn" />
</form>