echo "<html xmlns="http://www.w3.org/1999/xhtml">" ;Wat doe ik hier verkeerd. Ik heb een vermoeden dat het te maken heeft met de ", maar ik ben nie zeker.
echo "<html xmlns="http://www.w3.org/1999/xhtml">" ;
<?php
// Config : [ You must set these options ]
$sql_host = "localhost" ; // MySQL host
$sql_user = "user" ; // MySQL username
$sql_pass = "pass" ; // MySQL password
$sql_db = "db" ; // Database name
// End of config //
$link = mysql_connect ($sql_host, $sql_user, $sql_pass) or die("Could not connect : " . mysql_error());
mysql_select_db ($sql_db) or die ("Could not select database '{$sql_db}' .");
$query = "SHOW TABLES FROM $sql_db" ;
$r = mysql_query ($query) or die ("Query failed : " . mysql_error());
$dbase = 0 ;
while ($row = mysql_fetch_row($r)) if ($row[0]=="protect_users") $dbase = 1 ;
if ($dbase != 1)
{
$query = "CREATE TABLE protect_users (id CHAR(20), passwd CHAR(34))" ;
$r = mysql_query($query) or die("Query failed : " . mysql_error());
$pass = crypt('phpclub', 'pc') ;
$query = "INSERT INTO protect_users VALUES ('admin', '{$pass}')";
$r = mysql_query($query) or die("Query failed : " . mysql_error());
}
login_check() ;
if(isset($_GET['logout'])) protect_logout() ;
if($_COOKIE['protect_user']=='admin') protect_admin() ;
/******** Functions : ********/
function login_check()
{
global $link ;
if (!isset($_COOKIE['protect_user']) || !isset($_COOKIE['protect_passwd'])) login_get() ;
$chars = count_chars($_COOKIE['protect_user']) ;
if($chars[0] || $chars[ord("'")]) { setcookie("protect_user", '', time(), '/') ;
die('Alarm !') ; }
$user = addslashes($_COOKIE['protect_user']) ;
$passwd = $_COOKIE['protect_passwd'] ;
$query = "SELECT * FROM protect_users WHERE id = '{$user}'";
$rr = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($rr) == 0) login_get() ; // user_not_found()
$row = mysql_fetch_assoc($rr) ;
if($row["passwd"] != $passwd) login_get() ; // password_error()
}
function login_get()
{
if (isset($_POST['user']) && isset($_POST['passwd'])) {
setcookie("protect_user", $_POST['user'], time()+864000, '/') ;
setcookie("protect_passwd", crypt($_POST['passwd'], 'pc'), time()+864000, '/') ;
die("<meta http-equiv='refresh' content='0; url=?'><a href='?'>Wait ...</a>") ;
}
echo "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">" ;
echo '<html xmlns="http://www.w3.org/1999/xhtml">' ;
echo "<head>" ;
echo "<title>Koninklijke Harmonie "De Heren van Zichem"</title>" ;
echo "<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />" ;
echo "<link rel="stylesheet" href="http://www.herenvanzichem.be/pages/style.css" type="text/css" />" ;
echo "<script src="http://www.herenvanzichem.be/pages/script.js" type="text/javascript"></script>" ;
echo "</head>" ;
echo "<body>" ;
echo "<div id="container"><a name="top"></a>" ;
echo "<div id="header">" ;
echo "<img src="http://www.herenvanzichem.be/images/logo.jpg" alt="Koninklijke Harmonie "De Heren van Zichem"" />" ;
echo "</div>" ;
echo "<?php" ;
echo "include "http://www.herenvanzichem.be/pages/menu.php";" ;
echo "?>" ;
echo "<div id="content">" ;
echo "<table width='50%'><tr><td align='center'><table>" ;
echo "<form action='?' method='post'>" ;
echo "<tr><td>Username :</td><td><input name='user'></td></tr>" ;
echo "<tr><td>Password :</td><td><input type='password' name='passwd'></td></tr>\r\n" ;
die("<tr><td> </td><td align='center'><input type='submit' name='Login' value='Login'></td></tr></form></table></td></tr></table>") ;
echo "<div id="footer">" ;
echo "2005-2006©Koninklijke Harmonie "De Heren van Zichem"" ;
echo "</div>" ;
echo "</div>" ;
echo "</body>" ;
echo "</html>" ;
}
function protect_admin()
{
echo "<html><head><title>Admin Section</title><style type='text/css'>TD {font-size: 12}</style></head><body><table width='100%'><tr><td align='center'>" ;
if (isset($_POST['add_user']) && isset($_POST['add_passwd'])) add_user($_POST['add_user'], $_POST['add_passwd']) ;
elseif (isset($_POST['chg_user']) && isset($_POST['chg_passwd'])) chg_user($_POST['chg_user'], $_POST['chg_passwd']) ;
elseif (isset($_POST['del_user'])) del_user($_POST['del_user']) ;
elseif (isset($_POST['list_users'])) list_users() ;
echo "<table><form action='?' method='post'>" ;
echo "<tr><td colspan=2><font color=blue><b>Add a New User</b></font></td></tr>" ;
echo "<tr><td>Username :</td><td><input name='add_user'></td></tr>" ;
echo "<tr><td>Password :</td><td><input type='password' name='add_passwd'></td></tr>\r\n" ;
echo "<tr><td> </td><td align='center'><input type='submit' name='add' value='Add'><hr></td></tr></form>" ;
echo "<form action='?' method='post'>" ;
echo "<tr><td colspan=2><font color=blue><b>Change Users Info</b></font></td></tr>" ;
echo "<tr><td>Username :</td><td><input name='chg_user'></td></tr>" ;
echo "<tr><td>New Pass :</td><td><input type='password' name='chg_passwd'></td></tr>\r\n" ;
echo "<tr><td> </td><td align='center'><input type='submit' name='chg' value='Update'><hr></td></tr></form>" ;
echo "<form action='?' method='post'>" ;
echo "<tr><td colspan=2><font color=blue><b>Delete a User</b></font></td></tr>" ;
echo "<tr><td>Username :</td><td><input name='del_user'></td></tr>" ;
echo "<tr><td> </td><td align='center'><input type='submit' name='chg' value='Delete'><hr></td></tr></form>" ;
echo "<form action='?' method='post'>" ;
echo "<tr><td colspan=2><font color=blue><b>List All Users</b></font></td></tr>" ;
echo "<tr><td> </td><td align='center'><input type='hidden' name='list_users' value='1'><input type='submit' name='lst' value='List Users'><hr></td></tr></form>" ;
die("</form></table><hr width=50%>[ <a href='?logout=1'>Logout</a> ]</td></tr></table></body></html>") ;
}
function add_user($u, $p)
{
global $link ;
$chars = count_chars($u) ;
if($chars[0] || $chars[ord("'")] || !$u || !$p) { die('Bad username/password .') ; }
$query = "SELECT * FROM protect_users WHERE id = '{$u}'";
$rr = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($rr) != 0) { echo('<font color=red>User already exists .</font><hr width=50%>') ;
return ; }
$pass = crypt($p, 'pc') ;
$query = "INSERT INTO protect_users VALUES ('{$u}', '{$pass}')";
$r = mysql_query($query) or die("Query failed : " . mysql_error());
echo "<font color=red>User added .</font><hr width=50%>" ;
}
function chg_user($u, $p)
{
global $link ;
$chars = count_chars($u) ;
if($chars[0] || $chars[ord("'")] || !$u || !$p) { die('Bad username/password .') ; }
$query = "SELECT * FROM protect_users WHERE id = '{$u}'" ;
$rr = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($rr) == 0) { echo('<font color=red>User doesnt exist .</font><hr width=50%>') ;
return ; }
$pass = crypt($p, 'pc') ;
$query = "UPDATE protect_users SET passwd = '{$pass}' WHERE id = '{$u}'";
$r = mysql_query($query) or die("Query failed : " . mysql_error());
echo "<font color=red>User changed .</font><hr width=50%>" ;
if ($u=='admin') { die("<meta http-equiv='refresh' content='2; url=?'><a href='?'>Wait ...</a>") ; }
}
function del_user($u)
{
global $link ;
if ($u=='admin') die("User 'admin' can not be deleted .") ;
$chars = count_chars($u) ;
if($chars[0] || $chars[ord("'")] || !$u) { die('Bad username .') ; }
$query = "SELECT * FROM protect_users WHERE id = '{$u}'" ;
$rr = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($rr) == 0) { echo('<font color=red>User doesnt exist .</font><hr width=50%>') ;
return ; }
$query = "DELETE FROM protect_users WHERE id = '{$u}'";
$r = mysql_query($query) or die("Query failed : " . mysql_error());
echo "<font color=red>User deleted .</font><hr width=50%>" ;
}
function list_users()
{
global $link ;
$query = "SELECT id FROM protect_users";
$rr = mysql_query($query) or die("Query failed : " . mysql_error());
echo "<table>" ;
while ($id = mysql_fetch_row($rr)) echo "<tr><td><font color=red>{$id[0]}</font></td></tr>" ;
echo "</table><hr width=50%>" ;
}
function protect_logout()
{
setcookie("protect_user", '', time(), '/') ;
setcookie("protect_passwd", '', time(), '/') ;
die("<center><font size=-1>Logged out .<br> [ <a href='javascript:history.back(1)'>Back</a> ]") ;
}
?>
wes schreef op 02.08.2006 11:38dan moet je daar toch een belletje bij gaan branden..
/******** Functions : ********/
function login_check()
{
global $link ;
if (!isset($_COOKIE['protect_user']) || !isset($_COOKIE['protect_passwd'])) login_get() ;
$chars = count_chars($_COOKIE['protect_user']) ;
if($chars[0] || $chars[ord("'")]) { setcookie("protect_user", '', time(), '/') ;
die('Alarm !') ; }
$user = addslashes($_COOKIE['protect_user']) ;
$passwd = $_COOKIE['protect_passwd'] ;
$query = "SELECT * FROM protect_users WHERE id = '{$user}'";
$rr = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($rr) == 0) login_get() ; // user_not_found()
$row = mysql_fetch_assoc($rr) ;
if($row["passwd"] != $passwd) login_get() ; // password_error()
}
function login_get()
{
if (isset($_POST['user']) && isset($_POST['passwd'])) {
setcookie("protect_user", $_POST['user'], time()+864000, '/') ;
setcookie("protect_passwd", crypt($_POST['passwd'], 'pc'), time()+864000, '/') ;
die("<meta http-equiv='refresh' content='0; url=?'><a href='?'>Wait ...</a>") ;
}
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' ;
echo '<html xmlns="http://www.w3.org/1999/xhtml">' ;
echo '<head>' ;
echo '<title>Koninklijke Harmonie "De Heren van Zichem"</title>' ;
echo '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />' ;
echo '<link rel="stylesheet" href="http://www.herenvanzichem.be/pages/style.css" type="text/css" />' ;
echo '<script src="http://www.herenvanzichem.be/pages/script.js" type="text/javascript"></script>' ;
echo '</head>' ;
echo '<body>' ;
echo '<div id="container"><a name="top"></a>' ;
echo '<div id="header">' ;
echo '<img src="http://www.herenvanzichem.be/images/logo.jpg" alt="Koninklijke Harmonie "De Heren van Zichem"" /><br />' ;
echo '</div>' ;
echo '<?php include "http://www.herenvanzichem.be/pages/menu.php";?>' ;
echo '<div id="content"><br />' ;
echo '<table width="50%"><tr><td align="center"><table><br />' ;
echo '<form action="?" method="post"><br />' ;
echo '<tr><td>Username :</td><td><input name="user"></td></tr>' ;
echo '<tr><td>Password :</td><td><input type="password" name="passwd"></td></tr>' ;
die('<tr><td> </td><td align="center"><input type="submit" name="Login" value="Login"></td></tr></form></table></td></tr></table><br />') ;
echo '<div id="footer"><br />' ;
echo '2005-2006©Koninklijke Harmonie "De Heren van Zichem"<br />' ;
echo '</div><br />' ;
echo '</div><br />' ;
echo '</body><br />' ;
echo '</html><br />' ;
}
function protect_admin()
{
echo '<html><head><title>Admin Section</title><style type="text/css">TD {font-size: 12}</style></head><body><table width="100%"><tr><td align="center">' ;
if (isset($_POST['add_user']) && isset($_POST['add_passwd'])) add_user($_POST['add_user'], $_POST['add_passwd']) ;
elseif (isset($_POST['chg_user']) && isset($_POST['chg_passwd'])) chg_user($_POST['chg_user'], $_POST['chg_passwd']) ;
elseif (isset($_POST['del_user'])) del_user($_POST['del_user']) ;
elseif (isset($_POST['list_users'])) list_users() ;
echo "<table><form action='?' method='post'>" ;
echo "<tr><td colspan=2><font color=blue><b>Add a New User</b></font></td></tr>" ;
echo "<tr><td>Username :</td><td><input name='add_user'></td></tr>" ;
echo "<tr><td>Password :</td><td><input type='password' name='add_passwd'></td></tr>\r\n" ;
echo "<tr><td> </td><td align='center'><input type='submit' name='add' value='Add'><hr></td></tr></form>" ;
echo "<form action='?' method='post'>" ;
echo "<tr><td colspan=2><font color=blue><b>Change Users Info</b></font></td></tr>" ;
echo "<tr><td>Username :</td><td><input name='chg_user'></td></tr>" ;
echo "<tr><td>New Pass :</td><td><input type='password' name='chg_passwd'></td></tr>\r\n" ;
echo "<tr><td> </td><td align='center'><input type='submit' name='chg' value='Update'><hr></td></tr></form>" ;
echo "<form action='?' method='post'>" ;
echo "<tr><td colspan=2><font color=blue><b>Delete a User</b></font></td></tr>" ;
echo "<tr><td>Username :</td><td><input name='del_user'></td></tr>" ;
echo "<tr><td> </td><td align='center'><input type='submit' name='chg' value='Delete'><hr></td></tr></form>" ;
echo "<form action='?' method='post'>" ;
echo "<tr><td colspan=2><font color=blue><b>List All Users</b></font></td></tr>" ;
echo "<tr><td> </td><td align='center'><input type='hidden' name='list_users' value='1'><input type='submit' name='lst' value='List Users'><hr></td></tr></form>" ;
die("</form></table><hr width=50%>[ <a href='?logout=1'>Logout</a> ]</td></tr></table></body></html>") ;
}
function add_user($u, $p)
{
global $link ;
$chars = count_chars($u) ;
if($chars[0] || $chars[ord("'")] || !$u || !$p) { die('Bad username/password .') ; }
$query = "SELECT * FROM protect_users WHERE id = '{$u}'";
$rr = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($rr) != 0) { echo('<font color=red>User already exists .</font><hr width=50%>') ;
return ; }
$pass = crypt($p, 'pc') ;
$query = "INSERT INTO protect_users VALUES ('{$u}', '{$pass}')";
$r = mysql_query($query) or die("Query failed : " . mysql_error());
echo "<font color=red>User added .</font><hr width=50%>" ;
}
function chg_user($u, $p)
{
global $link ;
$chars = count_chars($u) ;
if($chars[0] || $chars[ord("'")] || !$u || !$p) { die('Bad username/password .') ; }
$query = "SELECT * FROM protect_users WHERE id = '{$u}'" ;
$rr = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($rr) == 0) { echo('<font color=red>User doesnt exist .</font><hr width=50%>') ;
return ; }
$pass = crypt($p, 'pc') ;
$query = "UPDATE protect_users SET passwd = '{$pass}' WHERE id = '{$u}'";
$r = mysql_query($query) or die("Query failed : " . mysql_error());
echo "<font color=red>User changed .</font><hr width=50%>" ;
if ($u=='admin') { die("<meta http-equiv='refresh' content='2; url=?'><a href='?'>Wait ...</a>") ; }
}
function del_user($u)
{
global $link ;
if ($u=='admin') die("User 'admin' can not be deleted .") ;
$chars = count_chars($u) ;
if($chars[0] || $chars[ord("'")] || !$u) { die('Bad username .') ; }
$query = "SELECT * FROM protect_users WHERE id = '{$u}'" ;
$rr = mysql_query($query) or die("Query failed : " . mysql_error());
if (mysql_num_rows($rr) == 0) { echo('<font color=red>User doesnt exist .</font><hr width=50%>') ;
return ; }
$query = "DELETE FROM protect_users WHERE id = '{$u}'";
$r = mysql_query($query) or die("Query failed : " . mysql_error());
echo "<font color=red>User deleted .</font><hr width=50%>" ;
}
function list_users()
{
global $link ;
$query = "SELECT id FROM protect_users";
$rr = mysql_query($query) or die("Query failed : " . mysql_error());
echo "<table>" ;
while ($id = mysql_fetch_row($rr)) echo "<tr><td><font color=red>{$id[0]}</font></td></tr>" ;
echo "</table><hr width=50%>" ;
}
function protect_logout()
{
setcookie("protect_user", '', time(), '/') ;
setcookie("protect_passwd", '', time(), '/') ;
die("<center><font size=-1>Logged out .<br> [ <a href='javascript:history.back(1)'>Back</a> ]") ;
}
?>
wes schreef op 02.08.2006 12:58broncode verhaal vang je af met /r/n bijv
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n\r' ; dan krijg ik dit