Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorephi
    • CommentTimeFeb 25th 2006
     permalink
    This is my template.php file

    template.php (located in: http://mysite.com/new/template.php)
    ...
    <body>
    <? echo $title; ?>
    </body>
    ...

    and this is my xxx.php file that will include template.php

    xxx.php (located in: http://mysite.com/new/mission/xxx.php)
    ...
    $title="Information";
    include 'http://mysite.com/new/template.php';
    ...

    ------------------

    The xxx.php shown in the browser will output the template file, without the values for $title. Can somebody:
    (1) explains what happen?
    (2) suggest what I should do to tackle the problem? Suppose I want to put xxx.php anywhere in my site.
    •  
      CommentAuthornifkin
    • CommentTimeFeb 25th 2006 edited
     permalink
    well, one piece of advice: don't include() the file using a full URL, use a local file path to it.

    <?php
    $title="Information";
    include($_SERVER['DOCUMENT_ROOT'].'/new/template.php');
    ?>


    $_SERVER['DOCUMENT_ROOT'] is an automatic reference to the root directory for the website the file is being served from, so all you need to do is tack file paths (to web accessible stuff, that is) onto the end of it. saves a little time over trying to figure out include('/home/myusername/www/sitename/new/template.php') or whatever other weird full paths you might be needing to use otherwise.

    (Using include() on remote files is a big security no-no, and actually probably is why it won't pull that variable name in there. Otherwise what would stop you from using include('http://www.example.com/some/path/to/a/config.php'); and stealing someone else's DB information?)
    • CommentAuthorephi
    • CommentTimeFeb 27th 2006
     permalink
    Very nice input.
    Thank you so much, nifkin! And also for the security insight.
Add your comments
    Username Password
  • Format comments as (Help)