Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

PHP Login Problem (Masters in PHP)

Hey guys, okay I have a problem with PHP $_POST.

The problem is I have a login.php page where I want a particular username and password will work on it and redirect to a member-index.php page.

And, if the particular username and password is not there it will redirect them to incorrect.php

I came up with this though,
Code
$login = "james";
$password = "zero";

if ($login=='james' $password = 'zero');
{
echo document.location("site/member-index.php");
}
else
{
echo document.location("site/login-failed.php");
}

Here is the main login portal

Code
<form action="login-exec.php" name="login"  method="post" id="loginform">
<p><label for="ID">ID:&nbsp;</label> <input maxlength="30" name="login" tabindex="1" class="ftext" type="text"></p>
<p><label for="PIN">PIN:&nbsp;</label> <input maxlength="30" name="password" tabindex="2" class="ftext" type="password"></p>
<p align="center"><input name="image" src="assets/images/layout/btn_login.gif" alt="Login" height="23" type="image" width="77"></p>
</form>

Thanks for any reply
(Jul 17, 2012 07:17 PM)Dark Angels Wrote:  Hey guys, okay I have a problem with PHP $_POST.

The problem is I have a login.php page where I want a particular username and password will work on it and redirect to a member-index.php page.

And, if the particular username and password is not there it will redirect them to incorrect.php

I came up with this though,
Code
$login = "james";
$password = "zero";

if ($login=='james' $password = 'zero');
{
echo document.location("site/member-index.php");
}
else
{
echo document.location("site/login-failed.php");
}

Here is the main login portal

Code
<form action="login-exec.php" name="login"  method="post" id="loginform">
<p><label for="ID">ID:&nbsp;</label> <input maxlength="30" name="login" tabindex="1" class="ftext" type="text"></p>
<p><label for="PIN">PIN:&nbsp;</label> <input maxlength="30" name="password" tabindex="2" class="ftext" type="password"></p>
<p align="center"><input name="image" src="assets/images/layout/btn_login.gif" alt="Login" height="23" type="image" width="77"></p>
</form>

Thanks for any reply

When you're echoing your "redirects", use
PHP Code

<?php 
header
("Location: where"); 

not document.location. That's javascript. And you're not getting the values from the form. You're just checking to see if $login = $login (true) and $pass = $pass (true). Your code is being redundant and not even checking what has been submitted in the form.
Here's the completely working code.... with some improvements.

PHP Code

<?php
$username 
= "james";
$password = "zero";
//since there's no database...
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
    if (
$_POST['username'] == $username && $_POST['password'] == $password)
    {
    
header('Location: ./site/member-index.php');
    }
    else{
        
$messages = 'Login failed.';
    }
}
//display the login form
echo $messages.'</br>';
echo 
'
<form action=""  method="post">
<p><label for="ID">ID:&nbsp;</label> <input maxlength="30" name="login" tabindex="1" class="ftext" type="text"></p>
<p><label for="PIN">PIN:&nbsp;</label> <input maxlength="30" name="password" tabindex="2" class="ftext" type="password"></p>
<p align="center"><input name="image" src="assets/images/layout/btn_login.gif" alt="Login" height="23" type="image" width="77"></p>
</form>
'
;
?>
PHP Code

<?php
ob_start
();
$login = "james";
$password = "zero";
if(isset(
$_POST['login']) && $_POST['login'] != "" && isset($_POST['password']) && $_POST['password'] != "" )
{
    if(
$_POST['login'] == "james" && $_POST['password'] == "zero")
    {
        
header("location:site/member-index.php");
    }
    else
    {
        
header("location:site/login-failed.php");
    }
}
?>
(Apr 22, 2017 05:08 AM)ankitagrawal Wrote:  
PHP Code

<?php
ob_start
();
$login = "james";
$password = "zero";
if(isset(
$_POST['login']) && $_POST['login'] != "" && isset($_POST['password']) && $_POST['password'] != "" )
{
    if(
$_POST['login'] == "james" && $_POST['password'] == "zero")
    {
        
header("location:site/member-index.php");
    }
    else
    {
        
header("location:site/login-failed.php");
    }
}
?>

Why set the $login and $password variable? I thought he was submitting it via $_POST


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by SkidyDec 3, 2015 05:30 AM 26 711 Dec 3, 2015 05:30 AM
Last Post: Viktory
[PHP] by RihanaSmithJun 20, 2013 09:54 AM 15 348 Jun 20, 2013 09:54 AM
Last Post: YERANUK
[PHP] by OsteeNJan 19, 2012 01:03 AM 8 267 Jan 19, 2012 01:03 AM
Last Post: BlueLight™