By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,013 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

redirecting

P: n/a
what is wrong with
<?php
if(!stristr($_SERVER['SERVER_NAME'], 'www')) {
Header("Location: http://www.theSpear.net" . $_SERVER['PHP_SELF']);
exit();
}
?>

I am trying to make it redirect to www.theSpear.net if www. is not there,
but it doesnt work.. any ideas?
Jul 16 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
In article <xwEZa.118337$YN5.84458@sccrnsc01>, spearman <ne*@news.com>
wrote:
I am trying to make it redirect to www.theSpear.net if www. is not there,
but it doesnt work.. any ideas?


Perhaps you can check with your DNS host and configure a www subdomain.
Jul 16 '05 #2

P: n/a
no.. i just ppl that go to theSpear.net to go to www.theSpear.net instead..
dont want anything to happen between them.. just change it..
"E-Star" <un*******@linuxmail.org> wrote in message
news:100820032208028085%un*******@linuxmail.org...
In article <xwEZa.118337$YN5.84458@sccrnsc01>, spearman <ne*@news.com>
wrote:
I am trying to make it redirect to www.theSpear.net if www. is not there, but it doesnt work.. any ideas?


Perhaps you can check with your DNS host and configure a www subdomain.

Jul 16 '05 #3

P: n/a
I don't see any problem with the code unless I'm missing something. Just
make SURE that there is absolutely NO whitespace or any output to the
browser before the headers are processed and sent. Meaning the following
will NOT work:

<html>
<?php include 'includeme.php'; ?>
<?php
if(!stristr($_SERVER['SERVER_NAME'], 'www')) {
Header("Location: http://www.theSpear.net" . $_SERVER['PHP_SELF']);
exit();
}
?>

Double check the manual for more information on headers
http://ca3.php.net/manual/en/function.header.php
--

Warren Butt
-- Custom web design, cheap like cheese
"spearman" <ne*@news.com> wrote in message
news:xwEZa.118337$YN5.84458@sccrnsc01...
what is wrong with
<?php
if(!stristr($_SERVER['SERVER_NAME'], 'www')) {
Header("Location: http://www.theSpear.net" . $_SERVER['PHP_SELF']);
exit();
}
?>

I am trying to make it redirect to www.theSpear.net if www. is not there,
but it doesnt work.. any ideas?

Jul 16 '05 #4

P: n/a
Because $_SERVER['SERVER_NAME'] will return the name of the server as
SET on the server. So will probably always be 'www.thespear.net' or
whatever.
You'd want: $_SERVER['HTTP_HOST'], although not all browsers send this.

<?php
if (!stristr($_SERVER['HTTP_HOST'], 'www') &&
!empty($_SERVER['HTTP_HOST']))
{
Header("Location: http://www.theSpear.net" . $_SERVER['PHP_SELF']);
exit();
}
?>

Would be a solution, with a check to avoid a race condition (browser
that doesn't send a Host: header).
spearman wrote:
what is wrong with
<?php
if(!stristr($_SERVER['SERVER_NAME'], 'www')) {
Header("Location: http://www.theSpear.net" . $_SERVER['PHP_SELF']);
exit();
}
?>

I am trying to make it redirect to www.theSpear.net if www. is not there,
but it doesnt work.. any ideas?


Jul 16 '05 #5

P: n/a
thanks alot! any easy way to also send all variables like (?id=1 stuff?)
"blah" <ba*@lah.com> wrote in message
news:bh**********@bunyip.cc.uq.edu.au...
Because $_SERVER['SERVER_NAME'] will return the name of the server as
SET on the server. So will probably always be 'www.thespear.net' or
whatever.
You'd want: $_SERVER['HTTP_HOST'], although not all browsers send this.

<?php
if (!stristr($_SERVER['HTTP_HOST'], 'www') &&
!empty($_SERVER['HTTP_HOST']))
{
Header("Location: http://www.theSpear.net" . $_SERVER['PHP_SELF']);
exit();
}
?>

Would be a solution, with a check to avoid a race condition (browser
that doesn't send a Host: header).
spearman wrote:
what is wrong with
<?php
if(!stristr($_SERVER['SERVER_NAME'], 'www')) {
Header("Location: http://www.theSpear.net" . $_SERVER['PHP_SELF']);
exit();
}
?>

I am trying to make it redirect to www.theSpear.net if www. is not there, but it doesnt work.. any ideas?

Jul 16 '05 #6

P: n/a
For "get queries"....

You can try:

header( "Location:
http://www.theSpear.net$_SERVER[PHP_SELF]?$_SERVER[QUERY_STRING]" );

On Mon, 11 Aug 2003 06:51:16 GMT, "spearman" <ne*@news.com> scrawled:
thanks alot! any easy way to also send all variables like (?id=1 stuff?)
"blah" <ba*@lah.com> wrote in message
news:bh**********@bunyip.cc.uq.edu.au...
Because $_SERVER['SERVER_NAME'] will return the name of the server as
SET on the server. So will probably always be 'www.thespear.net' or
whatever.
You'd want: $_SERVER['HTTP_HOST'], although not all browsers send this.

<?php
if (!stristr($_SERVER['HTTP_HOST'], 'www') &&
!empty($_SERVER['HTTP_HOST']))
{
Header("Location: http://www.theSpear.net" . $_SERVER['PHP_SELF']);
exit();
}
?>

Would be a solution, with a check to avoid a race condition (browser
that doesn't send a Host: header).
spearman wrote:
> what is wrong with
> <?php
> if(!stristr($_SERVER['SERVER_NAME'], 'www')) {
> Header("Location: http://www.theSpear.net" . $_SERVER['PHP_SELF']);
> exit();
> }
> ?>
>
> I am trying to make it redirect to www.theSpear.net if www. is notthere, > but it doesnt work.. any ideas?
>
>



Jul 16 '05 #7

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Whilst lounging around on Mon, 11 Aug 2003 06:53:55 GMT,
ne*******@black-panther.freeserve.co.uk (James) amazingly managed to
produce the following with their Etch-A-Sketch:
For "get queries"....

You can try:

header( "Location:
http://www.theSpear.net$_SERVER[PHP_SELF]?$_SERVER[QUERY_STRING]"
);

^^ ^^ ^^ ^^

Missing quotes!!!

_ALWAYS_ quote these array elements! unless they're vars:
$_SERVER['PHP_SELF']

or

$_GET[$foo]

Regards,

Ian

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0

iQA/AwUBPzdGgWfqtj251CDhEQJe+gCgyRrS/EqNs7x/B1p3TvKzrnanED4AnR1v
DF/teF3j7tB0ZD8/2cL/VbfE
=2FV1
-----END PGP SIGNATURE-----

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
Jul 16 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.