Is it possible to invalidate the php utf8_encode / decode function? - php

My website has been running for a long time.
Currently upgraded to php 5.6 and maria db 10.1.44.
The utf8_encode function was used in a lot of php code.
But now I have to remove it so the characters are output correctly.
However, I can't edit a lot of php code ... Is there a way to invalidate the utf8_encode function?
Or is it possible to override the php core function?

Yes you could do so by making some changes in the php.ini file as
Disable PHP Functions

You could override utf8_encode() with function_override() but I can not recommend it.
Instead, you better fix the existing code yourself. When you use an IDE like Eclipse PDT, you can do a global search in all files and folders, and remove the calls to utf8_encode() rather quickly.
While PHP 5.6's default encoding has been changed to UTF-8, that version is already end-of-life: https://www.php.net/supported-versions.php. After moving up to 5.6, consider migrating your code to PHP 7.2 at least.

Related

Ioncube - PHP code obfuscation without encoding

Is there a way to obfuscate PHP code with Ioncube without encoding it?
I.e. the code is just obfuscated and it can be executed without the ioncube loader?
I am not 100% sure but I remember it was possible with an old version of Ioncube and now (v. 8.3.2) I can't find the way to do it: I still have an obfuscate option but it seems it always work in addition to encoding
It seems that it is not possible and it has never been possible to obfuscate only: http://forum.ioncube.com/viewtopic.php?p=10797#10797

How do I disable magic_quotes_runtime in PHP 5.5?

I'm trying to migrate a script in php 5.2 to 5.5 that uses set_magic_quotes_runtime() to disable them. I found a hint that suggested I could replace it with:
ini_set ("magic_quotes_runtime", 0);
Is this correct?
Simply delete the line.
Magic quotes have been dead for some time, and have been removed in PHP 5.4 and later. There is no reason to force them to off when they don't exist.
If you are trying to turn them off, there's nothing to be done - the feature has been removed from PHP entirely since PHP 5.4. There's no need for the line you cited at all in PHP 5.5.
If you are trying to turn them on, you would need to recreate the feature in userland using something like str_replace(); however, I would urge you not to do it.

Migrating php code from 5.2 to 5.3

I was asked to help getting a website that was running with 5.2 php code, to work on a 5.3 php server. The site is big, and I can't see the errors that would appear normally when a site isn't working.
I've tried to use the Search and replace function that Dream Weaver has, and simply use it all over the website. But the problem is that I only want to replace functions in PHP documents, and not in js files. When i use Search and replace, in Dreamweaver, it overwrites the js files aswell, and that would cause more errors. Because there's A LOT of files that i have to go through, it would take me a lot of time if i had to go through it manually.
I figured this must be a problem that a lot of firms experiance, so there must be ways to handle this without it being a bigger hassle.
Anybody out there who could help me out ? Any help is much appreciated!
Regards,
Mathias
Check out the official guide about Migrating from PHP 5.2.x to PHP 5.3.x
most existing PHP 5 code should work without changes, but make sure error-reporting is enabled to get some idea of what is going wrong .
I would recommend the use of sed from command line. It is most likely the fastest and most powerful find/replace utility available for LAMP developers.
http://www.grymoire.com/Unix/Sed.html
Dont worry about it! If your code works in php->5 for the most part it will work just fine. 5.3 offers a plethora of options but no doubt your not using them.

How can I add a specific PHP function to my server's install of PHP

I am running PHP version 5.1.6 currently, but I would have an application which makes pretty heavy use of the json_encode and json_decode functions, as such, I would like to add these functions to my server's install of PHP (as these functions only ship with PHP versions PHP 5.2 +)
What is the best way of doing this. I'm not too down with the whole Terminal approach so if there was another way that would be great
Many thanks in advance
If you're unable to upgrade, use PEAR's Services_JSON. It works as of PHP 4.3 so you should be fine.
Maybe you should put somewhere in the root of your application a call to a checker function that does function_exists() for a couple of your needed function and if not stops the execution to prevent unwanted results.

php 5.1.6 json_encode and codeigniter

Im building a codeigniter app which uses json_encode to provide ajax data in many places... today I learned that the server has php 5.1.6 which doesnt support this method (or json_decode).. what can I do?? please help.
There is an emulation of json_encode() in upgradephp. Just include() that script, and you don't need to rewrite anything.
As alternative you can use PEAR::PHP_Compat. IIRC it has an emulation of that too.
(There are further alternative implementation floating around; but often object-style and not as fast and designed to emulate the core function.)
You can set them up with auto_prepend_file= even. If you just want the JSON extension enabled, there are other sources of course.
You could use Services_JSON if CodeIgniter can use it instead of PHP 5.2's json_* functions - I know Zend_Framework has Zend_Json which uses json_* functions if available, otherwise it uses its own implementation in userland PHP code as a fallback.
Of course, if you have access to the server to compile PHP, you could try the extension or upgrading to PHP 5.2 (a better solution).
EDIT: I would take the route of compatibility layers as mentioned above.
The json_decode is added since (PHP 5 >= 5.2.0, PECL json >= 1.2.0), it is supported in your version too, you should give it a try :)
I needed json_encode and json_decode for jquery grid.
I tried upgradephp but json_encode didnt seem to work with jquery grid so I deleted that function from the file and added this one. json_decode seems to work just fine though.
In fact, 5.1.6 supports json_decode and json_encode, but they can be a bit weird. As in, if you feed it invalid JSON, such as if you have a blank key, it will die without any warnings or errors. But I use json_encode and json_decode every day in a 5.1.6 environment. It's totally possible.

Categories