My question is how to encode php codes but I am not looking for a site to do it ( or a program ) .
I am asking how to encode manually ? I mean how to change out codes into an unknown string so others may not understand what our codes are .
If you're looking for a compiler to compile your PHP code into byte code and add some obfuscation so that others cannot gain access to your code. Here are a few:
http://www.phpcompiler.org/
http://www.php-compiler.net/
https://github.com/facebook/hiphop-php/ - This one is launched by Facebook
http://www.bambalam.se/bamcompile/
http://sourceforge.net/projects/binaryphp/
http://www.roadsend.com/home/index.php?pageID=compiler
Some (if not all) of these compilers have features to obfuscate your code.
More at Can you "compile" PHP code?
Related
Is it possible to encode a php script that can't be decoded or at least the most secure way?
Yes, but the PHP script will not be able to encode and decode itself. You would need to write another program to do it on behalf of the PHP script. However, you can obfuscate the text using the combination of base64_decode and eval. This allows you to insert code so that someone cannot do a simple Ctrl+F search for a function that may be foreign. For example this is "Hello World":
eval(base64_decode("ZWNobyAiSGVsbG8gV29ybGQiOw=="));
This applies to the content of the PHP code, not the file.
You mean that you want to distribute your code, but not let anyone else read / decompile it.
Zend write PHP, so the best place would be to consider using their encoder for this purpose: http://www.zend.com/en/products/guard/ You can also add licencing to the distribution.
There are others out there that obfuscate code - but obfuscation doesn't stop people copying it and, in many cases, won't stop someone from editing it if they really want to.
This question already has answers here:
encoding php scripts on fly [duplicate]
(4 answers)
Closed 9 months ago.
I have a PHP script,
for example
<?php
$name="Alfred";
echo $name;
?>
I used following script to encrypt,(by www.rightscripts.com/phpencode/index.php)
<?php
eval(gzinflate(str_rot13(base64_decode('encrypted code'))));
?>
But it only print "$name="Alfred";" and "Undefined variable $name".
What is the problem ? Is there any other solution ? Please help me ?
"Encoding" this way doesn't really protect you from anything.
The encoded PHP code is on the server, and so is the code that decodes it back to regular PHP.
If someone has sufficient access to your server that they can read your encoded PHP scripts, then it is almost certain that they also have sufficient access to read the decoder script. Which means your code isn't actually protected at all.
There are a number of obfuscators and encoders which can do what you want, but at the end of the day, all you're really doing to your code is slowing it down (eval() is a major performance killer, quite aside from its other issues).
A better solution might be to compile your code. There is a PHP compiler called HipHop which will do the trick for you. It's worth giving it a try.
Even with compiled code (in any language), it is still possible for someone who's determined to pull it apart and learn your secrets, but it'll be a lot harder than a simple encoded script, and also it should run faster than normal when compiled, compared with slower than normal when encoded, so you win both ways.
The situation is next:
I have php file, which parses a web-page. on that web-page is a phone number and it's digits are mixed with each other. The only way to put each digit on the correct place is to use some JS functions (on the client side). So, when I execute that php file in linux console, it gives me all that I need, except js function's result (no wonder - JavaScript is not a server-side language). So all I see from JS - only a code, that I have written.
The question: can I execute js files via php and how?
Results of a quick google search (terms = javascript engine php)
J4P5 -- not developed since 2005 [BAD](according to its News)
PECL package spidermonkey
a 2008 post by jeresig points to PHPJS but can't see when it was last updated.
I'm sure you'll find many more links on that google search.
Alternatively:
you say that the digits are scrambled and you need to "unscramble" them using js. Can you code that unscrambling logic into a PHP function and just use it? Will sure save you a lot of trouble, but if learning to use js in php is what you're after, then its a whole different story...
Zend tutorial: "Using javascript in PHP with PECL and spidermonkey"?
http://en.wikipedia.org/wiki/Comparison_of_Server-side_JavaScript_solutions
Alternatively, PHP has simple functions for executing other programs and retrieving their output (I used this along with GPG once to create a PHP file manager which could live-encrypt files as you were uploading them and live-decrypt as you were downloading them)
Using those functions along with http://code.google.com/p/v8/ you should be able to interpret any javascript.
Not unless you know someone who's implemented a Javascript engine in PHP.
In other words, probably not.
Without some sort of browser emulation or passing the unparsed js off to a server side implementation of javascript (maybe node.js?), you won't be able to execute it.
However, does the page use the same js function to unscramble the phone number every time? You should be able to read the incorrect digits and shuffle them with PHP.
If you're prepared to do a bit of work building your own JS runtime to work with it, Tim Whitlock has written a javascript tokenizer and parser in pure PHP
node.js is server-side... but full JS :) no PHP in it so I don't it answer your needs...
Anyway, here is an example : a chat in JS both client & server-side : http://chat.nodejs.org/
Plus, not every host allows you to use the v8 engine...
If you have Javascript data objects, and you need to convert them to/from PHP arrays, that's quite easy using PHP's json_encode() and json_decode() functions.
But actually running Javascript code? No. You can't. You might be able to find a JS interpreter written in PHP (a few other answers have pointed a links that may or may not help you here), or more likely execute the JS using a stand-alone JS interpreter on your server which you call out to from PHP. However if the JS code includes references to the browser's DOM (which is highly likely), that's a whole other set of issues which will almost certainly make it impossible.
Given the way you describe the question, I'd say the easiest solution for you would just be to re-implement the JS code as PHP code; it's unlikely that all the work arounds being suggested would be appropriate for what sounds like a fairly simple bit of utility code.
See How to escape quote PHP strings generated by Delphi?
I am just interested to hear if anyone has used Delphi (or possibly BCB) as a code generator for PHP ...
(or thoughts about code generation from one language to another in general)
Hmm, any good books about code generation ?
I've generated javascript, SQL and Delphi many times. But mostly is basic substitution, (and the example in the post you mention looks the same), not really codegeneration in the "compiler" sense of the word.
But there are also many real compilers in Pascals and Delphi like dialects. The biggest one I think is Free Pascal (http://www.freepascal.org), which is a compiler for Object Pascal (aka delphi)
(added later:)
Besides variable substitution, basic templating engines also fall in this category. Templates are sometimes easier maintainable than the same fragement code. Specially in html/cgi land this is used a lot.
You can generate anything from a tool which can export text files no?
You can write all by the hand, or in a "delphi style" by using Delphi for PHP http://www.embarcadero.com/products/delphi-for-php
best regards,
anyone has used Delphi (or possibly BCB) as a code generator for PHP
PHP - no, but I'm generating a lot of Delphi/Pascal code from Delphi. I've also generated all other things used for a web application: HTML, JavaScript, CSS - but never PHP because I didn't need that. So it's possible, but simply knowing it's possible is not going to help you much.
thoughts about code generation from one language to another in general
You need to look into "text template engines" for Delphi. I can't suggest any because I wrote my own (and I'm not planing on releasing my own under any license).
Update:
This question is a duplicate of Are there any programming languages targeting PHP, besides Haxe?
The answers given here appear to be disjoint from those given at the other node, so this question was not (yet) deleted. If possible, please merge the answers here into the other node.
Question:
Is there any such thing as a programming language (other than an esoteric language such as BrainF##$, or the languages PHP or VB) that you can "compile" into non-obfuscated PHP source code?
Rationale:
Swip wants to generate ordinary PHP code because it is so ubiquitous for the types of projects swip wants to do. Unfortunately swip would like to actually avoid writing PHP -- strange but true! Swip is crazy enough to want to generate PHP source code without having to type any PHP into Swip's editor.
Take a look at
http://github.com/juliend2/phlower
This project claims about itself:
phlower (pronounced flower) is a small ruby script that compiles the Awesome code (invented by MACournoyer for his book void://createyourproglang.com/ ) into PHP code.
This script is written in Ruby and it depends on the racc gem.
Wasabi compiles down to PHP, but you'll have to beg Joel Spolsky for a copy.
I don't know what swip is, but this is not really possible. There are tools to aid the programmer in doing this, but they will not run without deep human interaction and refactoring. What you want is a skilled programmer.
Edit
I think I misunderstood, you want a scripting language to script PHP? While php compiles to bytecode internally, it isn't like java or .net where you can use different languages to do it. What are you trying to accomplish?