how can php manipulate other php files ?

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 1209 Views - Last Post: 20 July 2011 - 12:03 PM Rate Topic: -----

#1 hockey97  Icon User is offline

  • D.I.C Regular

Reputation: -77
  • View blog
  • Posts: 300
  • Joined: 25-September 08

how can php manipulate other php files ?

Posted 17 July 2011 - 10:33 PM

Hi, I want to be able to open up a php file and edit it... in the php file there be php code followed by echoing html code with javascript code.

what I want is at first a blank page is created. in php.

I will then have a gui interface where the client can add windows or change properties of lets say the body.... to different colors etc. They can also manipulate the php file too... where they can do a mysql query... using my GUI.

how is it possible to know exactly where to edit the code in the php file?

I know html you can easily edit it... but for php I would think it be hard. I know of string replace but I would think for that function to work you need to toss that specific code and type in all that code into that function for it to work. for example we will delete function tom(){

if I toss function tom() to the string replace and replace it with "" then I would think in the file you will see (){ the code }
so the function tom got replaced with nothing... so it went from function tom(){ some code }

to (){ some code } .

I would like to know if there is a way where I just say delete this variable or this function... or delete line 3 of this function... etc.

I want to be able to manipulate the php code via my GUI interface.

Is this possible and how would one do this?

Is This A Good Question/Topic? 0
  • +

Replies To: how can php manipulate other php files ?

#2 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5346
  • View blog
  • Posts: 27,302
  • Joined: 10-May 07

Re: how can php manipulate other php files ?

Posted 17 July 2011 - 10:37 PM

This tutorial goes over File I/O under php. It's similar to most other coding languages such as C/C++.
Was This Post Helpful? 0
  • +
  • -

#3 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 926
  • View blog
  • Posts: 3,205
  • Joined: 19-January 10

Re: how can php manipulate other php files ?

Posted 17 July 2011 - 10:38 PM

Instead of replacing pure PHP code with something the user gives you, make a template.

For example, page.php changes these things:
background color
header text
font color


Instead of having $color = "red", use this:
$color = file_get_contents("userData/" . $username . "/fontcolor.txt");

then do whatever with it. This makes it so that you will only need one PHP file (as apposed to one for every user). Yes it will take a little modification, but trust me, you will love yourself when it works perfectly.
Was This Post Helpful? 1
  • +
  • -

#4 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4353
  • View blog
  • Posts: 12,160
  • Joined: 18-April 07

Re: how can php manipulate other php files ?

Posted 17 July 2011 - 10:39 PM

Do realize that PHP script files are just text. You can edit them just like any text document. Read in the entire script into your GUI (like into a multiline text box), edit it there, then save the entire contents back to the file.

PHP is just text that contains code that is passed to an interpreter where it is then executed. It is not like compiled languages or anything.

:)
Was This Post Helpful? 0
  • +
  • -

#5 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 947
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: how can php manipulate other php files ?

Posted 18 July 2011 - 04:48 AM

Giving clients the power to edit PHP files is as dangerous as giving them the password to your server. It's something like SQL injections. A client can simply add malicious code to the end of their input and since it's in the PHP script it will be executed.

I'd suggest following creativecoding's suggestion with a bit of a twist. I understand you want users to customize what have you not but still you need to limit their freedom. For instance, picking the user preferred colour. Provide a color picker so that you have control over what is entered instead of them manually entering it themselves. It will also make your script less prone to errors.

Store the values in a database and filll them into a template. I'm sure you don't want to create a PHP script for every user that uses your site.
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3000
  • View blog
  • Posts: 10,390
  • Joined: 08-August 08

Re: how can php manipulate other php files ?

Posted 18 July 2011 - 06:51 AM

There is a reason we have separate files for HTML, CSS, Javascript, PHP, etc. They all have different purposes, and formatting is something best done with HTML and CSS. You should be using PHP to change the id or class name of an HTML object, and the CSS will set the color. And yes, the HTML really should be in its own file.
Was This Post Helpful? 1
  • +
  • -

#7 hockey97  Icon User is offline

  • D.I.C Regular

Reputation: -77
  • View blog
  • Posts: 300
  • Joined: 25-September 08

Re: how can php manipulate other php files ?

Posted 18 July 2011 - 12:11 PM

some don't quite understand what I want.


I don't plan on loading up a php file into a html text area to allow clients to do php programming.

What I want to do is create a GUI... the GUI will have my onw code where I will go and make changes to the php file.

overall I am giving my clients their own website page.. kinda like myspace.

but I want them to be able to create new apps themselves. So since I know the programming language... the clients wouldn't need to... but I will have a GUI where there are bunch of images and buttons... where they can click and I can add a if statement or create a new function.

I know would also like to be able to change properties of the html elements and then save it to file.

So there is no way the clients will do any php programming or write any code... I be doing it via my own script. Just would give them the GUI ability to create their website layout their way.
Was This Post Helpful? 0
  • +
  • -

#8 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 947
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: how can php manipulate other php files ?

Posted 18 July 2011 - 12:30 PM

That's client side coding. Javascript is what you'll use to make the code then send it to the server. Even if your GUI writes the code malicious coders can still send code of their own to your server side script via cURL or through sockets. I'd suggest using BBCodes instead of actually developing the code. This would give you control over what the gets executed since I don't think you'll have any malicious BBCodes.
Was This Post Helpful? 0
  • +
  • -

#9 hockey97  Icon User is offline

  • D.I.C Regular

Reputation: -77
  • View blog
  • Posts: 300
  • Joined: 25-September 08

Re: how can php manipulate other php files ?

Posted 18 July 2011 - 01:01 PM

View PostMartyr2, on 17 July 2011 - 11:39 PM, said:

Do realize that PHP script files are just text. You can edit them just like any text document. Read in the entire script into your GUI (like into a multiline text box), edit it there, then save the entire contents back to the file.

PHP is just text that contains code that is passed to an interpreter where it is then executed. It is not like compiled languages or anything.

:)



ya, I do know it's text. I know how to open text files via php... the thing is that I am new to file manipulation. I only know the basics... I know about string replace function and how to add new lines to the file and delete lines.

the problem is that I only know that you can delete a whole like.. so if I had like 3 different code on line 5 and I only wanted to delete just one of them... I would only be able to delete the whole line 5 which means I deleted all 3 codes... even though I only wanted to just delete just one.

yet, there is string replace... where you can search in the file for extact words and replace them with new words or a blank. Problem with this is... if you want to delete some code you will need to know all the letters symbols or words used and you need to throw that at the string replacement function of php. then you can delete that code in the file.

Now, I don't know if there is a way where I can get the user to click on something in the webpage and they can select or I can load in that code to a variable and then pass it to my gui editor when changes are made... so I can delete the exact code.

Right now I am thinking to make a class of code and then just call it in the clients webpage. and the gui will generate the proper code to grab certain code from the class.

my goal is to make a GUI for my client where they can add in new html elements into the page and also make changes to the php and javascript... so they can create their own custom effect.

Like for instance... my client might be a artist and he wants to show off his artwork. You may think well he will be bored if I only give him like 5 different gallery options.
with my gui he will be able to upload his own artwork and use that artwork to create a high end gallery for himself... it be something totally new and can show off his work in a artistic way.. he may do this as part of his resume to get jobs etc.

So I want to let the user to be in control. They don't touch any code at all. I will do that with my own scripts.

The problem I have is I don't know intermediate to advance stuff for file manipulations in php or any other language.

All I know is how to open a file, how to close the file, how to load the file inside a div and how to delete lines inside the file or add lines inside a file. you can add the lines at the start or add then at the bottom of the file. I know about emplode and explode. where it takes a string and breaks it up. I used it for a form where I had the user give me the phone number. I would get a full string of numbers... but knowing the phone number format. I would split the numbers up to at - inbetween them.. and store this in my database.

that's all great but I don't know how php makes changes to html elements and how I can use it to find in the file the exact code without tossing the whole code to search for. For instance how can I delete a function. I mean we all know the format it's like function tom() { } in between { } is the code we run when the function is called.. so can I just tell php to delete function tom and will it delete the whole function including the code inside { } the brackets.

If I can't do this without knowing the exact code meaning I have to tell php exactly each character to select or delete in the file. Then how can I select the code? if that is the only way then I need to find a way where when the user uses my GUI and wants to delete or modify something.. I should be able to select that whole code that needs to be modified or deleted and make the changes accordingly.
Was This Post Helpful? 0
  • +
  • -

#10 hockey97  Icon User is offline

  • D.I.C Regular

Reputation: -77
  • View blog
  • Posts: 300
  • Joined: 25-September 08

Re: how can php manipulate other php files ?

Posted 19 July 2011 - 12:41 AM

what I want to do is generate javascript,php, html code via GUI.

the user uses the GUI which will run functions that will generate the proper code. Then I will save this code in the clients webpage file. so that way they can customize their webpage and even program and generate effects for the page without actually being limited to templates or pre-coded effects and functions etc.
Was This Post Helpful? 0
  • +
  • -

#11 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 947
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: how can php manipulate other php files ?

Posted 19 July 2011 - 06:09 AM

Suppose I upload this to your server using cURL then run it? Then what?

Script that deletes files


Accepting raw code from the client is always dangerous.

CTphpnwb edit: codeprada, I know you mean well, but let's not give any potentially malicious script kiddies any more ammunition than they already have. ;)

This post has been edited by CTphpnwb: 19 July 2011 - 06:35 AM
Reason for edit:: removed potentially malicious script

Was This Post Helpful? 0
  • +
  • -

#12 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3000
  • View blog
  • Posts: 10,390
  • Joined: 08-August 08

Re: how can php manipulate other php files ?

Posted 19 July 2011 - 06:33 AM

I think hockey97 intends that the user won't upload any scripts, but his code will generate them based on user actions. I tried to make clear in post #6 that PHP shouldn't be changing, instead you might include/require different PHP files and you would have your PHP alter HTML so that it uses different CSS to style the page.
Was This Post Helpful? 0
  • +
  • -

#13 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 947
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: how can php manipulate other php files ?

Posted 19 July 2011 - 06:42 AM

From the sound of it it seems like it'll be generated client side.
Was This Post Helpful? 0
  • +
  • -

#14 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3000
  • View blog
  • Posts: 10,390
  • Joined: 08-August 08

Re: how can php manipulate other php files ?

Posted 19 July 2011 - 06:49 AM

From post #1:

View Posthockey97, on 18 July 2011 - 01:33 AM, said:

I will then have a gui interface where the client can add windows or change properties of lets say the body.... to different colors etc. They can also manipulate the php file too... where they can do a mysql query... using my GUI.

To me, manipulating any of the code using the gui would essentially tell the server what code to call up and use, not how to write it. So the initial empty PHP file would let them add preset scripts to it. I don't think this is really necessary since you're really trying to manipulate HTML and CSS.
Was This Post Helpful? 1
  • +
  • -

#15 hockey97  Icon User is offline

  • D.I.C Regular

Reputation: -77
  • View blog
  • Posts: 300
  • Joined: 25-September 08

Re: how can php manipulate other php files ?

Posted 20 July 2011 - 11:22 AM

View Postcodeprada, on 19 July 2011 - 07:09 AM, said:

Suppose I upload this to your server using cURL then run it? Then what?

Script that deletes files


Accepting raw code from the client is always dangerous.

CTphpnwb edit: codeprada, I know you mean well, but let's not give any potentially malicious script kiddies any more ammunition than they already have. ;)


no, Like I said it before. No raw code will be passed from my clients to my server. It be variables or phrases... my code on the server side will generate the raw code. I will code the stuff myself... the clients will just use a GUI that will send veriables to text phrases to my own scripts which will understand what they want... weather it be a if statement to be generated or a new function. The client won't ever touch raw code. My own scripts on my server will touch the raw code... basically it will generate the code and save it to their own file.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2