Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieve content of another website
    primarykey
    data
    text
    <p>I want to get the content of another page. The background is that I wanted to make an AJAX request but due to the <code>Same Origin Policy</code> I cannot do this. Now I wanted to write an own PHP script on which I make the AJAX request. The URL looks like the following:</p> <blockquote> <p><a href="http://domain.com/subfolder/another_subfolder/index.php?id=1234&amp;tx_manager_pi9[parameter]=1&amp;tx_manager_pi9[category]=test&amp;tx_manager_pi9[action]=getInfos&amp;tx_manager_pi9[controller]=Finder&amp;cHash=123456789001233455332" rel="nofollow noreferrer">http://domain.com/subfolder/another_subfolder/index.php?id=1234&amp;tx_manager_pi9[parameter]=1&amp;tx_manager_pi9[category]=test&amp;tx_manager_pi9[action]=getInfos&amp;tx_manager_pi9[controller]=Finder&amp;cHash=123456789001233455332</a></p> </blockquote> <p>I tried it with <code>fopen</code>, <code>curl</code> and <code>file_get_contents</code>. Nothing from the works. The problem is if I put in the URL as string like</p> <pre><code>$results = file_get_contents('http://domain.com/subfolder/another_subfolder/index.php?id=1234&amp;tx_manager_pi9[parameter]=1&amp;tx_manager_pi9[category]=test&amp;tx_manager_pi9[action]=getInfos&amp;tx_manager_pi9[controller]=Finder&amp;cHash=123456789001233455332'); </code></pre> <p>it does work. If I put in a variable</p> <pre><code>$url = 'http://domain.com/subfolder/another_subfolder/index.php?id=1234&amp;tx_manager_pi9[parameter]=1&amp;tx_manager_pi9[category]=test&amp;tx_manager_pi9[action]=getInfos&amp;tx_manager_pi9[controller]=Finder&amp;cHash=123456789001233455332'; $results = file_get_contents($url); </code></pre> <p>I come to a wrong page. With the specific parameter I get a result. If the parameter are not given correctly it seems that I come to a default page. I can't make a sense out of it.</p> <p>The same for <code>curl</code>:</p> <pre><code>$curlSession = curl_init(); $options = array ( CURLOPT_URL=&gt;$url, CURLOPT_HEADER=&gt;false, CURLOPT_RETURNTRANSFER=&gt;true, CURLOPT_FOLLOWLOCATION=&gt;true ); curl_setopt_array($curlSession,$options); $results = curl_exec($curlSession); </code></pre> <p>This doesn't work. If I put in the URL as string and not as variable I get some results! I thought that the ampersand <code>&amp;</code> or the square brackets <code>[]</code> are the problem but I cannot say this. <code>&amp;</code> should be reserved and <code>[]</code> are no correct URL parameters. But why does the direct input work and not the variable?</p> <p>I used the variable because I make some replacements with <code>str_replace</code> where I make the query more flexible.</p> <p>I saw similar questions here (<a href="https://stackoverflow.com/questions/13004417/curl-function-not-working">cURL function not working</a>, <a href="https://stackoverflow.com/questions/12056286/curl-setopt-doesnt-work-with-url-as-a-variable">curl_setopt doesnt work with url as a variable</a>) but there was never posted a real solution.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload