How Get the absolete URL from a relative url placed into a input form?

lebron letchev
lebron letchev used Ask the Experts™
on
Dear all,

Could I get the absolute url from a relative url placed into an input form?

Example:

Input text = "www.elmundo.es"
absolute url = https://www.elmundo.es

Input text = "w3guy.com/relative-absolute-url-guide/"
absolute url = https://w3guy.com/relative-absolute-url-guide/

Input text = "www.filosofia.org/rev/bas/"
absolute url = http://www.filosofia.org/rev/bas/

There are dozens of solutions to get absolute url from a relative url on address bar (the url of the open page), but not from an input form.

I just make a question ultimately!

Could someone help me to find a solution for this case

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Consultant & Challenge Subduer
Top Expert 2009
Commented:
Just assume it's "http://", since that should work regardless. If you want to be fancy about it, you could use cURL to see if a request gets redirected to "https://".

I'm curious, did you intentionally mark this as both ASP and PHP? Are you really using both for the same site?
Commented:
There's no way to do this with 100% accuracy. You cannot assume "http://" nor "https://" because not all sites will support either or both. Some sites might be "http://" and some others might be "https://" and some might work with both.

From a purely technical perspective, "http://" is currently a required step in the HTTPS handshake, but some sites might try to automatically redirect you to "https://" and others might try to block non-handshake HTTP requests.

If it's critical to find out whether it's "http" or "https", then I'd suggest doing a variation on what David suggested. Instead of hitting "http" to see if it redirects to "https", just hit "https" first (and make sure you do NOT disable verify peer). If it succeeds, then you know the site is very likely accessible via HTTPS. If it doesn't work, then you can assume regular HTTP.

Whatever you do, make sure you put some limitations on it. Otherwise, if you immediately try to connect to a URL that is provided by the user, then you are susceptible to malicious users. Someone could automatically submit the form 1000 times to hit a URL that they are trying to bring down with a denial-of-service attack, so you want to make sure your server is not vulnerable to that.
leakim971Multitechnician
Top Expert 2014

Commented:
adding asp and php topics, you finally answered me in your previous question
you just need to read the header using server code and see if you get a http 301 redirect code (maybe you to handle 302) and check if the new location start by "https" with the same address
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Hello,

I have a problem in programming! Formerly the languages had little more than 100 commands and functions, in the old days of the turbo pascal, but, today they are thousands and I do not know how to DECORATE ALL !!!

I am working with with 2 files. The first one with a input form and the 2nd in asp classic with Server.CreateObject ("Microsoft.XMLHTTP") and the script of the .asp file does not accept another url that the absolute url. For example:

the absolute url http://www.elmundo.es gives an error: msxml3.dll error '80070005'

It accepsts only the absolute ands correct url https://www.elmundo.es

And does not redirect the 'wrong' url to correct and current url

Yes, the asp classic and PhP have more options to answer this question, but I need reading and try the available codes to see if I could "rewrite" them

PS: Unfortunately due this 'problem" I could not to do the academic course I love because it have the logic program discipline!!!
Thank you in advance

Author

Commented:
Dear David S.

In another case I have 1 file in .asp and another in .php. Yes. "they working fine".

This script may be useful: LINK TO CONCURRENT SITE REMOVED

I will search for more to see if I find a code more simple and easy to rewrite it.

thanks by now

Author

Commented:
Hello, If  I sign up yours solve my question (and other) with a reasonale answer?

Author

Commented:
Many thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial