Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Processing php code containing php file.

php processing .php file

  • Please log in to reply
5 replies to this topic

#1 chax

chax

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 88 posts
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Perl, PL/SQL, Lisp, Assembly, Fortran, VBScript

Posted 13 October 2012 - 11:13 AM

I need to write a php script which will process(compile/interpret) the contents of a file containing unprocessed php code. I don't want to produce any intermediate files to dump/store php processed code. Do let me know if it is at all possible.
The following won't work. The problem with this approach is that I don't know the pathname of the file unless the file is on my computer.
<?php
system("php -f QUOTED_COMPLETE_PATHNAME\FILENAME");
?>

  • 0
Size does matter for science and its laws changes accordingly.

#2 Colanth

Colanth

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 165 posts
  • Location:Fayetteville, NC, USA
  • Programming Language:PHP, (Visual) Basic, JavaScript, Visual Basic .NET, Pascal, Logo, Assembly, VBScript, Others

Posted 14 October 2012 - 04:26 PM

1) If you don't know where the file is, you can't access it. In any language. It's like getting to main street without knowing which city it's in. It doesn't matter which car you use, you can't do it.

2) The eval() construct (it's not a function, it's a construct) may do what you need.

3) As the first comment for the construct says, "If eval() is the answer, you're almost certainly asking the
wrong question. -- Rasmus Lerdorf, BDFL of PHP"
  • 1

#3 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 14 October 2012 - 08:08 PM

1) If you don't know where the file is, you can't access it. In any language. It's like getting to main street without knowing which city it's in. It doesn't matter which car you use, you can't do it.

2) The eval() construct (it's not a function, it's a construct) may do what you need.

3) As the first comment for the construct says, "If eval() is the answer, you're almost certainly asking the
wrong question. -- Rasmus Lerdorf, BDFL of PHP"


Crystal clear!

Now let me try to understand your problem better.

I assume you somehow have the code you want to run, meaning it came to you by an upload (which you can find out where in the temp folder the file is) or by a text stream. Meaning Soap, text message or an input-text html field. and that is why you mention no generation of intermediate files.

So...
eval should do the trick if you pass your actual string to it, but don't expect any magic from it.

Why exactly would you want a php to execute unknown external php code?
  • 1

#4 BenW

BenW

    CC Devotee

  • Community Manager
  • 976 posts
  • Programming Language:ActionScript
  • Learning:ActionScript

Posted 15 October 2012 - 12:46 PM

Why exactly would you want a php to execute unknown external php code?

I'm interested in this too. My first thought is that it sounds like a pretty major security risk.
  • 0

fss_overall.png

 


#5 chax

chax

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 88 posts
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Perl, PL/SQL, Lisp, Assembly, Fortran, VBScript

Posted 05 November 2012 - 05:33 AM

Thanks a million. I want to make it unreadable and/or inaccessable to people who try to access my files without the right tools. I feel it necessary after seeing rising number of hacking attempts.
  • 0
Size does matter for science and its laws changes accordingly.

#6 Colanth

Colanth

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 165 posts
  • Location:Fayetteville, NC, USA
  • Programming Language:PHP, (Visual) Basic, JavaScript, Visual Basic .NET, Pascal, Logo, Assembly, VBScript, Others

Posted 05 November 2012 - 09:57 AM

1) If this is your code, you do know the path of the file, since your installation procedure put it there.

2) Eval will obfuscate (hide from the user) your code from any casual user. Anyone who has a little programming experience will just unobfuscate it. If the PHP interpreter can read the obfuscated code, so can anyone with a little programming knowledge.

The only way to hide your code (and it's still not perfect, but it will keep it from most people) is to write it in a compiled language like C. (You can compile PHP too.) Then you have the problem of getting it to run as a website.

Any code you want to absolutely guarantee can't be read by anyone but you is code you don't let anyone have. If someone has it, someone can get past your attempts and decode it.
  • 0





Also tagged with one or more of these keywords: php, processing, .php file

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download