• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

simple PHP Authentication development

i looking for a compound state to authenticate a user with a predifined input such as username and password without the use of database.. once the input is correct the user will be redirected to a given link . I can up with something like the php code below. something is wrong with the code though it wouldnt work i am still learning. I need soem one to come up with something similar but would accomodate more user andof course work.
<?php 
$userid = $_POST['userid'];
$password = $_POST['password'];


if ( ($userid == 'thomas') && ($password -- 'hayes1') )
{
  echo "<script>location.replace('accountaccess/richard/www.ban/AccountSummary.htm');</script>";
exit;
}

else {echo "<script>location.replace('signonerr.html');</script>";
exit; }?>

Open in new window

0
missionon
Asked:
missionon
1 Solution
 
animesxplosionCommented:
<?php
$userid = $_POST['userid'];
$password = $_POST['password'];

if ( $userid == 'thomas' &&($password == 'hayes1' )
{
header('Location: accountaccess/richard/www.ban/AccountSummary.htm');
exit;
}
header('Location: signonerr.html');
exit; }?>
0
 
InsoftserviceCommented:
hi,


<?php
$userid = $_POST['userid'];
$password = $_POST['password'];


if ( ($userid == 'thomas') && ($password -- 'hayes1') )
{
 $uri ="complete path if success";
        header("Location:$uri");

exit;
}

else {
$uri ="complete path if fails";
        header("Location:$uri");
exit;
 }?>

 

0
 
animesxplosionCommented:
O script acima está com erro  use esse!!

<?php
$userid = $_POST['userid'];
$password = $_POST['password'];

if ( $userid == 'thomas' && $password == 'hayes1' )
{
header('Location: accountaccess/richard/www.ban/AccountSummary.htm');
exit;
}
header('Location: signonerr.html');
exit; }?>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
animesxplosionCommented:
I tested the above script and was not working

Here it is tested

lol

<?php
$userid = $_POST['userid'];
$password = $_POST['password'];

if ( $userid == 'thomas' && $password == 'hayes1' )
{
header('Location: accountaccess/richard/www.ban/AccountSummary.htm');
exit;
} else {
header('Location: signonerr.html');
exit; }
?>
0
 
Ray PaseurCommented:
@missionon, when you are not sure how a PHP command works, you can use the search box in top right of the webpage to look up the functions.  Example here:
http://us3.php.net/manual/en/function.header.php

What you are trying to do has "been done" before and you might want to learn from good examples of others.  I recommend this book to you.  It teaches EXACTLY how to do what you want, with good examples and step-by-step instructions, plus it comes with a code library that allows you to download the examples.
http://www.sitepoint.com/books/phpmysql4/

In the instant case if you want to add more possible users you might consider an array of userids and passwords.  You would take the input fields and iterate over the array with foreach.  When you found a match, you would set the userid in the Session array and use the header() to redirect to the appropriate page.  If you fell out of the foreach iterator loop, you would put up the "login failed" page.

best regards, and please invest in that book, ~Ray
0
 
missiononAuthor Commented:
I found addedd other user using the elseif statement. You have have been helpful
<?php
$userid = $_POST['userid'];
$password = $_POST['password'];

if ( $userid == 'thomas' && $password == 'hayes1' )
{
header('Location: accountaccess/richard/www.ban/AccountSummary.htm');
exit;
}

elseif ( $userid == 'james' && $password == 'police1' )
{
header('Location: accountaccess/james/www.ban/AccountSummary.htm');
exit;
}

 else {
header('Location: signonerr.html');
exit; }
?>

Open in new window

0
 
InsoftserviceCommented:
hi missionon,



May i know whats the issue in my code. same code has been accepted  i want a clarification for it.


code.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now