View Full Version : Variables wont carry through includes
Nothadoth
06-26-2006, 08:55 PM
I am setting a variable on my index.php and including the page "includes/navright.php".
The page is included and working, but when I call that variable from inside the navright.php page to show it's information, it comes out as blank.
This is happening everywhere and anywhere. Why????
Please help - it is REALLY frustrating me.
It was working fine before, until I started changing some stuff.
I used to have $BASEDIR containing my root url to save me writing it all out, then I decided not to, and changed all the $BASEDIR to the url itself because sometimes it wasn't working. And now - it just wont carry any variable through an include.
Please don't double-post.
If you're accessing the variable inside a function, you will need to
global $var; before using it.
Nothadoth
06-26-2006, 09:39 PM
I don't understand how to make the variable global.
it's not inside a function. It's inside an include.
I have the variable set - $creator = "Nothadoth";
Then i have
require_once("http://www.finalfantasyfan.net/includes/contentfooter.php");
And then in contentfooter.php I call the variable:
print "".$creator."";
And it doesn't work...
Btw: sorry, double-clicked submit on mistake.
djr33
06-26-2006, 11:04 PM
You can't include php as php code from a different server. It will instead take the output (html) and include that, like it would any non-php, just html page.
while you do seem to be using the same server, I believe this is the issue, because you are using a full URL, including http://.....
If you were to just use a relative URL, like require_once("includes/contentfooter.php"); I would guess it would work.
See if that helps.
this is just a hunch, but it makes sense.
this is just a hunch, but it makes sense.It's a good hunch. That is most likely the problem, yes. Just something I'm curious about:
print "".$creator."";This is totally pointless, but you're not the first person I've seen do it. Exactly what advantage do you think it yields?
djr33
06-27-2006, 12:49 AM
Perhaps people just like the quotes? heh.
Or... maybe that makes the output a string because the ""'s are strings? even if the $creator isn't.... er....
I dunno... weird. :)
Or... maybe that makes the output a string because the ""'s are strings? even if the $creator isn't.... er....That's justification for one set of single quotes, in a few extremely rare situations in which PHP wouldn't convert it properly.
Nothadoth
06-27-2006, 07:04 AM
I've learnt php through studying other codes and scripting my own, messing with forums etc.
Im only a begginer. Any techniques I pick up, like that, I get from others.
Ill try what you said in a minute. If it works, I thank you very much. In fact, this is the only forum where i've had a decent response.
:)
EDIT: It works! However. Is there anyway I can sneak the root url in? I was looking for a base template my staff can use without having to add ../ and all that everywhere. Is this possible? Can you suggest a way?
When I had it on a variable included in the maincore.php it wouldn't work everywhere.
Just set your include_path correctly in php.ini.
Nothadoth
06-27-2006, 07:11 PM
I dont know how php.ini works. I'll look it up, unless you have a tutorial?
http://www.php.net/manual/en/ini.core.php#ini.include-path
Nothadoth
06-27-2006, 08:00 PM
Sorry. Im really not very good at php yet. Im new.
So what do I put in my php.ini file if my includes path is http://www.finalfantasyfan.net/includes/
It's a local path, not an URL.
Nothadoth
06-28-2006, 07:27 AM
Do I have to include php.ini?
<?php
// Works as of PHP 4.3.0
set_include_path('/home/noth/public_html/includes');
// Works in all PHP versions
ini_set('include_path', '/home/noth/public_html/includes');
?>
i didn't include it but had this and it didn't work. When i went into a sub folder the includes were messed up.
I'm not surprised.
Try:
$seperator = ":"; // ; for Windows, : for anything else
set_include_path(get_include_path() . $seperator . '/home/noth/public_html/includes');
Nothadoth
06-28-2006, 03:17 PM
I put that in my php.ini file and then went on to my index.php in the folder 't' and it wouldn't work:
Warning: main(includes/maincore.php): failed to open stream: No such file or directory in /home/noth/public_html/t/index.php on line 11
Fatal error: main(): Failed opening required 'includes/maincore.php' (include_path='.:/usr/lib/php:/usr/local/lib/php:/home') in /home/noth/public_html/t/index.php on line 11
Twey. Have you got AOL or MSN?
By the way mate, you've been a great help, thank you a lot :)
Twey. Have you got AOL or MSN?Happily, no.
Firstly, that wasn't meant to be in your php.ini file, it's PHP code. If you want to use php.ini, find the line beginning "include_path" and add :/home/noth/public_html/includes to the end of the value.
Secondly, there'll be no need to specify the directory; it would simply be require_once('maincore.php').
Nothadoth
06-28-2006, 04:47 PM
Ok thannk you - it worked. Wouldn't work in php.ini so I put that code at the top.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.