- I’m a coder. Welcome to my blog. Here are some of the records on my job.
- Home
- Categories
- PHP — Maintaining session when redirecting HTTP to HTTPS?
- Related Articles
- How to manage the same ASP session when redirecting to SSL?
- php access session data between HTTPS and HTTP
- SSL certificate problem when redirecting ‘https://example.com’ to ‘https://www.example.com’
- PHP 404 error when redirecting from home page
- laravel can not recover session when redirected
- How does the webservice handle the session when the client is a Windows / Console application?
- PHP — Redirect HTTPS to HTTP — infinite loop
- Why do not my PHP session values ​​in http://www.domain.com work in domain.com?
- Nginx redirect loop when redirecting to https
- When an HTTP POST is redirected to GET, what happens to the body of the POST?
- Need help maintaining session in PHP Curl
- Does codeigniter share mysql sessions between the http request
- Temporarily redirect HTTP traffic to another server
- When redirecting to another controller session, does not work in the ID-code
- PHP — Maintaining session when redirecting from HTTP to HTTPS?
- Answer
- Solution:
I’m a coder. Welcome to my blog. Here are some of the records on my job.
Home
Categories
PHP — Maintaining session when redirecting HTTP to HTTPS?
I’m working on a simple shopping cart. When the user clicks checkout the URL changes from HTTP to HTTPS. Unfortunately the session does not appear to carry over and I get errors about $_SESSION[‘cart’] (where I hold the info) not existing.
I tried using mod_rewrite to redirect all HTTP to HTTPS so that the session would all be on HTTPS:
RewriteCond % !on RewriteRule (.*) https://%%
This worked. However, one page has Google Maps embedded on it, and it’s a HTTP URL so IE gives warnings about some elements being insecure etc.
So, I either need to know how to exclude a page with mod-rewrite (it sent me on an infinite redirect loop when I tried) or else to maintain the session between http and https. Thanks.
There’s no reason to make your entire website use https, you could do something like this to only redirect necessary pages to https:
# force https for checkout pages RewriteCond % !on RewriteCond % (checkout|register|login).php$ RewriteRule (.*) https://www.example.com/$1 [R,QSA,L] # non-secure pages RewriteCond % on RewriteCond % !(checkout|register|login).php$ RewriteRule (.*) http://www.example.com/$1 [R,QSA,L]
There’s no reason you can’t access a cookie set from http on a secure page, I do this all the time (unless you’re using secure cookies, if that’s the case the solution is to not use secure cookies or make sure your entire store is https).
Also, if you’re redirecting from, say, http://example.com to http://www.example.com you will lose your cookies.
But to answer your question, if you want to make your entire site use https except the map page, you could do something like this:
RewriteCond % !on RewriteCond % !map.php RewriteRule (.*) https://%% RewriteCond % on RewriteCond % map.php RewriteRule (.*) http://%%
Related Articles
How to manage the same ASP session when redirecting to SSL?
I have a shopping cart website running classic ASP that needs help during the checkout process. When a user is ready to checkout, they are redirected to an SSL version of the site. Response.Redirect «https://example.com/beginCheckoutProcess.asp»
php access session data between HTTPS and HTTP
Thanks for your replies. I have updated my PHP session code. I have a (HTTPS)-login.php which remains HTTPS ie once user logged in goes to account dashboard. Now the problem is say the user whilst logged on to the dashboard clicks on the (HTTP)-about
SSL certificate problem when redirecting ‘https://example.com’ to ‘https://www.example.com’
I’ve mapped ‘example.com’ and ‘www.example.com’ to the same IP address with my hosting service provider. But because my SSL certificate only works for ‘www.example.com’, so what I want is when the user visit ‘example.com’, he will be redirected to ‘w
PHP 404 error when redirecting from home page
I am trying to add a link to a different page of my website, but when I click the link, it gives me a «404 Page Not Found» error. Goal: All I want to do it be able to link my home page, index.php, to other pages of my website, like contact.php,
laravel can not recover session when redirected
in laravel 5.4 class AdminController extends Controller < public function checkLogin(Request $request) < Session::put('admin','yes'); return redirect('mobiles'); >> class MobilesController extends Controller < public function __construct() < if( ( S
How does the webservice handle the session when the client is a Windows / Console application?
How does webservice maintain session when client is windows/Console app?Using cookies. When you send HTTP requests, make sure to include a CookieContainer. (assuming you’re using HttpWebRequest)
PHP — Redirect HTTPS to HTTP — infinite loop
I’m trying to prevent certain pages on my site from being accessed through HTTPS, and (for whatever reason) I want to do it through PHP and not through a .htaccess. Here’s the code I’m using: if ( isset($_SERVER[‘HTTPS’]) && $_SERVER[‘HTTPS’] == ‘
Why do not my PHP session values ​​in http://www.domain.com work in domain.com?
Possible Duplicate: PHP: Cookie domain / subdomain control I have tow page a.php and b.php. I am running my a.php page with the url as http://www.domain.com/a.php. Here, page contains some session values. Ex: $_SESSION[‘name’]=’my name’; In b.php i a
Nginx redirect loop when redirecting to https
If you have the free cloudflare plan, or cloudflare enabled, it will cause an infinite redirect loop. I am trying to redirect http to https with nginx. I have tried literally(almost) everything. I have tried regex, 301 redirects and returns. I am not
When an HTTP POST is redirected to GET, what happens to the body of the POST?
As per my previous question, I need to redirect an HTTP POST request to a different server. I believe this can be done using HTTP response headers from php, but I understand the POST request will become a GET request. My question is what happens to t
Need help maintaining session in PHP Curl
I want to grab images from http://www.ps3-themes.com/, but whenever i directly enter image URL it doesn’t work. It redirects it to main URL of site. I’m using following code. $cookie_file = ‘c:/tmp-cookie.txt’; $crl = curl_init(); curl_setopt($crl, C
Does codeigniter share mysql sessions between the http request
Is there any way that 2 different http requests to use same mysql connection/session when using codeigniter’s database class (e.g. $this->db)? I heard that some frameworks does that, however, my project’s well being depends on the hope that codeignit
Temporarily redirect HTTP traffic to another server
Assume you have one box (dedicated server) that’s on 24 7 and several other boxes that are user machines that have unused bandwidth. Assume you want to host several web pages. How can the dedicated server redirect http traffic to the user machines. I
When redirecting to another controller session, does not work in the ID-code
i am stuck here when i sign up and want to redirect controller to another controller for showing dashboard then that time created session does not working on redirected controller. here is my sample code . My Sign up controller : class Signup extends
PHP — Maintaining session when redirecting from HTTP to HTTPS?
I’m working on a simple shopping cart. When the user clicks checkout the URL changes from HTTP to HTTPS. Unfortunately the session does not appear to carry over and I get errors about $_SESSION[‘cart’] (where I hold the info) not existing.
I tried using mod_rewrite to redirect all HTTP to HTTPS so that the session would all be on HTTPS:
RewriteCond % !on RewriteRule (.*) https://%%
This worked. However, one page has Google Maps embedded on it, and it’s a HTTP URL so IE gives warnings about some elements being insecure etc.
So, I either need to know how to exclude a page with mod-rewrite (it sent me on an infinite redirect loop when I tried) or else to maintain the session between http and https. Thanks.
Answer
Solution:
There’s no reason to make your entire website use https, you could do something like this to only redirect necessary pages to https:
# force https for checkout pages RewriteCond % !on RewriteCond % (checkout|register|login).php$ RewriteRule (.*) https://www.example.com/$1 [R,QSA,L] # non-secure pages RewriteCond % on RewriteCond % !(checkout|register|login).php$ RewriteRule (.*) http://www.example.com/$1 [R,QSA,L]
There’s no reason you can’t access a cookie set from http on a secure page, I do this all the time (unless you’re using secure cookies, if that’s the case the solution is to not use secure cookies or make sure your entire store is https).
Also, if you’re redirecting from, say, http://example.com to http://www.example.com you will lose your cookies.
But to answer your question, if you want to make your entire site use https except the map page, you could do something like this:
RewriteCond % !on RewriteCond % !map.php RewriteRule (.*) https://%% RewriteCond % on RewriteCond % map.php RewriteRule (.*) http://%%