Making a script that will allow you to edit your site code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Making a script that will allow you to edit your site code

Post by nigma »

I wortk on my site at home but often look at it when I am on diff computers, school computers, library computers, etc. So I was wondering if it would be pretty easy to make a place on the site where you select a page/script that is on your site that you want to edit and the contents of the file are put into a textarea. You then update the code in the textarea box and hit a button that will save the new updated file to the old one. Then you have a way to debug/update your site without being at your webserver computer.

How much exp with php do you think you would have to have before this became a realistic idea?

thanks for all help and advice provided.
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

It should not be terribly difficult. All you have to do is set up an FTP connection, retrieve the document, use fopen/fread/fwrite to modify it, and then FTP it back up.

Personally, I would just use an FTP client (ex: WS_FTP) to login to your webserver and get the document directly. That way you can get the code from anywhere and use text editors on it
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

That was what I thought of first. The reason I would do it through a web-interface is because the network I would be doing it from does not allow you to connect to a computer outside the network. Or it wont work if I try to telnet, ftp, ssh to my home comp ( I set it to allow those just to see if it would work ) but I can look at my site from the network.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

With ftp you can download & edit your php scripts but it sounds like you want to edit content via a browser.

Yes, SELECT the content from the database, textarea field in form, submit form to a processor script to UPDATE the record (addslash it first). You'll need to get a row ID from the original SELECT to use in the UPDATE - could add that to the form as a hidden field.

Post again if your stuck on the code.
mqD
Forum Newbie
Posts: 3
Joined: Fri Feb 28, 2003 3:35 am
Location: Southern California

Post by mqD »

Editing scripts via browser does sound pretty convenient. But what about the possible security risks? If someone managed to gain access to your editing page, then there's the potential to do some serious damage to your site / hostserver. I'm assuming that in order to edit your code via the web, the form would have to allow most of all the characters that we normally filter for to be allowed--that there just sounds very evil.. But then again, I'm no professional coder so perhaps there's a safe way around this..

If you do find a full-proof method (or is it 'fool' proof?), please let me know.. As I also work at different computers at different times for my code.. And having this option to edit via browser would be nice.. Although I think a safer way would be to stick to FTP. (If possible, that is.)
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

You could create a php login script with password for the "admin" area, or you could simply put the admin.php file in an .htaccess protected folder.

It's pretty much standard practice on many sites to work this way: it allows for a team of content editors to share out the work. As long as only genuine admin users can run the admin scripts, you'll be ok.

You can even just edit the database directly if you have something like phpMyadmin installed on your server.
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

I have what you're looking for with security via session login if you're interested

leave me your email and I'll send you it
Post Reply