View Full Version : Admin Notes
Prick
10-03-2008, 12:12 AM
Okay well I'm crap at php and I want to add a admin notes part on my website just like the one on vbulletin
eg.
Text box
_________
save button
under it and when you click save it saves it to a .txt file and well as I said like vbulletins admin note thing
Protege
10-03-2008, 08:08 AM
Its pretty easy, if its that small just basically use a text file to load and save.
<html>
<head>
<title>Admin Notes</title>
</head>
<body>
<form method="post" action="save.php">
<?
## File DIR (if on your PC C:\adminnotes.txt) or cPanel something like public_html etc.
$filename = "adminnotes.txt";
## Open file
$handle = fopen($filename, "r");
## Contents, we want to echo the contents into the textbox(area)
$contents = fread($handle, filesize($filename));
## As this is a small code im including minor HTML
echo("<textarea name=\"adminnote\">".$contents."</textarea><br>");
fclose($handle);
?>
<input type="submit" value="Save admin notes"><br></form>
</body>
</html>
- This file is called "adminnotes.php"
example = http://www.driftpanzy.co.uk/admin.php
<?
$filename = "adminnotes.txt";
if(isset($_POST["adminnote"])) {
if(($_POST["adminnote"] == "")) {
echo("No content");
} else {
$content = $_POST["adminnote"];
if(is_writable($filename)) {
if(!$handle = fopen($filename, 'a')) {
echo("Cant write");
exit;
} else {
echo("Success, updated");
fclose($handle); exit;
}
echo("File name isn't writable");
}
}
}
?>
This was done quickly so I haven't really checked for errors/exploits.
Prick
10-03-2008, 04:11 PM
just one.. save.php should be adminnotes.php on line six of the first code :P
And thanks
Also how can I ahve it so it just reloads the page instead of showing "Success Updated"?
Protege
10-03-2008, 04:30 PM
The bottom PHP is under the page "send.php", sorry I didn't tell you that lol, to read load the page you could just include("adminnotes.php"); or do a meta reload.
Prick
10-03-2008, 04:31 PM
Okay one more thing to add..
I was thinking this might not be secure and can be easily viewed/or edited by someone I don't want to edit it, so maybe it could be safer in a table in my sites database?
If it is safer (probably is) can anyone edit that code so that it writes to a database table and then prints the text back into the textarea
EDIT: sorry for all the questions but I'm getting
Warning: fread() [function.fread (http://virtual-gamez.net/site/admin/function.fread)]: Length parameter must be greater than 0 in /home/virtualg/public_html/site/admin/adminnotes.php on line 13
when I load the page
Protege
10-03-2008, 04:35 PM
You can make it save it to a MYSQL table, but you could always just use the permissions of the folder from 755 to something else so other users can read it, only the system. Having a table JUST for a "online notepad" isn't really worth it, unless your using it to process passwords etc, for people not to be able to add to it, add it to your "Members system" or use cPanel little nifty password directories.
Prick
10-03-2008, 05:49 PM
Okay I still need help on the fread error :/
Protege
10-03-2008, 07:02 PM
Thats because the file has no content in it, it cant read from nothing.
Prick
10-03-2008, 07:59 PM
Ugh nothing ever works for me :eusa_wall
In my /site/admin I've got
adminnotes.php with your code in it
save.php with your code in it
adminnotes.txt with a small bit of text in it
I've set all permissions on each file to 755
I've Added an include('adminnotes.php'); into the admin panel of my website
I've put some text in it and clicked save admin note and it doesn't save it
Protege
10-03-2008, 08:02 PM
755 allows all settings I think lol - edit = I didnt put write to file LOL sorry man let me paste the code for send.php. (replace)
<?
$filename = "adminnotes.txt";
if(isset($_POST["adminnote"])) {
if(($_POST["adminnote"] == "")) {
echo("No content");
} else {
$content = $_POST["adminnote"];
if(is_writable($filename)) {
if(!$handle = fopen($filename, 'w')) {
echo("Cant write");
exit;
} else {
if (fwrite($handle, $content) === FALSE) {
echo("File name isn't writable");
}
else
{
## add here to redirect
echo("Success...");
}
}
}
}
}
fclose($handle);
?>
Prick
10-03-2008, 08:58 PM
Now it works :P
Thanks +rep
Just one little thing, whats the best permissions to set?
I don't want anyone to be able to read the .txt file by going to www.(site).net/admin/adminnotes.txt
atm anyone can go to that link and see the notes, how can I stop people form seeing them?
Prick
10-03-2008, 09:15 PM
Ugh sorry for double post modzzz
Yeah is 750 permissions on each file enough?
I went on a proxy and it said forbidden so I guess it is?
Navicat
11-03-2008, 12:15 AM
You don't have to fread ;) or open it for that matter. file_get_contents should do the trick.
http://www.php.net/file_get_contents
file_get_contents — Reads entire file into a string
string file_get_contents ( string $filename [, int $flags [, resource $context [, int $offset [, int $maxlen ]]]] )
Protege
11-03-2008, 02:33 AM
To protect it, basically you can just add a quick "Validation" of who it is, just add another input called
<input type="password" name="pw"> into the admin.php and then into the send.php, before everything else add
$password = "Yourpwhere";
if(isset($_POST["pw"])) {
if(($_POST["pw"] == "$password")) {
{
# Rest of the code here...then add this at the end of the code
} }This is a poor way to secure a page... Unless you build a member system with encrypts and session checking.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.