Numerous redirects

I am working with a small API for lead capturing. I have this form:

On submit, it will redirect to a url similar to this:<id=5&fname=Ryan&lname=Coughlin&address=399%20Saint%20Paul%20Street&city=Kennebunk&country=UnitedStates&state=AZ&zip=05402&phone=2075905241&besttime=08:48:50¤t_date=2010-04-21&IP=

That pages response then displays a URL that I then need to redirect the user too. BUT I can send parameters in this fashion:$phone&email=$email&fname=$fname&lname=$lname&address=$address&city=$city&state=$state&zip=$zip&country=$country

Once the form is submitted, send to the first URL posted, then redirect user will the data to the URL above.

My code is below that I am working with.

Maybe use AJAX? To send the data to the first server and on success redirect?

$name_first = $_POST['first_name'];
$name_last  = $_POST['last_name'];
$Address    = $_POST['Address'];
$Apt        = $_POST['Apt'];
$City       = $_POST['City'];
$state      = $_POST['state'];
$email      = $_POST['email'];
$zip        = $_POST['zip'];
$phone_work_area   = $_POST['phoneworkArea'];
$phone_work_prefix = $_POST['phoneworkPrefix'];
$phone_work_suffix = $_POST['phoneworkSuffix'];
$current_time      = time();
$current_date      = date("Y-m-d",$current_time);
$current_time      = strftime("%H:%M:%S",$current_time);

$phone = $phone_work_area.$phone_work_prefix.$phone_work_suffix;

    //Define option variables 
    $action = "".$name_first."&lname=".$name_last."&address=".$Address."&city=".$City."&country=UnitedStates&state=".$state."&zip=".$zip."&phone=".$phone."&besttime=".$current_time."&current_date=".$current_date."&IP=".$_SERVER['REMOTE_ADDR']."&DateStamp=".$current_date."&email=".$email;
    //$cookie = "cookie".$admin[admin_id].".txt"; 
	//echo $action ;
	header('Location: '.$action.'');
   // $agent = "Mozilla/5.0"; 
    /*$referer = ""; */

    //Initialize a CURL session 
   // $ch = curl_init($action); 

    //Define form data array 
    $postfields = array(); 
    $postfields["name_first"] = urlencode($name_first); 
	$postfields["name_last"] = urlencode($name_last);
	$postfields["Address"] = urlencode($Address); 
    $postfields["Apt"] = urlencode($Apt); 
    $postfields["City"] = urlencode($City); 
	$postfields["State"] = urlencode($state); 
	$postfields["zip"] = urlencode($zip);  
    $postfields["email"] = urlencode($email); 
	$postfields["phone"] = urlencode($phone); 
    $postfields["current_time"] = urlencode($current_time); 
	$postfields["current_date"] = urlencode($current_date);  
   // $postfields["__VIEWSTATE"] = urlencode($result); 
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $action );
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 //curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
// curl_setopt($ch, CURLOPT_HEADER, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 $result = curl_exec($ch);
    //Set the CURL options 
/*    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); 
    //curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); 
    //curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
    //curl_setopt($ch, CURLOPT_REFERER, $referer); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
	curl_setopt($ch, CURLOPT_URL,$action); 
	//curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); 
    $result = curl_exec($ch); */
	echo  $result;

Open in new window

Who is Participating?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.