PDA

View Full Version : PHP HTTPS to HTTP redirect


mrobben375515
02-11-2011, 08:56 AM
Hi, a while back you guys gave me a redirect to cause checkout pages to go to https. Now on one of our sites we're having issues after users go to the product pages (where they are redirected to https) and then leave to go back to the rest of the site. The rest of the site has google ads which use js files from an unsecure site so a pop up comes up in IE asking if they only want to few content that was delivered securely. There's no way to change the ads, I've looked for a solution. Is there a redirect that will take the page from https and go back to http? Here's the redirect I was given to go to https.

<?php if((!(isset($_SERVER['HTTPS']))) || ($_SERVER['HTTPS'] == "") || ($_SERVER['HTTPS'] == "off"))header("Location: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); ?>

Jason Byrnes
02-11-2011, 11:08 AM
on the pages you do not wish to view using https, use this code:


<?php if((!(isset($_SERVER['HTTPS']))) || ($_SERVER['HTTPS'] == "") || ($_SERVER['HTTPS'] == "off"))header("Location: http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); ?>

mrobben375515
02-11-2011, 11:27 AM
I should have mentioned that I tried to change the "Location: https://" to "Location: http://" and didn't have any success. I just tried it again with what you gave me, but it still stays at https... Any other suggestions? I googled it but only found codes for http to https.

Jason Byrnes
02-11-2011, 12:02 PM
are you using an htaccess rule as well?

If you use an htacess rule, then that will override any php code.

mrobben375515
02-11-2011, 12:06 PM
no, i don't have any htaccess rules.

Jason Byrnes
02-11-2011, 12:25 PM
may be try using this instead:


if ($_SERVER['SERVER_PORT']==443) header("Location: http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);

mrobben375515
02-11-2011, 12:50 PM
Perfect, thanks Jason

Jason Byrnes
02-11-2011, 12:58 PM
you're welcome.

jmgo
02-22-2011, 12:02 PM
When redirecting from cart.php to index.php clicking the "Home" button a 404 error shows up.
I followed this post directions to redirect my https pages to http ones.
I added the following code to the cart page:
<?php if((!(isset($_SERVER['HTTPS']))) || ($_SERVER['HTTPS'] == "") || ($_SERVER['HTTPS'] == "off"))header("Location: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); ?>
And the following to the index page:
<?php if ($_SERVER['SERVER_PORT']==443) header("Location: http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); ?>
Other links from https to http works fine but this. I checked the source code and the link seems Ok.

https://www.jomsy.com/kids/cart.php

Jason Byrnes
02-22-2011, 12:21 PM
send a copy of the index.php file, it is directing to a file called fakey.php for some reason.

jmgo
02-22-2011, 02:45 PM
Thanks for the quick answer.

The index file is attached

jmgo
02-24-2011, 09:43 AM
Hi,
It s been a couple a days since I attached the index.php file. Do you have any insight of what is going on
Thanks

Jason Byrnes
02-24-2011, 11:22 AM
there is nothing in the code to redirect the index.php page to fakey.php, it seams like there is a server setting, maybe an htaccess rule that is causing this behavior.


if i try to access you page at:
https://www.jomsy.com/kids/index.php

or:
http://www.jomsy.com/kids/index.php

I am redirected to:
http://www.jomsy.com/kids/fakey.php

however, if I use:
https://www.jomsy.com/kids/

or:
http://www.jomsy.com/kids/

i get the page to show correctly.



your page code does not include any references to the fakey.php page, so it has got to be a server setting.

jmgo
02-25-2011, 10:14 AM
I got different results. When I try to access the Home page through the https address I've always been redirected to fakey.php

https://www.jomsy.com/kids/index.php
https://www.jomsy.com/kids/

However if I try the regular URL I get the right page.

http://www.jomsy.com/kids/index.php
http://www.jomsy.com/kids/

I've tried with different browsers having the same results. They do not care about the .../index.php but what makes the difference is the Https.

I've been in touch with my Host (Fatcow) and I got this answer to my ticket:"Checking the account we were not able to find the redirect in any .htaccess or .php files, it's likely that it takes place at the database level."

Any ideas on where to look for a solution?

Jason Byrnes
02-25-2011, 10:43 AM
if it where coming from the database, it would be in the wa_settings table for the power store database.

jmgo
02-26-2011, 04:08 PM
Line 65 of the file "kids/galleries/global.php" is

"$_SERVER['PHP_SELF'] = $pg_config['path'] . 'fakey.php';"

This appears to be the line causing the redirect but no idea about the reason and most important, how to solve it. Please help..

Jason Byrnes
02-28-2011, 07:57 AM
try changing that to:
"$_SERVER['PHP_SELF'] = $pg_config['path'] . 'index.php';"

jmgo
02-28-2011, 12:23 PM
Thanks, the link works nicely.
But the page fakey.php is still a mistery for me. Is this WA original code?

Jason Byrnes
02-28-2011, 01:30 PM
that line is in place for when the simpleXML function fails to load the gallery xml, it probably should not use a page name at all.

I have logged a bug in the bugbase.

jmgo
03-02-2011, 04:52 PM
Navigating from and to the HTTPS pages works fine. However I got these Warning message after an order is completed.

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /hermes/web08/b2652/moo.jomsy/kids/checkout_success.php:2) in /hermes/web08/b2652/moo.jomsy/kids/WA_SecurityAssist/Helper_PHP.php on line 5

Thanks for your advice

Jason Byrnes
03-03-2011, 06:39 AM
the headders already sent error means that there is output to the page before the session_start function.

the error is reporting the output at lines 1 or 2:
output started at /hermes/web08/b2652/moo.jomsy/kids/checkout_success.php:2


if you cannot spot the problem, send a copy of the checkout_success.php page in a zip archive.