json and php settings - php

I am passing a json encoded string from javascript to a php file on the server via ajax. on my online server this works fine. but locally, it does not.
There are a few differences in the php installs in the 2 places. minor ones. both are php4. the install locally is actually a newer php4.
I'm trying to track down why this is happening. It looks like the json parsing on the server side with the pear servies_json (json.php), isn't parsing correctly. It manages the first brackets, but then it stops there, and all the internal data is lost?
Is there a php plug in or something that I need to install that keeps this from happening. A setting switch? Thanks for any help.

json_decode() should be used on the server-side to decode the JSON object, it should work fairly consistently. Its sister function json_encode() is equally good for encoding an array/object to a JSON string which can be echoed in your javascript.
Both functions require php 5, for php 4 you can check out this code.

Related

PHP 5.1.6. json_decode slow

Because PHP 5.1.6. doesn't include the json_decode function, I've downloaded an alternative and included it myself. But for some reason it's really really slow.
This one for example I tried:
http://mike.teczno.com/JSON/JSON.phps
I have tried a few other alternatives.
Does somebody know a better alternative to decode json faster or is it impossible in PHP < 5.2

Why do I need a server for practicing PHP?

I took a PHP course on a site called Codecademy.com, and I later learned that you needed a server to practice PHP independently. I don't want to host a server, because all I want to do is practice PHP. Why is this so?
Your need for a "server" is really just a need for some kind of PHP runtime. Since version 5.4, PHP includes an integrated webserver for you to do just this kind of thing, so as long as you install a recent version of PHP you have everything you need.
What You need to understand is that PHP is server-side.
That means if You open a php file without a server,
you will see the code, and not the result of php,
because PHP must be processed by PHP parser.
That's why You have to use a server, but You can open one locally, using a program such as:
XAMPP

How to use Xdebug to decode Ioncube

I have been researching for a few days now, and have found no useful tutorials or guides on how to perform a decode of an ioncube encoded file by using xdebug.. Multiple SO post answers do not serve a starting place for a complete beginner.
In short: You can't.
In long:
IonCube is an encoder, and Xdebug is a debugger - not a decoder. It does not know how to read encoded files and even if it could get into the process of intercepting the PHP things that it does, it still won't be able to show you the source code.
When a file is encoded, it is first converted from text into "opcodes"—that is an internal representation of binary stuff which PHP can execute. At this stage, it is already useless for Xdebug.
And then it is encoded, which makes it even less possible to do anything with.

php echo and echo json_encode returns weird characters

So I was developing something with PHP and MongoDB on windows with xampp, and I moved my php files to linux mint, it runs apache2 with php cgi 5.4.
After I moved my files (without changing) to linux, the php started returning these weird characters after every response.
echo 'success';
response comes like this
sucess����������������
when converted it looks like this
sucess�
It seems like they are appended to the end of everything, here is a screenshot of responses with firebug (only left side of the pic)
Link to the Image
Also mongod started echoing some errors that never existed on windows (right side of the picture for reference).
I do not use any special characters, languages, encodings, nothing of that sort.
Did anyone experience anything like this?
Mongo stores all strings as utf-8 and expects them to be delivered as such. Simply convert your data to utf-8 before getting it from mongo and you're set.

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