-3

I'm using a download api for some applications. So when I'm entering the URL 1, I'll get the new generator URL2 as a result.
Here is my code:

<?php
$json=file_get_contents("URL 1");
$details=json_decode($json);
if($details->Response=='True')
?>
 <?php echo $details->data;?>

This is what I'm getting as result from the URL 1:

{"data": "URL2"}

I need the result of url 2 witches almost similar result as URL2

{"data": "DOWNLOAD LINK"}

I found on way just to post it to other page which is something that I don't want.

I want once I enter the first page it should download by it self.

ANY IDEA?

mickmackusa
  • 43,625
  • 12
  • 83
  • 136
Zabi
  • 23
  • 9
  • If $details->data is just a URL string to the JSON data you need then I suppose you must fetch that into a new variable. `$result2 = json_decode(file_get_contents($details->data));` - Please explain if that's not what you meant – KEK Feb 15 '18 at 12:25
  • 1
    You need to clarify your question. I've read it a few times and still doesn't really know what you want to do or what the issue is. – M. Eriksson Feb 15 '18 at 12:25
  • Please just take a look to my code – Zabi Feb 15 '18 at 12:26
  • Let me make a screenshot – Zabi Feb 15 '18 at 12:30
  • Please take a look to this url @KEK http://2strok.com/download/download.json – Zabi Feb 15 '18 at 12:35
  • @MagnusEriksson please take a look to this link : http://2strok.com/download/download.json – Zabi Feb 15 '18 at 12:35
  • I'm not going to click on some external link. Even if I did, I still don't really understand what the actual question is so it wouldn't help much. You need to update your question to include _all_ relevant information and code, including a detailed explanation/examples about the expected behavior and what actually happens. Remember, we're not there with you. We have no idea what you're code suppose to do. – M. Eriksson Feb 15 '18 at 12:39
  • @MagnusEriksson I'm really sorry how can i explain it more to you. It should be a very very simple and easy for you guys. I'm not may good in english but I'm showing you on the second link i made to clear it :D – Zabi Feb 15 '18 at 12:44
  • We don't just need links and code, we also need to understand the issue. The only way we can do that is through your explanation. If we don't, we won't be able to help no matter how much we want to. We've already told you that we don't understand the issue, but you haven't made any attempt to update your question at all to make it clearer. I'm out. – M. Eriksson Feb 15 '18 at 12:49
  • @MagnusEriksson I'm really sorry i couldn't make it more clear. – Zabi Feb 15 '18 at 12:50

1 Answers1

0

Using similar logic to the answer here: https://stackoverflow.com/a/11545741/733547

First, you get the response from "URL 1", json decode it, and set the decoded object to $details1. Then, using the $details1->data field (containing "URL 2") perform the same steps and set the "URL 2" decoded response object to $details2. Once you have that, you can echo the "URL 2" data. I'd also recommend checking that the responses actually return the data structure you expect them to, which is what the if statements are performing.

// pull URL 1's details
$details1 = json_decode(file_get_contents("URL 1"));
if (!empty($details1->data)) {
    // pull URL2's details
    $details2 = json_decode(file_get_contents($details1->data));
    if (isset($details2->data)) {
        // display the data value as a hyperlink
        echo "<a>{$details2->data}</a>";
    } else {
        // display an error message.
        echo "Unable to retrieve data.";
    }
} else {
    // display an error message.
    echo "Unable to retrieve data.";
}
Bryce Siedschlaw
  • 4,136
  • 1
  • 24
  • 36
mickmackusa
  • 43,625
  • 12
  • 83
  • 136
  • @mickamacxhusa . please take a look :D http://2strok.com/download/download.json Nope sorry – Zabi Feb 15 '18 at 12:40
  • how can i get the result of this link when it's changing all the time : http://2strok.com/download/17472558997ec4f508441f4849dd9b8e-dfde3acc01675ab6c4ee9f9088ba8de8.json – Zabi Feb 15 '18 at 12:42
  • YES but i tried your code. it did not gave me any respons – Zabi Feb 15 '18 at 12:46
  • ONE think i need to remind you. the second URL i'm getting as a result is refreshing and generating a new url :P – Zabi Feb 15 '18 at 12:47
  • yeah : = Could not retrieve details1 – Zabi Feb 15 '18 at 12:54
  • Do you want to do something like this? https://stackoverflow.com/q/11545661/2943403 – mickmackusa Feb 15 '18 at 13:04
  • Hi again @mickmackusa, the script were working good until today I'm getting error: Warning: file_get_contents(): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in – Zabi Feb 17 '18 at 16:27
  • Sounds like you have a file path that leads to a non-existent file. You will need to investigate why this is happening. In your script, you can add a condition that checks if a file exists before calling `file_get_contents()`, but if it's not there, there's nothing programmatical to change. – mickmackusa Feb 17 '18 at 20:46