Last active
August 29, 2015 14:24
-
-
Save matthewpoer/a0538d0952ac96957a7e to your computer and use it in GitHub Desktop.
Attempt to demonstrate a potential PHP Bug wherein a string of data that includes an equals sign (=), when json_encode()'d twice and delivered to a web server, will be interpreted as a split in a data array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo "<h1>JSON Array to Double Array PHP Bug(?)</h1>"; | |
echo "<p>Attempt to demonstrate a potential PHP Bug wherein a string of data that includes an equals sign (=), when json_encode()'d twice and delivered to a web server, will be interpreted as a split in a data array.</p>\n"; | |
$array = array( | |
'one' => 'one is one', | |
'two' => 'two = two', | |
); | |
$encoded_once = json_encode($array); | |
$top_array = array( | |
'requests' => $encoded_once, | |
); | |
$encoded_twice = json_encode($top_array); | |
echo "<h2>Building the request</h2>"; | |
echo "Child Data: \n"; | |
var_dump($array); | |
echo "The Child Data array is json_encode()'d and appended to the Parent Data.<br>\n"; | |
echo "Parent Data: \n"; | |
var_dump($top_array); | |
echo "The Parent Data is again json_encode()'d and and will be sent to the server.<br>\n"; | |
var_dump($encoded_twice); | |
echo "Sending to service ...<br />\n\n"; | |
$url = 'http://localhost/~matthewpoer/EqualsTesting/ApiServer.php'; | |
/* | |
* begin cURL setup | |
*/ | |
$curl_request = curl_init($url); | |
/* | |
* the Request will be different for differnet | |
*/ | |
curl_setopt($curl_request, CURLOPT_POST, 1); | |
/* | |
* set cURL options, including a 10 minute limit on waiting for the | |
* server's response and 2 minute limit waiting on its connection | |
*/ | |
curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | |
curl_setopt($curl_request, CURLOPT_HEADER, false); | |
curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0); | |
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0); | |
curl_setopt($curl_request, CURLOPT_TIMEOUT, 600); | |
curl_setopt($curl_request, CURLOPT_CONNECTTIMEOUT, 120); | |
curl_setopt($curl_request, CURLOPT_POSTFIELDS, $encoded_twice); | |
$result = curl_exec($curl_request); | |
echo "<h2>Server Results:</h2>"; | |
echo $result; | |
curl_close($curl_request); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
var_dump($_REQUEST); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>JSON Array to Double Array PHP Bug(?)</h1><p>Attempt to demonstrate a potential PHP Bug wherein a string of data that includes an equals sign (=), when json_encode()'d twice and delivered to a web server, will be interpreted as a split in a data array.</p> | |
<h2>Building the request</h2>Child Data: | |
<pre class='xdebug-var-dump' dir='ltr'> | |
<b>array</b> <i>(size=2)</i> | |
'one' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'one is one'</font> <i>(length=10)</i> | |
'two' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'two = two'</font> <i>(length=9)</i> | |
</pre>The Child Data array is json_encode()'d and appended to the Parent Data.<br> | |
Parent Data: | |
<pre class='xdebug-var-dump' dir='ltr'> | |
<b>array</b> <i>(size=1)</i> | |
'requests' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'{"one":"one is one","two":"two = two"}'</font> <i>(length=38)</i> | |
</pre>The Parent Data is again json_encode()'d and and will be sent to the server.<br> | |
<pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font color='#cc0000'>'{"requests":"{\"one\":\"one is one\",\"two\":\"two = two\"}"}'</font> <i>(length=61)</i> | |
</pre>Sending to service ...<br /> | |
<h2>Server Results:</h2><pre class='xdebug-var-dump' dir='ltr'> | |
<b>array</b> <i>(size=1)</i> | |
'{"requests":"{\"one\":\"one_is_one\",\"two\":\"two_' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>' two\"}"}'</font> <i>(length=9)</i> | |
</pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JSON Array to Double Array PHP Bug(?) | |
Attempt to demonstrate a potential PHP Bug wherein a string of data that includes an equals sign (=), when json_encode()'d twice and delivered to a web server, will be interpreted as a split in a data array. | |
Building the request | |
Child Data: | |
array (size=2) | |
'one' => string 'one is one' (length=10) | |
'two' => string 'two = two' (length=9) | |
The Child Data array is json_encode()'d and appended to the Parent Data. | |
Parent Data: | |
array (size=1) | |
'requests' => string '{"one":"one is one","two":"two = two"}' (length=38) | |
The Parent Data is again json_encode()'d and and will be sent to the server. | |
string '{"requests":"{\"one\":\"one is one\",\"two\":\"two = two\"}"}' (length=61) | |
Sending to service ... | |
Server Results: | |
array (size=1) | |
'{"requests":"{\"one\":\"one_is_one\",\"two\":\"two_' => string ' two\"}"}' (length=9) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment