Problem with reg globals

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jon31
Forum Newbie
Posts: 3
Joined: Sat Mar 01, 2003 1:49 pm

Problem with reg globals

Post 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
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

just send it as $Story_1, you dont need to define everything as a $_POST variable.
jon31
Forum Newbie
Posts: 3
Joined: Sat Mar 01, 2003 1:49 pm

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Post 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";
}
?>
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

or

Code: Select all

extract($_POST);
extract($_GET);
Post Reply