/    Sign up×
Community /Pin to ProfileBookmark

PHP – No SQL

Is there a way/script that can allow me to edit the content of a page (very simple, just a text box that shows the code) and save/submit it without using a database?
In PHP of course.

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@papa_faceFeb 20.2007 — I made this quite quickly so if they're some errors forgive me ?

You will need to make a directory named /files - put the files you want to edit in there.

Then put these files in the directory below files:

editfile.php:
<?php

if (isset($_POST["content"]))
{
//the following will be processed if the content feild has something set to it
$content = $_POST["content"];
$file = $_POST["location"];
$open = fopen($file, "w+");
$write = fwrite($open,$content);

<i> </i> $write;
//checks if the file has been edited:
if ($write == true)
{
echo "File editted sucessfully!";
}
//If the file has had a problem being written to, the follwing is run:
else
{
echo "There was a problem, please try again. Problems may include that you did not make any changes to the file.";
}

<i> </i> fclose($open);
<i> </i> }

//the following will be processed if the content feild does NOT have anyting set to it
else
{
echo "No file has been selected to edit.";
}
?&gt;

index.php:
&lt;?php

if (isset($_POST["submit"]))
{
if ($_POST["filename"] == "")
{
echo "Please enter a file name";
}
else
{
if (file_exists($_POST["filename"]) == false)
{
echo "This file does not exist";
}
else {

<i> </i> $filename = $_POST["filename"];
<i> </i> echo "&lt;form action="editfile.php" method="post"&gt;
<i> </i> &lt;textarea name="content" cols="100" rows="30"&gt;". file_get_contents($filename) ."&lt;/textarea&gt;
<i> </i> &lt;input name="location" type="hidden" value="". $filename ."" /&gt;&lt;br&gt;&lt;br&gt;
<i> </i> &lt;input name="submit" type="submit" value="Make Changes to the file"/&gt;
<i> </i> &lt;/form&gt;";
<i> </i> }
<i> </i> }

<i> </i> }
else
{
echo "&lt;form action="". $_SERVER["PHP_SELF"]. "" method="post"&gt;
Enter the file location you want to edit:&lt;input name="filename" type="text" /&gt;&lt;br /&gt;&lt;br /&gt;
&lt;input name="submit" type="submit" value="Click here to edit" /&gt;
&lt;/form&gt;";
}

?&gt;

Enter the filename (inc extention into the text box) e.g files/test.txt

That should do the job.
Copy linkTweet thisAlerts:
@MrCoderFeb 20.2007 — What is to stop people from $_POST(ing) data to any file?

The above script has huge security holes, I would review the code before use.
Copy linkTweet thisAlerts:
@papa_faceFeb 20.2007 — ^^

We've got Sherlock on the case.

It was only meant for personal use. Calm down.

What do you expect me to do, write a bullet-proof script for someone i dont even know and not get paid?

I provided an outline to the script that is required, it is up to the OP to secure it depending on the environment they wish to run it on.

Would you prefer me to remove it completely and therefore not offer any help to the OP?

or guide the OP the best I can with the short time I had?

By the way, those are rhetorical questions.
Copy linkTweet thisAlerts:
@KovoauthorFeb 20.2007 — ^^

We've got Sherlock on the case.

It was only meant for personal use. Calm down.

What do you expect me to do, write a bullet-proof script for someone i dont even know and not get paid?

I provided an outline to the script that is required, it is up to the OP to secure it depending on the environment they wish to run it on.

Would you prefer me to remove it completely and therefore not offer any help to the OP?

or guide the OP the best I can with the short time I had?

By the way, those are rhetorical questions.[/QUOTE]


Thank you. I will secure the pages myself, so not just anyone can edit it. Thank you!
Copy linkTweet thisAlerts:
@KovoauthorFeb 20.2007 — one issue, once I update the content, it is automatically modified into this:

[CODE]<script type=\\\"text/javascript\\\">
function popUp(URL) {
day = new Date();
id = day.getTime();
eval(\\\"page\\\" + id + \\\" = window.open(URL, \\\'\\\" + id + \\\"\\\', \\\'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=700,left = 326,top = 0\\\');\\\");
}
</script>


<a href="javascript:popUp('documents/tscf.jpg')"><img src="documents/tscf.gif" border="0"/></a>

<a href="javascript:popUp('documents/tscb.jpg')"><img src="documents/tscb.gif" border="0"/></a>



<script type=\\\"text/javascript\\\">
var speed, currentpos=curpos1=0,alt=1,curpos2=-1

function initialize(){
if (window.parent.scrollspeed!=0){
speed=window.parent.scrollspeed
scrollwindow()
}
}

function scrollwindow(){
temp=(document.all)? document.body.scrollTop : window.pageYOffset
alt=(alt==0)? 1 : 0
if (alt==0)
curpos1=temp
else
curpos2=temp

window.scrollBy(0,speed)
}

setInterval(\\\"initialize()\\\",10)
</script>[/CODE]


it autmatically adds before every " or '
Copy linkTweet thisAlerts:
@MrCoderFeb 20.2007 — ^^

We've got Sherlock on the case.

It was only meant for personal use. Calm down.

What do you expect me to do, write a bullet-proof script for someone i dont even know and not get paid?

I provided an outline to the script that is required, it is up to the OP to secure it depending on the environment they wish to run it on.

Would you prefer me to remove it completely and therefore not offer any help to the OP?

or guide the OP the best I can with the short time I had?

By the way, those are rhetorical questions.[/QUOTE]


I feel that you have taken the points I raised above to seriously.

I was merely stating that the code should be reviewed before use due to its nature. As you agree the code above is not bullet proof I do not see why my post seems to have enraged you.

Elementary my dear Watson.

Also the reason it is adding the "" is due to your server using magic_quotes. To address this issue you could disable them or use stripslashes() on all instances of $_POST values.
Copy linkTweet thisAlerts:
@KovoauthorFeb 20.2007 — I feel that you have taken the points I raised above to seriously.

I was merely stating that the code should be reviewed before use due to its nature. As you agree the code above is not bullet proof I do not see why my post seems to have enraged you.

Elementary my dear Watson.

Also the reason it is adding the "" is due to your server using magic_quotes. To address this issue you could disable them or use stripslashes() on all instances of $_POST values.[/QUOTE]

Hmm thanks, but how would I implement them, If I added them the way I think I should, it ruins the script. Any ideas?


btw: if u go to http://www.kovo.ca/suxs

Youll see I implemented a security feature, to stop easy access to the script ?
Copy linkTweet thisAlerts:
@papa_faceFeb 20.2007 — change editfile.php to:
&lt;?php

if (isset($_POST["content"]))
{
//the following will be processed if the content feild has something set to it
$content = stripslashes($_POST["content"]);
$file = stripslashes($_POST["location"]);
$open = fopen($file, "w+");
$write = fwrite($open,$content);

<i> </i> $write;
//checks if the file has been edited:
if ($write == true)
{
echo "File editted sucessfully!";
}
//If the file has had a problem being written to, the follwing is run:
else
{
echo "There was a problem, please try again. Problems may include that you did not make any changes to the file.";
}

<i> </i> fclose($open);
<i> </i> }

//the following will be processed if the content feild does NOT have anyting set to it
else
{
echo "No file has been selected to edit.";
}
?&gt;
×

Success!

Help @Kovo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...