dongxi2163 2015-11-12 13:03
浏览 13
已采纳

如何在没有http的情况下将用户重定向到PHP域中的www域?

I have a website (let's call it www.mywebsite.com) that allows users to enter a URL that other users on my website can be redirected to. If a user types in a full URL like so https://www.google.com then all is well because my header() function will redirect to exactly that.

However when a user enters in www.google.com or even google.com then the header() function will attempt to redirect to this https://www.mywebsite.com/www.google.com.

Remember, I can't fully format the user's URL myself because the program doesn't know whether the website is https:// or http:// and if you get this wrong the user can end up at a non existent page.

What I need is a method of telling PHP to just go to the URL specified without relativity to my website almost like the a user had typed it in the URL bar themselves.

Any ideas?

  • 写回答

1条回答 默认 最新

  • donglanzhan7151 2015-11-12 13:25
    关注

    You should only redirect to the http:// if you don't know the protocol because it is REALLY the responsibility of the receiving website to have a redirect setup form HTTP to HTTPS.

    Therefore if the user doesn't specify a protocol, you simply add the non-secure http protocol and it should get redirected to the correct page.

    You should not be inserting www at all if the user hasn't put that in.

    Notwithstanding all this, you could always perform a check yourself in your own code to see which protocols exist at the other end, but you should probably simple enforce the user supply it in the first place

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?