-2

I read this post Why does Google prepend while(1); to their JSON responses?

Can help what kind of php script for this ?

I try

$time=time();
$hash=md5(mt_rand(1,200000));

$arr = array('time' => $time, 'hash' => $hash);
while(1);json_encode($arr);

In Ajax answer i have error Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\foo\1.php on line 6

Community
  • 1
  • 1
Michael Phelps
  • 2,911
  • 5
  • 26
  • 56
  • 2
    It is performing an infinite loop and encoding the $arr, why are you doing this? – ka_lin Jun 27 '14 at 07:03
  • 10
    you should attach as string with JSON string data `echo "while(1);".json_encode($arr);` – Girish Jun 27 '14 at 07:04
  • 1
    @Girish yep, and the client which is making the request should strip the `while(1);` before parsing the JSON response. – Fabrício Matté Jun 27 '14 at 07:07
  • possible duplicate of [Why does Google prepend while(1); to their JSON responses?](http://stackoverflow.com/questions/2669690/why-does-google-prepend-while1-to-their-json-responses) – njzk2 Aug 01 '14 at 18:30

1 Answers1

3

Thank you Girish very much works :

1.php

<?php
$time=time();
$hash=md5(mt_rand(1,200000));

$arr = array('time' => $time, 'hash' => $hash);
echo "while(1);".json_encode($arr);

ajax -side

responseText=req.responseText.substring(9);
            var obj=JSON.parse(responseText);

            statusElem.innerHTML = obj.hash
Michael Phelps
  • 2,911
  • 5
  • 26
  • 56