Jump to content
The Uniform Server Community

Recommended Posts

Posted

can some one tell me what i am doing wrong with this code

 

config.php

<?php 
$username = array('Admin', 'User'); 
$password = array('adminpass', 'userpass'); 
?>

 

index.php

<?php 
require ("config.php"); 
session_start(); 
if ((!$username) || (!$password)) 
{ 
  echo '<form name=login method=post action=""> 
  user:<input type=text name=user><br> 
  pass:<input type=text name=pass><br> 
  <input type=submit value=go> 
  </form>'; 

} 
else 
{ 
  if($user==$username && $pass==$password) 
  { 
  session_register("username"); 
  session_register("password"); 

  echo "Congratulations &username, you have logged in!<br> 
  <a href=\"?logout=1\" >Logout</a>"; 

  } 
  else 
  echo "Incorrect Password please <a href=?index.php?>try again</a>"; 

} 
if($logout==1) 
{ 
  session_unregister("username"); 
  session_unregister("password"); 
} 
?>

IPB Image

 

IPB Image

if you like this Uniform Server User Sing take em i do not mind share

IPB Image

 

IPB Image

Posted

There are a few things wrong, the following gives you a clue what you need to do:

<?php
require ("config.php"); // load in array (name and password values)
session_start();

$userin = $_POST['user']; // get from poat
$passin = $_POST['pass']; // get from post

if ( !isset($userin) || !isset($passin)) // chect not set
{
?>
  <form name="login" method="post" action="index.php">
  Name: <input type="text" name="user" ><br>
  Pass: <input type="password" name="pass" ><br>
  <input type="submit" value="go">
  </form>
<?
}
else   //both are set, check for correct values
{
  // scan each array for a match using in_array function  
  if( in_array($userin, $username) && in_array($passin, $password))
  {
  session_register("$userin");
  session_register("$passin");

  echo "Congratulations $userin, you have logged in!<br>
  <a href=\"?logout=1\" >Logout</a>";

  }
  else // failed to match
  echo "Incorrect Name or Password please <a href=?index.php?>try again</a>";

}
if($logout==1)
{
  session_unregister("$userin");
  session_unregister("$passin");
}
?>

All the best

Ric :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...