Login Script Problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Mexican Hat
Forum Newbie
Posts: 19
Joined: Sat Mar 08, 2003 8:35 pm
Location: Baltimore, Maryland
Contact:

Login Script Problems

Post by Mexican Hat »

Here is all the code I'm using for the login script but when I tried to login it says "Error on Page". Does anyone know whats wrong with the code.

Also is it possible to have different users login to different pages, insted of all users logining into the same page. How would you do this?

login.html:

Code: Select all

<form action="login.php" method="post">

Username: <input type="text" name="username" class="form"><br>
Password: <input type="password" name="password" class="form"><p>

<input type="button" name="login" value="login" onClick="go()">
login.php:

Code: Select all

<?php 
//function display_name() &#123;
// global $_POST&#1111;'username'];
//&#125;

function valid_login($username, $password) &#123; 
return ($username == 'username' && $password == 'password')
or ($username == 'admin' && $password == 'pass')
or ($username == 'name' && $password == 'word');
&#125; 

if ($_SESSION&#1111;'logged_in']= 1) &#123;
header( "Location: index.php" );
&#125;

session_start(); 

if ( valid_login($_POST&#1111;'username'], $_POST&#1111;'password']) ) &#123; 
$_SESSION&#1111;'logged_in'] = 1; 
header( "Location: index.php" );
&#125; 

else &#123;header( "Location: login.html" );&#125;

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

error on page where? on login.html? the javascript function go() probably doesn't exist, or has errors in it.

If you are in IE, double click the warning icon that shows in the status bar.

If you are in Mozilla/Firefox/Netscape, you hopefully have the javascript console installed, so you can see the errors..
User avatar
Mexican Hat
Forum Newbie
Posts: 19
Joined: Sat Mar 08, 2003 8:35 pm
Location: Baltimore, Maryland
Contact:

Post by Mexican Hat »

IE says the Error is "Object Expected" Anyone have any suggestions to fixing the problem and have different users login to different pages, insted of all users logining into the same page?
dwfait
Forum Contributor
Posts: 113
Joined: Sun Aug 01, 2004 10:36 pm

Post by dwfait »

why dont you use a MySQL table? Then just have a field, for each user, to have the page you want them to go to.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

Mexican Hat wrote:have different users login to different pages, insted of all users logining into the same page?
ok, what i would do is in your members / customres table which lists all the people registered for your site, have an extra field called access_level then.....

Code: Select all

if ($array['access_level'] == "standard")
{
// standard user
header("Location: index.php")
}
elseif ($array['access_level'] == "admin")
{
// administrator
header("Location: admin/index.php");
}
else
{
// somewhere here
}
etc etc
User avatar
Mexican Hat
Forum Newbie
Posts: 19
Joined: Sat Mar 08, 2003 8:35 pm
Location: Baltimore, Maryland
Contact:

Post by Mexican Hat »

I think I fixed the script error because none are showing up in ie but when I try to login it seems like its doesn't read the username and password and reset itself.

I'm also unsure what to do with the code that directs users to different pages. Here's the code I tried to use but still not working.

login.html:

Code: Select all

<script type="text/javascript">
function go()
&#123;
if ( (document.forms&#1111;'signin'].username.value != '') && (document.forms&#1111;'sign'].password.value != '') )
&#123;
return true;
&#125;
alert('All fields are required');
return false;
&#125;
</script>

<form name="signin" action="login.php" method="post" onsubmit="return go()">

Username: <input type="text" name="username" class="form"><br>
Password: <input type="password" name="password" class="form"><br>

<input type="submit" name="signin" value="login">
</form>
login.php

Code: Select all

<?php
//function display_name() &#123;
// global $_POST&#1111;'username'];
//&#125;

function valid_login($username, $password) &#123;
return ($username == 'log' && $password == 'pass')
or ($username == 'friendshipchurch' && $password == 'man217')
or ($username == 'murray' && $password == 'tenderloins');
&#125;

if ($array&#1111;'access_level'] == "standard") 
&#123; 
// standard user 
header("Location: index.php") 
&#125; 
elseif ($array&#1111;'access_level'] == "admin") 
&#123; 
// administrator 
header("Location: admin/index.php"); 
&#125; 
else 
&#123; 
// somewhere here 
&#125;

else &#123;header( "Location: login.html" );&#125;

?>
Post Reply