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
Mexican Hat
Forum Newbie
Posts: 19 Joined: Sat Mar 08, 2003 8:35 pm
Location: Baltimore, Maryland
Contact:
Post
by Mexican Hat » Tue Aug 10, 2004 8:17 pm
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() {
// global $_POSTї'username'];
//}
function valid_login($username, $password) {
return ($username == 'username' && $password == 'password')
or ($username == 'admin' && $password == 'pass')
or ($username == 'name' && $password == 'word');
}
if ($_SESSIONї'logged_in']= 1) {
header( "Location: index.php" );
}
session_start();
if ( valid_login($_POSTї'username'], $_POSTї'password']) ) {
$_SESSIONї'logged_in'] = 1;
header( "Location: index.php" );
}
else {header( "Location: login.html" );}
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Aug 10, 2004 8:52 pm
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..
Mexican Hat
Forum Newbie
Posts: 19 Joined: Sat Mar 08, 2003 8:35 pm
Location: Baltimore, Maryland
Contact:
Post
by Mexican Hat » Wed Aug 11, 2004 8:56 am
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 » Wed Aug 11, 2004 8:58 am
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 » Wed Aug 11, 2004 9:00 am
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
Mexican Hat
Forum Newbie
Posts: 19 Joined: Sat Mar 08, 2003 8:35 pm
Location: Baltimore, Maryland
Contact:
Post
by Mexican Hat » Wed Aug 11, 2004 8:21 pm
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()
{
if ( (document.formsї'signin'].username.value != '') && (document.formsї'sign'].password.value != '') )
{
return true;
}
alert('All fields are required');
return false;
}
</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() {
// global $_POSTї'username'];
//}
function valid_login($username, $password) {
return ($username == 'log' && $password == 'pass')
or ($username == 'friendshipchurch' && $password == 'man217')
or ($username == 'murray' && $password == 'tenderloins');
}
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
}
else {header( "Location: login.html" );}
?>