473,473 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Enforcing https with javascript

mikek12004
200 New Member
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 1365
mikek12004
200 New Member
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;
  3.  
  4.     if (url.indexOf("https")==-1)
  5.     {
  6.             //alert('den einai https');
  7.  
  8.     }
  9.     else
  10.     {
  11.         //alert('einai https');
  12.         url=url.replace(/https/i,"http")
  13.         window.location = url; 
  14.  
  15.     }
  16.  
  17. goElseWhere(); 
  18.  
Note that the script above enforce http if the user types https
Oct 15 '08 #2
acoder
16,027 Recognized Expert Moderator MVP
Why not use server-side code for this? If someone has JavaScript disabled, it will remain on HTTP only.
Oct 15 '08 #3
pronerd
392 Recognized Expert Contributor
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

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

Similar topics

1
by: Groove | last post by:
Hopefully, this isn't too dumb of a question. I have a asp.net (2) app running on a dedicated Windows 2003 server. My host provider who manages the machine purchased and "installed" the SSL...
4
by: Jens Jensen | last post by:
Hello gurus, We have a site that need security upgrade to run over https. We want people to be redirected to https:oursite when the type what the know, http:oursite. Is this possible? How?...
7
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I am trying to set this up using asp code and IIS configuration. But it seems not working. Here it is the way I am doing. In IIS I set up a virtual directory with secure communication, I...
3
by: drewdall | last post by:
Hello All, I've read a lot of stuff which says it's impossible to hide Javascript, so if I get my PHP script to return some Javascript inside some XML using AJAX, how can it be viewed in the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.