473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Can Constants Be Used Inside Header()?

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
7 3303
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
>>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
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
.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
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
*** 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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: 2obvious | last post by:
I've been trying to create read-only global variables by creating constants (Const) in my global.asa, but I can't seem to reference them. Sticking them in an include works fine, but it seems more...
34
by: E. Robert Tisdale | last post by:
Please find attached the physical constants header file physical.h It defines conversion factors to mks units. It might be used like this: > cat main.cc #include<iostream>...
9
by: john smith | last post by:
Hi, If I have a large constants file and include that in a .cpp file will the executable become large? That is if I include a file with a bunch of constants does the executable include all of...
5
by: Veit Wiessner | last post by:
I wrote a program that handles the buildcount of projects (gets called every time I compile a project, it writes a header file which is #include-ed in the project). My question is this, is it...
8
by: Marty | last post by:
Hi, I'm new to C#, I used to code in VB.NET. Where is the best place to declare all my constants and global objects in my C# project to have them accessible globally? I have an event logger...
7
by: Don Wash | last post by:
Hi There! I'm trying to define constants so that I can refer those constants from any page of my ASP.NET website. I know I can use <appSettings> in web.config XML file but I don't want to parse...
3
by: Steve Folly | last post by:
Hi, I had a problem in my code recently which turned out to be the 'the "static initialization order fiasco"' problem (<http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12>) The FAQ...
2
by: Leslie Sanford | last post by:
I want to define a set of floating point constants using templates insteand of macros. I'd like to determine whether these constants are floats or doubles at compile time. In my header file, I have...
54
by: shuisheng | last post by:
Dear All, I am always confused in using constants in multiple files. For global constants, I got some clues from http://msdn.microsoft.com/en-us/library/0d45ty2d(VS.80).aspx So in header...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.