Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Variables wont carry through includes

  1. #1
    Join Date
    Jun 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Variables wont carry through includes

    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.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Please don't double-post.

    If you're accessing the variable inside a function, you will need to
    Code:
    global $var;
    before using it.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jun 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.
    Last edited by Nothadoth; 06-26-2006 at 09:56 PM.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Quote Originally Posted by djr33
    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?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Jun 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.
    Last edited by Nothadoth; 06-27-2006 at 07:21 AM.

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Just set your include_path correctly in php.ini.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Jun 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I dont know how php.ini works. I'll look it up, unless you have a tutorial?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •