MajorDisaster
Mitglied
Servus, hab hier ein Artikelscript, dass allerdings keine Passwortabfrage für den Adminbereich hat, d.h. jeder könnte einen Artikel erstellen/editieren/löschen.
Jetzt wollt ich fragen, wie ich eine Passwortabfrage für den Adminbereich einbauen kann:
Code:
[admin.php]:
[config.php]
Jetzt wollt ich fragen, wie ich eine Passwortabfrage für den Adminbereich einbauen kann:
Code:
[admin.php]:
PHP:
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
<html>
<head>
<title>MD Article - Administration Area</title>
</head>
<body>
<?php
/*
---------------------------------------------------
|MD Article version 1.0 |
|Copyright (c) Matthew Dingley 2003 |
|For any help or assistance go to MD Web at: |
|www.matthewdingley.co.uk |
| |
|For information on how to install see the readme |
---------------------------------------------------
*/
$configFile="config.php";
require $configFile;
//Connect to database
$db = mysql_connect("$host", "$username", "$password");
mysql_select_db("$databasename", $db);
function doOptions()
{
echo "
<br>
<br>
<a href=\"$PHP_SELF?action=main\">Main Menu</a> <a href=\"$PHP_SELF?action=add\">Add an article</a> <a href=\"$PHP_SELF?action=help\">Help</a>
<br>Get Help and support for MD Article as well as more cool programs to use on your website at <a href=\"http://www.matthewdingley.co.uk\" target=\"_blank\">MD Web</a>
<br>
<br>
MD Article © <a href=\"http://www.matthewdingley.co.uk\" target=\"_blank\">Matthew Dingley</a> 2003
";
}
echo "<h2 align=\"left\">MD Article Administration Area</h2>";
echo "<p align=\"left\"><i>Version 1.0.0</i><br><br>";
//Date stuff
$today = getdate();
$month = $today["month"];
$mday = $today["mday"];
$year = $today["year"];
$theDate = "$mday $month $year";
//End date stuff
//Start add article
if($action=="add")
{
//If they have entered data into the form, do this
if($title||$summary||$author||$date||$full)
{
if($complete)
{
$insertIt=mysql_query("INSERT INTO $tablename (`title`, `summary`, `author`, `date`, `full`, `complete`) VALUES ('$title', '$summary', '$author', '$date', '$full', '$complete')",$db);
}
else
{
$insertIt=mysql_query("INSERT INTO `$tablename` (`title`, `summary`, `author`, `date`, `full`) VALUES ('$title', '$summary', '$author', '$date', '$full') ",$db);
}
if($insertIt)
{
echo "The article <i>$title</i> has been successfully added<br>";
}
else
{
echo "Sorry there has been an error, please try again<br>";
}
}
//Otherwise give them the form
else
{
echo "
<form action=\"$PHP_SELF\" method=\"post\">
<b>Title</b>:
<br>
<i>The title of your article</i>
<br>
<input name=\"title\" type=\"text\" value=\"\" size=\"35\" maxlength=\"70\">
<br>
<br>
<b>Summary</b>:
<br>
<i>A quick summary to tell your visitors what this article is all about</i>
<br>
<input name=\"summary\" type=\"text\" value=\"\" size=\"64\" maxlength=\"255\">
<br>
<br>
<b>Author</b>:
<br>
<i>The name of the author who wrote the article</i>
<br>
<input name=\"author\" type=\"text\" value=\"\" size=\"24\" maxlength=\"30\">
<br>
<br>
<b>Date</b>:
<br>
<i>The date on which this article was written (Note: this will have no effect on the order that this article is shown)</i>
<br>
<input name=\"date\" type=\"text\" value=\"$theDate\" size=\"16\" maxlength=\"20\">
<br>
<br>
<b>Full article</b>:
<br>
<i>The full text of the article. (Note: this can contain HTML. To include images, put the images into the images directory and use a HTML <IMG> tag</i>
<br>
<textarea name=\"full\" rows=\"14\" cols=\"70\" >
</textarea>
<br>
<br>
<b>Completed</b>:
<br>
<i>Tick this off when the article is complete. It won't be displayed in the index otherwise</i>
<br>
<input type=\"checkbox\" name=\"complete\" value=\"1\">
<br>
<br>
<input name=\"action\" type=\"hidden\" value=\"add\">
<input type=\"submit\" value=\"Add Article\">
</form>
";
}
doOptions();
}
//Start edit article
if($action=="edit")
{
//If they have entered data into the form, do this
if($title||$summary||$author||$date||$full)
{
$updateIt=mysql_query("UPDATE $tablename SET title='$title', summary='$summary', author='$author', date='$date', full='$full', complete='$complete' WHERE id='$id'",$db);
if($updateIt)
{
echo "The article <i>$title</i> has been successfully updated<br>";
}
else
{
echo "Sorry there has been an error, please try again<br>";
}
}
//Otherwise give them the form
else
{
$getUpdateInfo=mysql_query("SELECT * FROM $tablename WHERE id='$id'",$db);
if($updateInfo=mysql_fetch_array($getUpdateInfo))
{
echo "
<form action=\"$PHP_SELF\" method=\"post\">
<input name=\"id\" type=\"hidden\" value=\"$id\">
<b>Title</b>:
<br>
<i>The title of your article</i>
<br>
<input name=\"title\" type=\"text\" value=\"";
printf($updateInfo["title"]);
echo "\" size=\"35\" maxlength=\"70\">
<br>
<br>
<b>Summary</b>:
<br>
<i>A quick summary to tell your visitors what this article is all about</i>
<br>
<input name=\"summary\" type=\"text\" value=\"";
printf($updateInfo["summary"]);
echo "\" size=\"64\" maxlength=\"255\">
<br>
<br>
<b>Author</b>:
<br>
<i>The name of the author who wrote the article</i>
<br>
<input name=\"author\" type=\"text\" value=\"";
printf($updateInfo["author"]);
echo "\" size=\"24\" maxlength=\"30\">
<br>
<br>
<b>Date</b>:
<br>
<i>The date on which this article was written (Note: this will have no effect on the order that this article is shown)</i>
<br>
<input name=\"date\" type=\"text\" value=\"";
printf($updateInfo["date"]);
echo "\" size=\"16\" maxlength=\"20\">
<br>
<br>
<b>Full article</b>:
<br>
<i>The full text of the article. (Note: this can contain HTML. To include images, put the images into the images directory and use a HTML <IMG> tag</i>
<br>
<textarea name=\"full\" rows=\"14\" cols=\"70\" >";
printf($updateInfo["full"]);
echo "</textarea>
<br>
<br>
<b>Completed</b>:
<br>
<i>Tick this off when the article is complete. It won't be displayed in the index otherwise</i>
<br>";
if($updateInfo["complete"]=="1")
{
echo "<input type=\"checkbox\" name=\"complete\" value=\"1\" checked>";
}
else
{
echo "<input type=\"checkbox\" name=\"complete\" value=\"1\">";
}
echo "<br>
<br>
<input name=\"action\" type=\"hidden\" value=\"edit\">
<input type=\"submit\" value=\"Update\">
</form>
";
}
else
{
echo "Sorry, there has been an error. Please try again";
}
}
doOptions();
}
//Start Delete Article
if($action=="delete")
{
if($id)
{
if($check=="yes")
{
$deleteIt=mysql_query("DELETE FROM $tablename WHERE id='$id'",$db);
if($deleteIt)
{
echo "The article has been successfully deleted";
}
else
{
echo "Sorry there has been an error. Please try again";
}
}
else
{
$getDeleteInfo=mysql_query("SELECT title FROM $tablename WHERE id='$id'",$db);
if($deleteInfo=mysql_fetch_array($getDeleteInfo))
{
$title=$deleteInfo["title"];
echo "Are you sure you want to delete the article <b>$title</b>?<br>";
echo "<a href=\"$PHP_SELF?action=delete&id=$id&check=yes\">Yes</a>
<a href=\"$PHP_SELF?action=main\">No</a>";
}
else
{
echo "Sorry there has been an error, please try again";
}
}
}
else
{
echo "Sorry there has been an error, please try again";
}
doOptions();
}
//Start Help
if($action=="help")
{
echo "If you need any help or assistance, please go to MD Web at <a href=\"www.matthewdingley.co.uk\">
www.matthewdingley.co.uk</a>. Just go to the contact section and send me an e-mail with a description of your problem
";
doOptions();
}
//End help
//Start Full
if($action=="full")
{
$getFull=mysql_query("SELECT * FROM $tablename WHERE id=$id", $db);
if($theFull=mysql_fetch_array($getFull))
{
echo "
<h2 align=\"left\">
";
printf($theFull["title"]);
echo "
</h2>
<p align=\"left\">
By:
";
printf($theFull["author"]);
echo "
</p>
<p align=\"left\">
";
printf($theFull["full"]);
echo "
</p>
<p align=\"left\">
";
printf($theFull["author"]);
echo "
</p>
";
}
else
{
echo "Sorry, there has been an error. Please try again";
}
doOptions();
}
//End full
//Start install
if($action=="install")
{
if(mysql_query("
CREATE TABLE $tablename (
id int(5) NOT NULL auto_increment,
title varchar(70) default NULL,
date varchar(20) default NULL,
summary varchar(255) default NULL,
full text,
author varchar(30) default NULL,
novisitors int(5) default '0',
complete tinyint(1) NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE KEY id (id)
)
",$db))
{
echo "MD Article has been installed successfully. Thank you for using MD Article.<br>
You can now <a href=\"$PHP_SELF?action=add\">add a download</a>
";
}
else
{
echo "Sorry, the install procedure was not sucessfull. If this error persists, please try checking that you have entered in your information into the config.php file correctly.
For any more help or assistance, please go to <a href=\"http://www.matthewdingley.co.uk\" target=\"_blank\">MD Web</a> and contact me.
";
}
}
//End install
//Start Main
if($action=="main"||!$action)
{
echo "<a href=\"$PHP_SELF?action=add\">Add article</a><br>";
//Start unfinished
$getArticles=mysql_query("SELECT id, title, date, summary, novisitors FROM $tablename WHERE complete='0'", $db);
if($articleInfo=mysql_fetch_array($getArticles))
{
echo "<h3 align=\"left\">Unfinished Articles</h3>";
echo "<table width=\"90%\" cellspacing=\"12\" cellpadding=\"0\">
<tr>
<td>
<b>ID</b>
</td>
<td>
</td>
<td>
<b>Hits</b>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<tr>
";
do
{
echo "
<tr>
<td>
";
printf($articleInfo["id"]);
echo "
</td>
<td>
<b>
";
printf($articleInfo["title"]);
echo "
</b>
<br>
<i>
";
printf($articleInfo["date"]);
echo "
</i>
<br>
";
printf($articleInfo["summary"]);
echo "
</td>
<td>
";
printf($articleInfo["novisitors"]);
echo "
</td>
<td>
<a href=\"$PHP_SELF?action=edit&id=
";
printf($articleInfo["id"]);
echo "
\">Edit</a>
</td>
<td>
<a href=\"$PHP_SELF?action=delete&id=
";
printf($articleInfo["id"]);
echo "
\">Delete</a>
</td>
<td>
<a href=\"$PHP_SELF?action=full&id=
";
printf($articleInfo["id"]);
echo "
\">View Full</a>
</td>
<tr>
";
}
while($articleInfo=mysql_fetch_array($getArticles));
echo "</table>";
echo "<hr><h3 align=\"left\">Finished Articles</h3>";
}
//End unfinished
$getArticles=mysql_query("SELECT id, title, date, summary, novisitors FROM $tablename WHERE complete='1'", $db);
if($articleInfo=mysql_fetch_array($getArticles))
{
echo "<table width=\"90%\" cellspacing=\"12\" cellpadding=\"0\">
<tr>
<td>
<b>ID</b>
</td>
<td>
</td>
<td>
<b>Hits</b>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<tr>
";
do
{
echo "
<tr>
<td>
";
printf($articleInfo["id"]);
echo "
</td>
<td>
<b>
";
printf($articleInfo["title"]);
echo "
</b>
<br>
<i>
";
printf($articleInfo["date"]);
echo "
</i>
<br>
";
printf($articleInfo["summary"]);
echo "
</td>
<td>
";
printf($articleInfo["novisitors"]);
echo "
</td>
<td>
<a href=\"$PHP_SELF?action=edit&id=
";
printf($articleInfo["id"]);
echo "
\">Edit</a>
</td>
<td>
<a href=\"$PHP_SELF?action=delete&id=
";
printf($articleInfo["id"]);
echo "
\">Delete</a>
</td>
<td>
<a href=\"$PHP_SELF?action=full&id=
";
printf($articleInfo["id"]);
echo "
\">View Full</a>
</td>
<tr>
";
}
while($articleInfo=mysql_fetch_array($getArticles));
echo "<tr><td colspan=\"6\">";
doOptions();
echo "</td></tr>";
echo "</table>";
}
else
{
echo "Sorry, there are no articles in the database";
doOptions();
}
}
?>
</body>
</html>
[config.php]
PHP:
<?php
/*
---------------------------------------------------
|MD Article version 1.0 |
|Copyright (c) Matthew Dingley 2003 |
|For any help or assistance go to MD Web at: |
|www.matthewdingley.co.uk |
| |
|For information on how to install see the readme |
---------------------------------------------------
*/
//Your host name. This is usually localhost, but check with your administrator if you are not sure
$host = "localhost";
//The name of the database you want the MySQL table to be installed under
$databasename= "matthewd_mdweb";
//The name of the table you want the program to run on
$tablename = "mdarticle2";
//Your username for your database
$username = "matthewd_matthew";
//Your password for your database
$password = "tooltip";
//The number of articles you want to show on the 'latest articles' file
$numArticles = "2";
?>