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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.