• 0

[php] is it possible to...


Question

Get the contents of an entire .html page, and display it in an editable html form? So once it's saved/submitted, it will save these changes in the original .html document?

Basically I'm designing a website as a personal project - I'm trying to learn more advanced things like php and I can't just read books and tutorials, I have to actually try and do things... but here I am stumped! At the moment the website it's all hard coded, but I've got the body content parts stored away in separate files, but I'm wondering if there's a way to get those files displayed in a text box and then allow them to be edited.

I'm just wondering if it's possible. I know there are CMS's like WordPress which will give me everything I need in that respect, but it's not really worth all the effort of re-writing everything and trying to implement how I've designed it into that sort of thing - which I doubt I'd be able to do anyway at this stage.

The other thing would be securing the whole thing down as well... I know it'd be a massive security risk and make spam and maliciousness incredibly easy but yeah... It's all part of this incredibly steep learning curve. :p

Thanks for any advice! If it's that much of a bother though, I'll just teach who I'm handing it over to how to edit things with FTP. :p

Link to comment
Share on other sites

Recommended Posts

  • 0

Oh man... *wipes forehead* It's adding slashes to everything when I save, and I haven't changed the code one bit.

Do you happen to have magic quotes on? If yes, turn the, deprecated as of 5.3.0, feature off.

If you are going to use the script on multiple shared hosts where you don't have any rights, I would suggest checking if the content is automatically slashed and based on the answer running stripslashes().

Remember to read the security manuals of PHP (and the DBMS) before you change to using databases, if you ever are going to. Never trust the input and double escaping is bad.

What comes to the html_entitiy_decode, well, you don't need to use the entity decoding when the data is received. Browsers are designed to show encoded content in texteareas and the content is automatically sent in the form as shown. If you use decoding when the data is received, you will also remove the entities you put in the code.

Link to comment
Share on other sites

  • 0

I'm using a shared hosting package, but I think it may be on, I don't understand the configuration.

It says:

magic_quotes_gpc: On

magic_quotes_runtime: Off

magic_quotes_sybase: Off

The host I'm using is using PHP 5.2.13, and I've tried adding in stripslashes(); myself, but cannot get it working.

Link to comment
Share on other sites

  • 0

oops didnt notice that typo in my original code, sorry :p

its odd that magic quotes is on if your PHP version is 5.2.13 since they have been deprecated.

what did you add stripslashes(); to?

Link to comment
Share on other sites

  • 0

.. Everything? I kept getting bad results so I attached it to everything.

... <.< Still didn't work. I literally have a headache! xD

Link to comment
Share on other sites

  • 0
 
&lt;?php
define('PAGE_TO_BE_EDITED', 'page.html');

if(get_magic_quotes_gpc()){
 $_POST = array_map('stripslashes', $_POST);
}

if('POST' === $_SERVER['REQUEST_METHOD']){
 file_put_contents(
	PAGE_TO_BE_EDITED,
	html_entity_decode($_POST['page_data'])
 );
 header('Location: ' . $_SERVER['PHP_SELF']);
 exit;
}

$page_data = htmlentities(file_get_contents(PAGE_TO_BE_EDITED));
?&gt;
&lt;html&gt;
 &lt;head&gt;&lt;/head&gt;
 &lt;body&gt;
	&lt;form method="post" action=""&gt;
 	&lt;textarea cols="50" rows="20" name="page_data"&gt;&lt;?php echo $page_data; ?&gt;&lt;/textarea&gt;
 	&lt;br /&gt;
 	&lt;input type="submit" value="Save" /&gt;
	&lt;/form&gt;
 &lt;/body&gt;
&lt;/html&gt;

Link to comment
Share on other sites

  • 0

And there we have it, right off the bat. Thanks for the code sir!

I'll be sure to try and make sense of it instead of just shamelessly copying & pasting it. >.>

Link to comment
Share on other sites

  • 0

I'll be sure to try and make sense of it instead of just shamelessly copying & pasting it. >.>

Liar. :p

...and you're most welcome.

Link to comment
Share on other sites

  • 0

I need to learn this stuff, and alll you people can obviously tell I'm as dumb as a post. :laugh:

Ah well, at least I don't give up... asking for help... >.>

see? I modified it already. :[.. I'm not that bad. :rofl:

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.