eldan88 Posted September 25, 2012 Share Posted September 25, 2012 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.""); Quote Link to comment https://forums.phpfreaks.com/topic/268795-have-a-question-about-using-constants-in-urls/ Share on other sites More sharing options...
Pikachu2000 Posted September 25, 2012 Share Posted September 25, 2012 What do you get if you echo or var_dump() the constant store_name? Quote Link to comment https://forums.phpfreaks.com/topic/268795-have-a-question-about-using-constants-in-urls/#findComment-1380923 Share on other sites More sharing options...
scootstah Posted September 25, 2012 Share Posted September 25, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/268795-have-a-question-about-using-constants-in-urls/#findComment-1380924 Share on other sites More sharing options...
eldan88 Posted September 26, 2012 Author Share Posted September 26, 2012 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?? Quote Link to comment https://forums.phpfreaks.com/topic/268795-have-a-question-about-using-constants-in-urls/#findComment-1381157 Share on other sites More sharing options...
Jessica Posted September 26, 2012 Share Posted September 26, 2012 If it's a value that is POSTed, it's not going to stay constant and not change. Why bother POSTing it then? Just set it. Quote Link to comment https://forums.phpfreaks.com/topic/268795-have-a-question-about-using-constants-in-urls/#findComment-1381158 Share on other sites More sharing options...
eldan88 Posted September 28, 2012 Author Share Posted September 28, 2012 If it's a value that is POSTed, it's not going to stay constant and not change. Why bother POSTing it then? Just set it. Can you please explain me what do you mean by setting it? Quote Link to comment https://forums.phpfreaks.com/topic/268795-have-a-question-about-using-constants-in-urls/#findComment-1381555 Share on other sites More sharing options...
JonnoTheDev Posted September 28, 2012 Share Posted September 28, 2012 Can you please explain me what do you mean by setting it? It means use a hardcoded value i.e define('SITE_EMAIL_ADDRESS', 'joe@bloggs.com'); 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. Quote Link to comment https://forums.phpfreaks.com/topic/268795-have-a-question-about-using-constants-in-urls/#findComment-1381589 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.