alcarter Posted October 10, 2007 Share Posted October 10, 2007 I am a novice at PHP but have been programming in other languages for quite a while. I am having trouble recalling global variables. In other languages (VB for instance) if you want a variable to be visible throughout an application you declare it as Public. I have tried to use the global on variables but they still are not visible when I try to recall the values. The same with $_POST varibles. I do a POST and then load another form and the POST variable is available. If the next form has a POST action all the variables go away. Hope this makes sense to someone Quote Link to comment https://forums.phpfreaks.com/topic/72603-globals-and-_post/ Share on other sites More sharing options...
trq Posted October 10, 2007 Share Posted October 10, 2007 You cannot declare variables globally in php. However, ou can use the global keyword to bring a variable into a function. eg; <?php $s = 'hello'; function foo() { global $s; echo $s; } foo(); ?> As for the post thing, we might need a clearer explination. The $_POST, $_GET, $_SESSION, $_COOKIE and $_FILES arrays are all global in nature and should be available anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/72603-globals-and-_post/#findComment-366086 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.