PHP Classes

Change URL location on CURL requests?

Recommend this page to a friend!

      cURL  >  All threads  >  Change URL location on CURL requests?  >  (Un) Subscribe thread alerts  
Subject:Change URL location on CURL requests?
Summary:curl posting changing url location
Author:alessandra bilardi
Date:2010-03-15 12:54:13

  1. Change URL location on CURL requests?   Reply   Report abuse  
Picture of alessandra bilardi alessandra bilardi - 2010-03-15 12:54:14
Hi all,
I read more forum and tutorial about curl post and changing URL
location.. but I think that something escapes me..
I have got a form (https://domain1/page.html) that I would like:
* mask it with my form (https://domain2/page.html)
* post all fields into original form (https://domain1/page.html)
* return thank you page about original form
(https://domain1/page.html) when I submitted with my form

domain1/page.html has got a form tag:
<form method="post" id='signup' onsubmit="return validate_form();">
function javascript returns true.
if I filled in all fields and I submitted it, browser returns thank
you page into same url page: https://domain1/page.html

I create my form into https://domain2/page.html
that recall https://domain2/my.php that post fields by this code:

$url = "https://domain1/page.html";
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($postdata));
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);

if I filled in all fields about my form (https://domain2/page.html)
and I submitted it, browser returns original form page
(https://domain1/page.html) with all fields filled and not thank you
I tested more curl lib options adding each option at a time:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);

I checked safe and basedir options, curl lib errors and url info:

.. previous code..

if(!ini_get('safe_mode') && !ini_get("open_basedir")) {
echo "n safe, n basedir: CURLOPT_FOLLOWLOCATION, true";
} elseif(!ini_get("open_basedir")) {
echo "y safe, n basedir";
} elseif(!ini_get('safe_mode')) {
echo "n safe, y basedir";
} else {
echo "y safe, y basedir";

$error_no = curl_errno($ch);
$error_wd = curl_error($ch);
$url_info = curl_getinfo($ch);

$result = curl_exec($ch);
$strg = "";

foreach ($url_info as $k => $v) {
$strg .= "$k = $v; ";

if ($error_no == 0) {
$error = '<br/>File uploaded succesfully
('.$error_wd.'['.$error_no.']): '.$strg.'.';
} else {
$error = '<br/>File upload error ('.$error_wd.'['.$error_no.']): '.$strg.'.';

echo $error;

And I obtainted that:
* php runs with safe_mode and open_basedir ON
* posting by curl lib has got error:
File uploaded succesfully ([0]): url = https://domain1/page.html;
content_type = text/html; http_code = 200; header_size = 393;
request_size = 175; filetime = -1; ssl_verify_result = 0;
redirect_count = 0; total_time = 1.60061; namelookup_time = 0.002403;
connect_time = 0.143216; pretransfer_time = 0.438166; size_upload =
4552; size_download = 51836; speed_download = 32385; speed_upload =
2843; download_content_length = 0; upload_content_length = 4552;
starttransfer_time = 0.589802; redirect_time = 0; .1

I don't understand where/what I must to do because browser returns me
thank you page: https://domain1/page.html
can you help me about?