Post by Dev. » Mon Oct 09, 2023 8:50 am

Hi All
I'm working on opencart 3. I want to make some changes to the custom plugin.
After the customer selects the payment method I want to redirect to the external page.
In the index function, I try to use
return $this->response->redirect(URL)
But will get the below error.

Code: Select all

Warning: header() expects parameter 3 to be int, string 
In the Console will get the below error.

Code: Select all

index.php:1 Access to XMLHttpRequest at 'URL' (redirected from 'https://URL/index.php?route=checkout/confirm') from origin 'https://URL' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
How can solve it?

New member

Posts

Joined
Sun Jul 17, 2022 10:02 pm

Post by JNeuhoff » Mon Oct 09, 2023 4:48 pm

You haven't told us the whole story here.

The original redirect method from the system/library/response.php class has this signature:

Code: Select all

	public function redirect($url, $status = 302) {
		header('Location: ' . str_replace(array('&', "\n", "\r"), array('&', '', ''), $url), true, $status);
		exit();
	}
Therefore, when it calls the header function it will use the integer value 302 for the 3rd argument, not a string!

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Dev. » Mon Oct 09, 2023 7:40 pm

JNeuhoff wrote:
Mon Oct 09, 2023 4:48 pm
You haven't told us the whole story here.

The original redirect method from the system/library/response.php class has this signature:

Code: Select all

	public function redirect($url, $status = 302) {
		header('Location: ' . str_replace(array('&', "\n", "\r"), array('&', '', ''), $url), true, $status);
		exit();
	}
Therefore, when it calls the header function it will use the integer value 302 for the 3rd argument, not a string!

Code: Select all

return $this->response->redirect($redirect, '', true);
This is what I do. But still get the same error
I didn't mean what's a missing parameter

New member

Posts

Joined
Sun Jul 17, 2022 10:02 pm

Post by ADD Creative » Mon Oct 09, 2023 7:56 pm

Try.

Code: Select all

return $this->response->redirect($redirect);

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Dev. » Mon Oct 09, 2023 8:08 pm

ADD Creative wrote:
Mon Oct 09, 2023 7:56 pm
Try.

Code: Select all

return $this->response->redirect($redirect);
will get error
undefind


and in the console will get

Code: Select all

index.php:1 Access to XMLHttpRequest at 'URL' (redirected from 'https://URL/index.php?route=checkout/confirm') from origin 'https://URL' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

New member

Posts

Joined
Sun Jul 17, 2022 10:02 pm

Post by straightlight » Mon Oct 09, 2023 8:48 pm

Dev. wrote:
Mon Oct 09, 2023 8:08 pm
ADD Creative wrote:
Mon Oct 09, 2023 7:56 pm
Try.

Code: Select all

return $this->response->redirect($redirect);
will get error
undefind


and in the console will get

Code: Select all

index.php:1 Access to XMLHttpRequest at 'URL' (redirected from 'https://URL/index.php?route=checkout/confirm') from origin 'https://URL' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
OC version. You're using an XML HTTP request. What is the actual code for the XML request you are using prior with the redirection?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Dev. » Mon Oct 09, 2023 8:54 pm

straightlight wrote:
Mon Oct 09, 2023 8:48 pm
Dev. wrote:
Mon Oct 09, 2023 8:08 pm
ADD Creative wrote:
Mon Oct 09, 2023 7:56 pm
Try.

Code: Select all

return $this->response->redirect($redirect);
will get error
undefind


and in the console will get

Code: Select all

index.php:1 Access to XMLHttpRequest at 'URL' (redirected from 'https://URL/index.php?route=checkout/confirm') from origin 'https://URL' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
OC version. You're using an XML HTTP request. What is the actual code for the XML request you are using prior with the redirection?
OC 3
I'm writing this in the index function and using curl to post requests. Then will redirect the customer to the external page

New member

Posts

Joined
Sun Jul 17, 2022 10:02 pm

Post by ADD Creative » Mon Oct 09, 2023 10:01 pm

Dev. wrote:
Mon Oct 09, 2023 8:08 pm
ADD Creative wrote:
Mon Oct 09, 2023 7:56 pm
Try.

Code: Select all

return $this->response->redirect($redirect);
will get error
undefind


and in the console will get

Code: Select all

index.php:1 Access to XMLHttpRequest at 'URL' (redirected from 'https://URL/index.php?route=checkout/confirm') from origin 'https://URL' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Error undefined is probably a JavaScript error. Perhaps you don't want a redirect, but just return the URL and let the JavaScript redirect. You are going to have to give a lot more information for others to understand what you are doing.

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom
Who is online

Users browsing this forum: Amazon [Bot], Majestic-12 [Bot] and 81 guests