John Davidson

php - I want to make a simple redirect to a url from my website without session refresh

0 comments
Message:


I have a variable with a url,


$order_paypage_url = "example.com"

I want to redirect from this to this url from website, I have tried this :


header('Location: '.$order_paypage_url);
exit;

But when I run this session refreshes and the redirect does not occur.


More relevant information :
I am working on a PHP based e-commerce site and this is in relevance to redirecting after clicking
on Place Order.
I have the target destination as url, I just want to know what is triggering this session refresh
which is keeping me from reaching this URL.
And how can i circumvent this problem.



My Answer:
The issue you are facing with the session refresh when using the header() function to redirect is likely due to output being sent to the browser before the header function is called. This can cause the headers to be sent too late, resulting in a session refresh.

To avoid this issue, you can try using output buffering to prevent any output from being sent before the header function is called. Here is an example of how you can do this:

php
ob_start(); // Start output buffering

$order_paypage_url = "example.com";

header('Location: '.$order_paypage_url);
exit;

ob_end_flush(); // Flush the output buffer
?>


By using output buffering, you can ensure that no output is sent to the browser before the header function is called, which should prevent the session refresh from occurring.

Rate this post

5 of 5 based on 3895 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us