Udhayan Nair
Udhayan Nair

Reputation: 470

Redirecting to external website with post data results in ErrorException (Laravel)

I'm trying to redirect my site to an external website with parameters. However when I do this, I get an Error Exception saying "Header may not contain more than a single header, new line detected". This would be my redirection code;

return Redirect::to($redirectUrl)->with(['ord_date' => $dueDate, 'ord_totalamt' => $cart_total, 'ord_gstamt' => 0.00, 'ord_shipname' => $user['name'],'ord_mercref' => $ord_mercref, 'ord_mercID' => $merchantid, 'ord_returnURL' => 'http://local.site.com/order/status', 'merchant_hashvalue' => $key]);

Note that I've tried using Redirect::away as well, and it results in the same error. What am I doing wrong here?

Edit #1;

My $redirecturl is as such; $redirecturl = 'https://myurl.com" so it is in one line.

Upvotes: 0

Views: 82

Answers (1)

N69S
N69S

Reputation: 17216

You should build the data into the $redirectUrl yourself instead of using with.

$query = http_build_query([
    'ord_date' => $dueDate,
    'ord_totalamt' => $cart_total,
    'ord_gstamt' => 0.00,
    'ord_shipname' => $user['name'],
    'ord_mercref' => $ord_mercref,
    'ord_mercID' => $merchantid,
    'ord_returnURL' => 'http://local.site.com/order/status',
    'merchant_hashvalue' => $key
])

$formattedRedirectUrl = preg_replace('/[ \t]+/', ' ', preg_replace('/[\r\n]+/', "\n", $redirectUrl);

return Redirect::to($formattedRedirectUrl.'?'.$query);

Upvotes: 2

Related Questions