Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using php, can I make a web page editable ??

Status
Not open for further replies.

djbeta

IS-IT--Management
Apr 16, 2004
46
US


I am not sure how to explain what it is that I want to do.. so it's making it hard for me to search for it.. I'll try to explain.

Last year, I helped my department build a web site that has a lot of static html pages which are mostly text.

Of course, we're now running into the problem of pages getting a bit out-of-date.

Using PHP, I was wondering if there might be a somewhat simple way to build in a crude way to directly edit the web pages from a web browser. (I'm thinking I can change the html pages to php pages and build in a function at the bottom of the page that says "edit this page")

Could someone give me a few ideas of how I might be able to approach this ?

I'm very new to php, so please be gentle and as generic with your terminology as possible.

Thanks for reading this.
:)
 
If you add the Edit this page at the bottom, what is stopping anybdy that browses to that page from editing it.

Second:

Supposing you could limit the users that can edit the webpage, the easiest way of acomplishing this would be to create a standard editor page with a textarea to opne the webpage into. and then save it again from there.

So it would be something like thios, after the button has been clicked and the user authenticated as one that can edit the page:
in pesudocode.
Code:
Open page...

echo into textarea: <textarea name=edit> echo " opened file" </textarea>
<input type=submit value=Save>


Taker a look at the following functions in the php online manual at php.net:
[blue]
fopen(),fclose(), fgets(), fread(), fwrite(),file(), file_exists()[/blue]

You can start here:



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
there are lots of neat ways of doing this. they all involve quite a lot of upfront work and thereafter discipline by the users.

common to all methods is that you grab the editable content from a db or file before displaying it.

you can either build web front ends to accept content in forms and then store it in a db or in the filesystem or you can allow people to create text files with specific names and upload it to the filesystem on the web-server.

if you are looking to make the style etc editable the same constructs apply but beware - here be dragons...
 

You're right, the security is not the best for sure,
but it's a pretty small workgroup and we all share
a password for access.

Thanks for the tips.. unfortunately, I'm not sure that programmers
who point newbies to the php manual understand that if you're a newbie,
it's very hard to understand that manual.

I went to the link you provided:

first line:
fopen() binds a named resource, specified by filename, to a stream.

what the heck is a stream ??? see my point ? the manual is loaded with programmer jargon that goes above my head pretty quickly.

I know I have to start somewhere but that manual doesn't seem like the right place to start. I have PHP Essentials by Julie Meloni.. perhaps I'll spend more time with that and then revisit my question

If anyone has a simpler solution or any good book recommendations, could you please let me know

thank you :)




 
Lets try this again:

fopen opens the file into a handle which can then be used to read the file into a string.

Code:
$handle=fopen($file_to_open,'r');

This opens the file in readonly mode (that what the 'r' does, and creates the handle. so it can then be used.

Second, you need to read the file from the handel, using fread()

so
Code:
$contents=fread($handle,filesize($file_to_open));

So You read the file from the handle.

filesize() as the name implies gets the filesize of the file to read, so freads knows how much to read.

Once you have everything in the file, you can then echo it into a textarea. like so:

Code:
<textarea name=editor> echo $contents; </textarea>


If that made sense then we can continue to the next step.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
think of a stream as a handle that php can then manipulate. it is not internal to php but a link to the outside world: the filesystem.

you then use this handle in commands like fwrite and fread.

have a look at as an example of how to get the source code from a file and display it on a page.

for the writing bit... let us know when you get to that stage. it's really very simple (promise...)
 

yes.. i think that did make sense.. so the handle is just a variable that holds the contents of the page ? temporarily so that it can be read as a string ?



 
the handle is a "variable/object" that holds the information that php needs to read/write to a file. a bit like a database connection.

the reading is not necesarily as a string - that's up to you. different calls read in the file as an array of strings, for example.
 
It doesn't actually grab the contents, more like points to where the contents of the file is.

Then using [blue]fread()[/blue] You can read the contents into the a string.
so that you can then manipulate it anyway you want.

[blue]fopen()[/blue] takes several parameters:

The [red]filename[red] that is the name of the page you want to edit with extension, and path.

And a small string that tells it how to open it. Readonly, Read and Write, etc...

I believe the best option is to open it readonly, that way if the user should change their mind about editing the page, the contents will be untouched, until you execute the writing operation. but we will go into that once you have the opening part down.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
thanks for all this great info.. i will read up on this and give it a try later on.. hopefully i'll have some good results !
 
O.k. if you have any questions, feel free to post back here, and we will try to help you.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Why don't you just try using some of the firefox extensions to change the pages all you want and then save them over the originals ?

Check out these extensions for the firefox web browser...

1)web-developer
2)platypus
3)greasemonkey

... to be honest, I'd reckon that the task of coding the whole thing up from php may be beyond your abilities for the moment. Especially if there are time constraints involved as I'd imagine there would be for an IT department.

I think that your first php programs should be something a little smaller and have less things that could go wrong. But that's just my opinion ;) ... check out the extensions and then make up your own mind. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top