1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: PHP GLOBALS array disappears

Discussion in 'Web Design & Development' started by andynic, May 5, 2015.

Thread Status:
Not open for further replies.
  1. andynic

    andynic Thread Starter

    Joined:
    May 25, 2007
    Messages:
    386
    Hi,

    I have the following input button in an html form:
    <input type="button" name="preview" id="preview" value="Voorbeeld"
    onclick="alert( &quot;{$GLOBALS['PROGRAM_NAME']}&quot; );
    document.titelMuteren.action='../../../../public_html/uitgaven.php?mode=displayUitgavenPreview';
    submit();" />

    The alert is there to prove to me that at that moment the global is set and contains the expected value.

    The <form> tag is this: <form action="" method="post" name="titelMuteren" id="titelMuteren" enctype="">

    As the very first lines of uitgaven.php, I have put the following lines;
    echo "POST[titel] = " . $_POST['titel'] . "<br />\n";
    echo "GLOBALS['PROGRAM_NAME'] = " . $GLOBALS['PROGRAM_NAME'] . " <br />\n";
    echo "<pre>" . print_r($GLOBALS['PROGRAM_NAME'] , true) . "</pre>\n";
    exit();

    When the input button above is clicked, this appears at the top of the page produced by uitgaven.php:
    POST[titel] = Test D
    GLOBALS['PROGRAM_NAME'] =

    $_POST is as it should be and the "titel" element contains the expected value.

    The "alert" of the input button shown above correctly displays the value "arnManageTitels.php" which is what I expected to see at the top of the page produced by uitgaven.php.

    Have I misunderstood something critical? I thought that he GLOBALS array remains unchanged in situations like the one described above and would have expected the value of GLOBALS['PROGRAM_NAME'] to have been "arnManageTitels.php" rather than blank or null.

    Any ideas as to what is going on would be appreciated.

    Thanks for your help.
    Andynic
    Have I misunderstood something critical?
     
  2. andynic

    andynic Thread Starter

    Joined:
    May 25, 2007
    Messages:
    386
    I answered my own question by re-reading the PHP manual entry on GLOBALS.
    Would have been sensible to have done that first!

    "An associative array containing references to all variables which are currently defined in the global scope OF THE SCRIPT. The variable names are the keys of the array."
     
  3. JiminSA

    JiminSA

    Joined:
    Dec 15, 2011
    Messages:
    3,388
    First Name:
    Jim
    You're just like me Andy - we too often ask for help when the answer is just one step ahead;)
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1147744

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice