Re: Re: php forgetting variables very easily

From: Date: Wed, 05 Mar 2003 15:02:05 +0000
Subject: Re: Re: php forgetting variables very easily
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-138276@lists.php.net to get a copy of this message
> I am still having problems with variables not being > remembered by included files. I've tried using the > global command and it still doesn't work. I've cut > down my two pages to contain the main stuff so you can > see what's happening. Basically main.php includes the > file new.php and I want the variable '$name' to be > remembered in it. The other included files aren't > important to the problem I'm having. > > main.php > =========== > > <?php > global $name; > $name = 'home'; > ?> > <html><head> > <title>Tite</title> > <link rel="stylesheet" type="text/css" > href="stylesheet.css"/> > </head> > <body> > <?php > > > include("http://www.vocalwebsites.com/neilhowlett/new.php") Use include("new.php"), not the full URL. The way you're doing it now, your making a brand new request for the _result_ of a .php page. There is no relation to this page and new.php when you request it in this manner. If you just do include('new.php'), then it takes the _php_ code (the whole file) from new.php and inserts it into this file and runs it. So then your variables will still work. also, take away the "global $name" calls, they don't do anything. > ?> > <hr> > <?php > include("http://www.vocalwebsites.com/footer.php"); Same thing here... You're getting the parsed _result_ of footer.php, not the code. ---John Holmes...

« previous php.general (#138276) next »