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

Can Constants Be Used Inside Header()?

P: n/a
i have something similar to this:

<?php
header("Location: http://mysite.com/destination.php");
?>

i would like to replace "mysite.com/destination.php" with a constant.

for example, with a constant DESTINATION defined as
"mysite.com/destination.php".

can this be done?

if so, how?

tia...

Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
skeeterbug wrote:
i have something similar to this:

<?php
header("Location: http://mysite.com/destination.php");
?>

i would like to replace "mysite.com/destination.php" with a constant.

for example, with a constant DESTINATION defined as
"mysite.com/destination.php".

can this be done?

if so, how?


You mean like this?

define('DESTINATION', 'http://mysite.com/destination.php');
....
header('Location: ' . DESTINATION);

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #2

P: n/a
>>You mean like this?

define('DESTINATION', 'http://mysite.com/destination.php');
....
header('Location: ' . DESTINATION);<<

this doesn't work for me.

this is copy and paste... (except for mysite.com).

define("ENTER_CUSTOMER_URL", "http://mysite.com/index.php");
header('Location: ' . ENTER_CUSTOMER_URL);

Jul 17 '05 #3

P: n/a
skeeterbug wrote:
You mean like this?


define('DESTINATION', 'http://mysite.com/destination.php');
...
header('Location: ' . DESTINATION);<<

this doesn't work for me.

this is copy and paste... (except for mysite.com).

define("ENTER_CUSTOMER_URL", "http://mysite.com/index.php");
header('Location: ' . ENTER_CUSTOMER_URL);


So what actually happens when you try it?

To debug, try doing this instead:

define("ENTER_CUSTOMER_URL", "http://mysite.com/index.php");
print('Location: ' . ENTER_CUSTOMER_URL);

This way you get to see the output.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #4

P: n/a
.oO(skeeterbug)
You mean like this?

define('DESTINATION', 'http://mysite.com/destination.php');
...
header('Location: ' . DESTINATION);<<

this doesn't work for me.


How does it "not work"? Any error messages?
this is copy and paste... (except for mysite.com).

define("ENTER_CUSTOMER_URL", "http://mysite.com/index.php");
header('Location: ' . ENTER_CUSTOMER_URL);


Looks OK and works here (but please use www.example.com/org for example
URLs, these domains are reserved for that purpose).

Micha
Jul 17 '05 #5

P: n/a
Do you have exit(); after the header call? If not and you are running
any code after the call, this could cause unwanted results.

Jul 17 '05 #6

P: n/a
*** skeeterbug escribió/wrote (14 Jan 2005 15:24:39 -0800):
define("ENTER_CUSTOMER_URL", "http://mysite.com/index.php");
header('Location: ' . ENTER_CUSTOMER_URL);


Constants aren't any sort of mystery. Try:

echo 'Location: ' . ENTER_CUSTOMER_URL;

and you'll see the exact argument you are passing to header(). BTW, perhaps
you are missing an exit() somewhere after the redirection.
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la papelera
-+ I'm not a free help desk, please don't e-mail me your questions
--
Jul 17 '05 #7

P: n/a

Chris Hope wrote:
skeeterbug wrote:
You mean like this?


define('DESTINATION', 'http://mysite.com/destination.php');
...
header('Location: ' . DESTINATION);<<

this doesn't work for me.

this is copy and paste... (except for mysite.com).

define("ENTER_CUSTOMER_URL", "http://mysite.com/index.php");
header('Location: ' . ENTER_CUSTOMER_URL);


So what actually happens when you try it?

To debug, try doing this instead:

define("ENTER_CUSTOMER_URL", "http://mysite.com/index.php");
print('Location: ' . ENTER_CUSTOMER_URL);

This way you get to see the output.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

chris, thanks for the tip. the value printed is the ocrrect url.

i think the problem is how header handles variables within the quotes
used to pass the string to the header function.

there must be some kind of methodology for handling this - i'll search
the net some and get back.

Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.