Page 1 of 1

Problem with reg globals

Posted: Sat Mar 01, 2003 3:45 pm
by jon31
[Admin Edit: This was moved from the reg globals sticky thread so the author's already read that.]

i've been reading through all these pages, and most of it is greek to me, so i haven't been able to figure out how to get variables that aren't in a form field. the thing I'm doing is generating a story from a number of variables and text. ex.

$Story = "the $animal_1 jumped over the $object_1";

now, I have a form on this page, that allows the user to e-mail the story to a friend, so how do I send the contents of $Story to the e-mail.php file, if $Story isn't a form object?

Thanks!
Jon

Posted: Sat Mar 01, 2003 6:48 pm
by evilcoder
just send it as $Story_1, you dont need to define everything as a $_POST variable.

Posted: Sat Mar 01, 2003 7:48 pm
by jon31
I've tried that, but with global_variables off, it doesn't work, I'm looking for a fix to the lack of global variables in the latest PHP.

Posted: Sun Mar 02, 2003 5:17 am
by twigletmac
Have you tried setting $Story into a hidden form field so that it can be passed using the form?

Code: Select all

echo '<input type="hidden" name="Story" value="'.$Story.'" />';
Mac

Posted: Sun Mar 02, 2003 8:49 am
by lc
The way twiglet does it is right.

But if you want to really want to get around register globals then just paste this at the top of your page.

Code: Select all

<?php
foreach ($_POST as $key=>$val){
$$key = "$val";
}
foreach ($_GET as $key=>$val){
$$key = "$val";
}
?>

Posted: Sun Mar 02, 2003 5:26 pm
by hob_goblin
or

Code: Select all

extract($_POST);
extract($_GET);