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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.