PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
RandomEngy
Forum Contributor
Posts: 173 Joined: Wed Jun 26, 2002 3:24 pm
Contact:
Post
by RandomEngy » Wed Jul 03, 2002 2:28 pm
I know It seems like a simple question, but I couldn't find the answer in my searches. What I want is to get the URL the person typed in their browser to get to the page.
The reason I need this, is that I'm using SLL on my server, and I want users who type in "
http://www.company.com/login " to be redirected to "
https://www.company.com/login " . I know how to tell if https was used or not, but I don't know how to get the
http://www.company.com portion. I was thinking:
Code: Select all
if(!$HTTPS)
header("Location: https://".$base_path_or_something.$_SERVERї'PHP_SELF']);
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Wed Jul 03, 2002 2:34 pm
$PHP_SELF returns part of it..
RandomEngy
Forum Contributor
Posts: 173 Joined: Wed Jun 26, 2002 3:24 pm
Contact:
Post
by RandomEngy » Wed Jul 03, 2002 2:45 pm
But I need all of it. :/
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Wed Jul 03, 2002 2:53 pm
and, if you have more than you need you could just use explode() and remove some of the entries you don't need
RandomEngy
Forum Contributor
Posts: 173 Joined: Wed Jun 26, 2002 3:24 pm
Contact:
Post
by RandomEngy » Wed Jul 03, 2002 3:08 pm
Hmmm, I couldn't find anything in those links that would tell me the part of the URL I needed. I just need to get that info, I'm fairly sure of what to do with it afterwards.
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Wed Jul 03, 2002 3:13 pm
try
$url = getenv('SERVER_NAME');
echo $url;
when i ran it on my own comp, it came up with "localhost"
protokol
Forum Contributor
Posts: 353 Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:
Post
by protokol » Wed Jul 03, 2002 3:18 pm
Code: Select all
if (!$HTTPS)
header("Location: https://{$_SERVERї'HTTP_HOST']}{$_SERVERї'REQUEST_URI']}");
Works like a charm
RandomEngy
Forum Contributor
Posts: 173 Joined: Wed Jun 26, 2002 3:24 pm
Contact:
Post
by RandomEngy » Wed Jul 03, 2002 3:55 pm
Alright, thanks protokol and hobgoblin, I got it working!