How to encrypt a part of a PHP script [duplicate] - php

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.

Related

Perl: How to do a PHP-style include? [duplicate]

This question already has answers here:
Is there any way to "auto-use" certain modules everytime I write a script?
(2 answers)
How can I export a list of modules with my own module?
(1 answer)
Closed 7 years ago.
In a PHP include, code is parsed as if it was written right into the source file. You get the same result as if you literally copy and pasted file A into file B.
I'm looking for a way to do this in Perl. The number of libraries I have to 'use' in every script is getting annoyingly large, and especially annoying is having to use v5.14 just so I can have the say function. I'm actually looking up how to alter the interpreter to always use the latest version of Perl at this moment, compatibility with the rest of the world be damned, but this won't solve the rest of my list of includes.
Edit: none of the linked answers answer the question.
The equivalent of PHP's include is do EXPR. There is also require EXPR, which is like require_once, and use, which will also call import on the package.
However that is probably not what you want. If you have a lot of .pl scripts without packages, you are dealing with legacy code. You need to be carefull what you require and include where.

PHP Manual Encoding

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?

Create PHP Code Encryptor [duplicate]

This question already has answers here:
Obfuscate PHP code [closed]
(7 answers)
Closed 9 years ago.
Here goes my question I just started to investigate some of the php's methods to create Encrypted strings , and surprisingly I found quite alot .
Md5 , Sha1 , base64 , salts, str_replace(which isnt even of an encryptor ) etc etc. But here is my Real Question - Can i create similar to those CODE encryptors. Atm i can convert only strings,is it possable encrypt my whole PHP source code then decrypt it (with my own enccryptor) and run the Code . Sth like that - . Most of those i found are easily reversable.
Thx in advance!
There is no point in "encrypting" your code. Don't make too much a deal of it. There are billions of lines of freely available PHP code already. Anyone could have any code they want. So, just take it easy and put your efforts in improving your code instead of encoding it.

Is there any other alternative to PHP which allows me to deploy unreadable code on a server? [duplicate]

This question already has an answer here:
Closed 10 years ago.
I am developing a CMS which has a PHP Encryption engine. But as the PHP code is completely visible, the method of encryption of data is easily compromised as every person who purchases the product can read the code. I want to pre compile the PHP or use any other server side scripting language that allows me to give a file containing the byte code of the program and which carries out the exact same function as the original PHP file. Is there any such language?
I know that perl can be precompiled.
This might be useful: http://www.perlmonks.org/?node_id=402933

Is using php shorthands bad? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Are PHP short tags acceptable to use?
I'm just learning php and (been learning for about 6 months) and in a tutorial that I'm going through, it's using php shorthands, so when I looked it up on google, I came to this stack overflow question StackOverflow question where one of the popular answers says that shorthands are bad.
I know one of the following comments then suggest that it's not bad but I also remotely remember reading from a php book before that it's not always good to use them. So I'm a bit confused, are they bad or not?
It is generally a bad idea because of portability. All PHP configurations understand the <?php ?> tags, but not all are configured to use <? ?>.
Same thing goes for <? =$variable; ?> for printing.
They are not bad actually, but you can say that it's kinda a bit lazy sort of thing to do for a GOOD TECHNICAL programmer. Why I'm using this word "GOOD TECHNICAL" is because, since they know about the technicalities of PHP, then they should also know whether the shorthands will be of any use or not in the long run, whenever any adjustments is to be made regarding the fine tunings of the PHP Server.
But still, it's one of my views & may be it will not match with others' answers.
I personally never use them because I find it makes my code ugly, hard to read and harder to debug. I'm talking about shorthands like the one-line if statement.
Not every PHP configuration understands short open and ending tags, and not every programmer knows about shorthand notation so this might be a problem if you want to share code at some point. I wouldn't advise using it.
the code "<? ?>" depends on the "php.ini", you should change the state short open tag. While the code "<?php ?>" can run everytime everywhere, without any configuration.
I recommend you to use smarty template.It's perfectly easy to use. And code is beautiful.

Categories