So what I am doing is I set a variable $GLOBALS['me] in File1.php, and in File2.php I try to get and set a new variable with that data, but it doesn't work, when I pass it it then becomes null,... but if you check if it is set, it says it's set. I am calling File2.php with an ajax XMLHttpRequest which I feel might be the cause of this.
---File1.php---
$raceid = 2;
$wpm = 1;
$char = 3;
$me = 4;
...
$GLOBALS['me'] = $me;
$content = "char: " . $char . "
" . "wpm: " . $wpm . "
" . "me: " . $GLOBALS['me'] . "
" . "raceId: " . $raceid . "
";
$fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/myText.txt","wb");
fwrite($fp,$content);
fclose($fp);
//End of php File1.php
As you can see, it print the results to a file, so I can see what $GLOBALS['me'] is. So here is myText.txt after this get's run.
---myText.txt---
char: 3
wpm: 1
me: 4
raceId: 2
So this is great $GLOBALS['me']
equals 4 (Only in this file it equals 4) So here's PHP File2.php(it get's run when javascript function is executed)
---File2.php---
//wpm char and race id are defined above in this file.
if (isset($_POST['char']) && isset($_POST['wpm'])){
$char = $_POST['char'];
$wpm = $_POST['wpm'];
if(isset($GLOBALS['raceid'])){
$raceid = $GLOBALS['raceid'];
}
if (isset($GLOBALS['me'])){
$me = $GLOBALS['me'];
$content = "char: ".$char."
"."wpm: ".$wpm."
"."me: ".$GLOBALS['me']."
"."raceId: ".$raceid."
";
$fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/myText.txt","wb");
fwrite($fp,$content);
fclose($fp);
}
//Other stuff that only executes if $me is a value
}
As you can see in this file if $GLOBALS['me']
is set then I set this files $me equal to it. Then I again set the data in the file, but this time the file looks like this.
---myText.txt---
char: 3
wpm: 1
me:
raceId: 2
now me is blank(null) and I'm still using $GLOBALS???
now here is my javascript to call File2.php, via the post method, and executed via an html button click.
---Javascript---
function ClickMe(){
$.post("update.php", {
char: 72,
wpm: 123
}, function(data, status){
alert("done!");
});
}
Any help on why $GLOBALS['me'] is not keeping it's value, between these php files, would be helpful, and how you would be able to get the $me variable from php File1 to php File2. Their is nothing else called between these php files except the script that posts to File2, thanks for the help. Sorry for the long question wanted to be as descriptive as possible and show that in File1 what $GLOBALS['me'] is set and in File2 it is empty or null. Thanks!