Jump to content

globals and $_POST


alcarter

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/72603-globals-and-_post/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/72603-globals-and-_post/#findComment-366086
Share on other sites

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.