Jump to content

Have A Question About Using Constants In Url's...


eldan88

Recommended Posts

Hey,

 

I have defined a post value into a constants and I am trying to call the defined constant into a URL but its not working. It worked for a variable, but not for a constant.

 

I have noticed that usually constants are defined in all caps. I defined it in lower case... Can that be the issue? Below is an example of how I wrote the code.

 

Thank you!

 

 

if(isset($_POST['submit'])) {
define("store_name", "{$_POST['store_name']}");
goto_page("store_configuration_setting.php?send_store=".store_name."");

That's not really what constants are for. You are relying on the fact that a variable will exist prior to setting the constant. A variable which comes from the user, and is only set under certain circumstances. Why not, then, just use a variable in place of the constant?

That's not really what constants are for. You are relying on the fact that a variable will exist prior to setting the constant. A variable which comes from the user, and is only set under certain circumstances. Why not, then, just use a variable in place of the constant?

 

I like to get int he habit of using constants, since its always going to stay constant and not change. Is it possible to store POST subper globals into constants??

Can you please explain me what do you mean by setting it?

 

It means use a hardcoded value i.e

define('SITE_EMAIL_ADDRESS', '[email protected]');

 

As the site email address will never change (it is constant) it is hardcoded into a CONSTANT.

 

Data which comes from the superglobal arrays $_POST, $_GET, etc is NOT constant. It can be ammended by a user.

 

The answer is to hardcode a value. There is no need to post it through a form or send it through the url as it will always be available if you are including you constants definintion file throughout your site.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.