OxyScripts.com
Menu spacer Home Tutorials Articles Code Forums irc.freenode.net #oxyscripts
Main (PHP)
Home Forums PHP News PHP Tutorials Articles PHP Code Snippets Contact Us Sysadmin Resources Books Template Shop
3rd Party Streams
SlashDot PHPDeveloper.org PHP.Net
Resources
PHP Manual MySQL Manual Smarty Manual PEAR Manual PHP-GTK Manual Symfony Manual
Code Snippets
Authentication Database Graphics HTTP Miscellaneous Time/Date
Affiliates
Scripts TutorialMan TutorialGuide CodingForums.com PHP Scripts Cheap Web Hosting Affordable Web Hosting Dreamweaver Templates

Search This Site :     PHP Function Reference :
 

Simple login and logout form

By Sam Colebatch (2002-03-29. 8675 views.)
Basic authentication system for a personal website

Edit the html but unless you know php don't edit anything else

Thisis what I was using for my old admin system now gone


if ($action == "login") {
if ($username == "admin" || $password == "admin") {
setcookie("admin", "loggedin", "+3600");
header('Location: admin.php');
}
else {
$error = "wrong password";
}
}
elseif ($action == "logout") {
setcookie("admin", "loggedout", "-3600");
header('Location: http://216.118.121.28/pw/');
}


echo $error
?>

Snewz WMS







if($admin == "loggedin") { ?>










Snewz WMS







login | logout



















News Admin



echo "n";
echo "
add newsn";
echo "
view newsn";
echo "
config news
n";
echo "

n";?>











Guides Admin



echo "n";
echo "
add wheren";
echo "
config guides
n";
echo "

n";?>











Articles Admin



echo "n";
echo "
add wheren";
echo "
config articles
n";
echo "

n";?>











Reviews Admin



echo "n";
echo "
add wheren";
echo "
config reviews
n";
echo "

n";?>











Tutorials Admin



echo "n";
echo "
add wheren";
echo "
config tutorials
n";
echo "

n";?>












Ancient History



echo "n";
echo "
add wheren";
echo "
config A.H. articles
n";
echo "

n";?>


 
if($action == "edit" && isset($HTTP_POST_VARS['password'])) {
//obviously you should change this password on the next line
if($HTTP_POST_VARS['password'] == "editpass") {
//First let's recompile that line with the pipe symbols so we can reinsert it
$line = $HTTP_POST_VARS['date'] . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news'];
$line = str_replace("rn","
",$line);
$line .= "rn";
$data = file('news.txt');
$data[$id] = $line;
//the next line makes sure the $data array starts at the beginning
reset($data);
//now we open the file with mode 'w' which truncates the file
$fp = fopen('news.txt','w');
foreach($data as $element) {
fwrite($fp, $element);
}
fclose($fp);
echo "Item Edited!

n";
echo "Go Backn";
exit;
} else {
echo "Bad password!n";
exit;
}
}
if($action == "edit") {
$data = file('news.txt');
$element = trim($data[$id]);
$pieces = explode("|", $element);
//the next line is to reverse the process of turning the end of lines into breaking returns
$news = str_replace("
","rn",$pieces[2]);
echo "Make the changes you would like and press save.
n";
echo "
n";
echo "Name:
n";
echo "
n";
echo "The News:
n";
echo "

n";
echo "Password:
n";
echo "
n";
echo "n";
echo "n";
echo "
n";
echo "
n";
exit;
}
if($action == "delete" && isset($HTTP_POST_VARS['password'])) {
//obviously you should change this password on the next line
if($HTTP_POST_VARS['password'] == "deletepass") {
$data = file('news.txt');
//this next line will remove the single news item from the array
array_splice($data,$id,1);
//now we open the file with mode 'w' which truncates the file
$fp = fopen('news.txt','w');
foreach($data as $element) {
fwrite($fp, $element);
}
fclose($fp);
echo "Item deleted!

n";
echo "Go Backn";
exit;
} else {
echo "Bad password!n";
exit;
}
}
if($action == "delete") {
echo "

You are about to delete the following news item.

n";
$data = file('news.txt');
$element = trim($data[$id]);
$pieces = explode("|", $element);
echo $pieces[2] . "
" . "Posted by " . $pieces[1] . " on " . $pieces[0] . "n";
echo "

n";
echo "Are you sure you want to delete this news item? If so, enter the password and click on Delete.
n";
echo "
n";
echo "Password:
n";
echo "
n";
echo "n";
echo "
n";
echo "
n";
exit;
}


echo "

Current News

n";
$data = file('news.txt');
//next line removed to make everything else easier in the admin script
//$data = array_reverse($data);
foreach($data as $key=>$element) {
$element = trim($element);
$pieces = explode("|", $element);
echo $pieces[2] . "
" . "Posted by " . $pieces[1] . " on " . $pieces[0] . "n";
echo " Deleten";
echo " Editn";
echo "

n";
}
echo "
n";
echo "

Add News

n";
if($HTTP_POST_VARS['submit']) {
if($HTTP_POST_VARS['password'] == 'pass') {
if(!$HTTP_POST_VARS['name']) {
echo "You must enter a name";
exit;
}
if(!$HTTP_POST_VARS['news']) {
echo "You must enter some news";
exit;
}
if(strstr($HTTP_POST_VARS['name'],"|")) {
echo "Name cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['news'],"|")) {
echo "News cannot contain the pipe symbol - |";
exit;
}
$fp = fopen('news.txt','a');
if(!$fp) {
echo "Error opening file!";
exit;
}
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news'];
$line = str_replace("rn","
",$line);
$line .= "rn";
fwrite($fp, $line);
if(!fclose($fp)) {
echo "Error closing file!";
exit;
}
echo "News added!n";
} else {
echo "Bad Password";
}
}

?>

Your name:



The News:




News Password:










































Name:



Password:















hope this helps you people out there
 

 
   Print this page

Top Sponsor

Sponsors
CA
Sponsors
AdWords Dominator 125*125
Advertisting

Affiliates
VertexTemplates PHPFreaks CodeWalkers StarGeek DevScripts CGI & PHP Scripts PHP CMS

Shopping Rebates   Sell It 4 You   Flash Page Counters   Get Insured
GPS Tracking Service   Charity Donate Info   Web Site Hosting   VOIP Service

Privacy Policy | Links | Site Map | Advertising

All content on OxyScripts.com is (©)2002-2007

 
Powered by Adrastea - Version 1.0.0. Copyright © Rune Solutions, 2004-2005