469,323 Members | 1,427 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

Enforcing https with javascript

200 100+
For a spesific page (order.php) I want if the user didn't entered https to automatically reload it with https (note that this page loads also other pages with includes based on a _GET variable-e.g order.php?stat=1) and in all other pages to enforce http (all other pages loads with index.php in which I include all the others based on a _GET variable like above any suggestions?)
Oct 15 '08 #1
3 1267
200 100+
After some digging I found this which works, (though I do not know if it will with nice URLS)
Expand|Select|Wrap|Line Numbers
  1. function goElseWhere() 
  2. var url = document.URL;
  4.     if (url.indexOf("https")==-1)
  5.     {
  6.             //alert('den einai https');
  8.     }
  9.     else
  10.     {
  11.         //alert('einai https');
  12.         url=url.replace(/https/i,"http")
  13.         window.location = url; 
  15.     }
  17. goElseWhere(); 
Note that the script above enforce http if the user types https
Oct 15 '08 #2
16,027 Expert Mod 8TB
Why not use server-side code for this? If someone has JavaScript disabled, it will remain on HTTP only.
Oct 15 '08 #3
392 Expert 256MB
It would be both easier and more reliable to do this with the server configuration. You would not have to write and code, and it would still work if the user had JavaScript disabled.
Oct 20 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Groove | last post: by
4 posts views Thread by Jens Jensen | last post: by
7 posts views Thread by =?Utf-8?B?YzY3NjIyOA==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.