I am not sure if this is even possible since I m new to PHP. I have a URL (for instance: http://www.mysite.com/data/response/) which gives me some cookie data as json respose ( {“cookie_name”:”value”,”ttl”:60} ). I have a php script that thows some output based on a cookie value. So, right on top of this php script I need to make a call to the above url, get the json response/interpret it and set a cookie based on the response. Can someone please help me with this?
Many thanks in advance.
L
Here it is:
As cwallenpoole mentioned in comments below, make sure that
allow_url_fopenruntime configuration variable is set to TRUE (it is by default). If not – useini_set('allow_url_fopen', 1), but it may be restricted by safe mode I think 🙂json_decodefunction has been introduced in PHP 5.2.0. If you have PHP >= 5.2 andjson_decodeis not available, please check if JSON extension is enabled (extension=json.soin your php.ini) and if you PHP was combiled with--disable-jsonflag.If you use pre-5.2 PHP then you can use following code (introduced by Anonymous user on PHP.net):
If
allow_url_fopenis set to 0 and you cannot change it byini_setor by setting it in your php.ini file, that you can stick to cURL (if cURL extension is enabled :)):The rest code should work as in first example. Hope it helps!