Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen I get a page with a cURL request, how to navigate that page if paths are relative?
    primarykey
    data
    text
    <p>This is probably an easy question but I can't find the answer... I have a PHP script named 'send.php' which makes a cURL request to open an external web page. It outputs the external page to the browser. All completely by the books.</p> <pre><code>$ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_REFERER, $referer); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_exec($ch); </code></pre> <p>All it does is posts some POST data to a processing script on an external site and then displays on the browser whatever that external script would display normally; ie, a confirmation message, thank you, etc.</p> <p>Problem is: My 'send.php' is still the url that appears up in the navigation bar. So if I click around on that page, and the links are using relative paths, it tries to append my current path with those relative paths, which of course leads to a 404. Additionally, if there are more form fields on the page, and the action path is an empty string, it will try to post those submissions to send.php again on my server, which then generates errors.</p> <p>How can I make it so it will still send the post data and output the result of the processing script but still allow the user to navigate the output page as they normally would? Or if it's a multi-page form, they can continue filling out page 2 as if they were just on that site?</p> <p>Thanks in advance</p> <p>Update: Solved by adding these lines to the above code:</p> <pre><code>curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); $url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); $response = str_ireplace('&lt;head&gt;', "&lt;head&gt;&lt;base href=\"$url\" /&gt;", $response); echo $response; </code></pre>
    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.
    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