/    Sign up×
Community /Pin to ProfileBookmark

php header infinite loop

i have an infinite loop issue using php’s header function with the following code:

[code=php]if($_SERVER[“HTTPS”] != “on”)
header(“Location: https://www.$_SERVER[SERVER_NAME]$_SERVER[REQUEST_URI]”);
[/code]

on the bottom left hand side of my browser, i get “connected to site.com”, “waiting for site.com”, “connected to site.com” and this repeat until after 10 seconds of attempts, then it stops. any suggestions?

on the php header page, an individual wrote to turn RewriteLocation to 0, but i have no idea what RewriteLocation is.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@SyCoMay 23.2008 — This might help from the user comments on

http://us2.php.net/reserved.variables

danvasile at pentest dot ro

If you have problems with $_SERVER['HTTPS'], especially if it returns no values at all you should check the results of phpinfo(). It might not be listed at all.

Here is a solution to check and change, if necessary, to ssl/https that will work in all cases:

[code=php]<?php
if ($_SERVER['SERVER_PORT']!=443) {
$sslport=443; //whatever your ssl port is
$url = "https://". $_SERVER['SERVER_NAME'] . ":" . $sslport . $_SERVER['REQUEST_URI'];
header("Location: $url");
}
?>[/code]


Of course, this should be done before any html tag or php echo/print.[/QUOTE]
Copy linkTweet thisAlerts:
@ixxalnxxiauthorMay 23.2008 — thank you, that solution works.
Copy linkTweet thisAlerts:
@ixxalnxxiauthorMay 23.2008 — are you familiar whether switching ports will affect a session? that is, if the site is not secured however the check out area is secured, will the switch from ports X to 443 kill or alter the session?
Copy linkTweet thisAlerts:
@SyCoMay 23.2008 — Sessions are saved per domain but when the protocol changes I don't know if you'd loose the session or not. You could test easily enough to find out. Let us know what you see.

I'm know for sure you don't want to append the session id to the url to get around the issue if there is one, or session hijacking will become simple for anyone sniffing your network.
×

Success!

Help @ixxalnxxi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...