Page 1 of 1

Login Script Problems

Posted: Tue Aug 10, 2004 8:17 pm
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;

?>

Posted: Tue Aug 10, 2004 8:52 pm
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..

Posted: Wed Aug 11, 2004 8:56 am
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?

Posted: Wed Aug 11, 2004 8:58 am
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.

Posted: Wed Aug 11, 2004 9:00 am
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

Posted: Wed Aug 11, 2004 8:21 pm
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;

?>