1

I have this link I want to parse some information in it or just save it in a file...

can't do it without this simple code:

Example:

<?php
$myFile = 'test.txt'; 
$get= file_get_contents("http://www.ticketmaster.com/json/resale?command=get_resale_listings&event_id=0C004B290BF2D95F");
file_put_contents($myFile, $get); ?>

The output is:

{"version":1.1,"error":{"invalid":{"cookies":true}},"command":"get_resale_listings"}

I tried many other things like fopen or include did not work either. I don't understand because when I put the url in the browser it shows exactly ALL the code (google chrome) OR even better ask me to save it as a file (explorer). Looks like a browser cookies or something that doesn't load on my localhost ??

thanks for your tips.

Alex Choroshin
  • 6,177
  • 2
  • 28
  • 36
  • you could take a look into this question: http://stackoverflow.com/questions/3938534/download-file-to-server-from-url but as it says in the comments it may be the php.ini setting: allow_fopen_url set to off which would break the code. – Samuel Lopez Mar 28 '14 at 00:08
  • thanks but the allow_fopen_url is on, did not work either. – user3470727 Mar 28 '14 at 14:18

1 Answers1

1

You need to access that url with CURL.

The server checks if the client has cookies enabled. Using file_get_content() You do not send any information about client (browser).

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.ticketmaster.com/json/resale?command=get_resale_listings&event_id=0C004B290BF2D95F');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_exec($ch);
Filip Górny
  • 1,749
  • 16
  • 24
  • OK... but the cookies are located in the Content Settings of my browser, how can I put them in my_cookies.txt ? – user3470727 Mar 28 '14 at 04:46