Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Redirect problem with subdomain

I'm using PHP to redirect a page back to the previous page with the following:

header("Location: {$_SERVER['HTTP_REFERER']}");

This set of pages will only be used by internal users, so I'm not terribly concerned about the fact that the referer will not always be available.

The problem I'm running in to is that if the referer looks like http://subdomain.domain.com/test.php?id=13, the redirect ends up going to http://subdomain.domain.com/.domain.com/test.php?id=13. Notice the additional .domain.com/ in the url.

I've tested by hardcoding the value, and it causes the problem as well. phpMyAdmin seems to suffer the same issue, but only on this particular server.

If this is not an SO question, please move accordingly.

EDIT: per @yaggo

test.php contains only header("Location: http://subdomain.domain.com/test2.php");

curl --head --referer 'http://subdomain.domain.com/' 'http://subdomain.domain.com/test.php'

HTTP/1.1 302 Found
Server: nginx/0.7.64
Date: Fri, 02 Apr 2010 17:21:45 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.2.12-pl0-gentoo
Location: .domain.com/test2.php
like image 871
Glen Solsberry Avatar asked May 09 '26 00:05

Glen Solsberry


1 Answers

I've recreated both your programs on my server once with

header("Location: http://subdomain.domain.com/some/place");

and once with

header("Location: {$_SERVER['HTTP_REFERER']}");

and both give the corret result

curl --head --referer 'http://subdomain.domain.com/some/place' 'http://subdomain.domain.com/test.php'

HTTP/1.1 302 Found
Date: Fri, 02 Apr 2010 17:48:54 GMT
Server: Apache/2.0.52 (Red Hat)
X-Powered-By: PHP/5.1.2
Location: http://subdomain.domain.com/some/place
Connection: close
Content-Type: text/html

I'm using a different version of PHP and a different webserver, so there's two things to investigate.

like image 117
bjelli Avatar answered May 10 '26 12:05

bjelli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!