473,587 Members | 2,494 Online
Bytes | Software Development & Data Engineering Community
+ 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 1367
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
1063
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 certificate and took care of all of the details (no experience on my part) to enabled SSL on our app. We can now browse the site using HTTPS. The little lock in IE appears and it seems to be encrypted. How can I prevent any of the app/site being...
4
1149
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? mnay thanks JJ
7
13438
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 checked require secure channel, require 128-bit encryption. In custom error, instead of using default message HTTP 403.4 - Forbidden: SSL required Internet Information Services in iishelp 403.4htm, I am trying to do redirect automatically. so I...
3
1366
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 browser? Obviously, some essential Javascript has to be there at the outset, ie. that which handles the AJAX, so you can't hide that, but if you then use AJAX to supply ad hoc Javascript on demand, can it be seen anywhere? Your technical...
0
7924
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8349
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7978
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
5722
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5395
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
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 we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.