#1
  1. echo $usertitle['computer'];
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    UK
    Posts
    6,707
    Rep Power
    420

    css, functions, headers and includes troubles


    Hi,

    I have setup a templating system for a project I am working on.

    I have got a css file (css/style.css), which needs to be included before ANY text is sent to the browser.

    A common.php which must NOT output anything to the browser (called before header functions and stuff).

    A lib.php, which contains some functions, some which output text and need the CSS and some that will error if the css is included.

    How can I setup something so that when the lib.php is called, for some functions the css header is included and sometimes not?

    Thanks,
    computer
  2. #2
  3. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1100
    This is a hard one for us b/c we have no idea what's in each file. Sounds like you may need to rethink some logic!? Try changing the functions in lib.php to return text instead of echo()ing it.
  4. #3
  5. echo $usertitle['computer'];
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    UK
    Posts
    6,707
    Rep Power
    420
    return text how?

    some of the header needie fucntions build the cell headers and stuff:

    for example:
    PHP Code:
    function mainbox_top(){
    ?>
    <table width="100%">
    <tr>
    <td>

    <table cellspacing="0" cellpadding="0" width="100%">
    <tr>
    <td><img src="images/box/M-up-left.gif" width="15" height="15" /></td>
    <td background="images/box/M-up.gif" width="100%"><img src="images/box/M-up.gif" width="15" height="15" /></td>
    <td><img src="images/box/M-up-right.gif" width="15" height="15" /></td>
    </tr>
    <tr>
    <td background="images/box/M-left.gif"><img src="images/box/M-left.gif" width="15" height="15" /></td>
    <td>

    <!-- Content -->

    <table width=100% BGCOLOR="white">
    <tr>
    <td>
    <p>
    <?php
    }
    ?>
  6. #4
  7. No Profile Picture
    The Freshmaker
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Smurf Village
    Posts
    335
    Rep Power
    0
    A lib.php, which contains some functions, some which output text and need the CSS and some that will error if the css is included.
    why would some of your functions cause error if the css was included?
  8. #5
  9. echo $usertitle['computer'];
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    UK
    Posts
    6,707
    Rep Power
    420
    because to include the css i must do a <head>, no?

    as soon as that happens kabloom
  10. #6
  11. No Profile Picture
    The Freshmaker
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Smurf Village
    Posts
    335
    Rep Power
    0
    when are you including lib.php before or after the css?

    if before, why? sorry if I'm missing something :P
  12. #7
  13. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1100
    I'm confused by it all as well. Why would you call a function that builds a table before you call a function that builds the <head>?

    More on my previous post (returning text):
    PHP Code:
    function foo()
      {
      
    $foo 'text to return';
      return 
    $foo// could just `return 'text to return';`
      
    }
    // use
    echo foo();
    // or
    $foo foo(); // stores in variable for later 
  14. #8
  15. echo $usertitle['computer'];
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    UK
    Posts
    6,707
    Rep Power
    420
    okay i see i am not making sense

    i have a lib.php which contains some functions that cannot be called after headers have been sent. some functions need to have the headers though before they will work correctly.

    on the pages, i have:

    <? include("common.php") ?>
    <? include("header.php") ?>
    <? include("menu.php") ?>

    common.php:
    Code:
    <?php
    session_start();
    header("Cache-control: private");
    
    include("configuration.php");
    include("lib.php");
    
    db_connect($dbhost, $dbuser, $dbpass, $dbdb);
    
    include("online_update.php");
    ?>
    configuration and online_update self explainatery. db_connect is a fnction defiend in lib.php

    header.php:
    does all the sites <head> and starts the body. also includes the css line.

    menu.php:
    just the nav bar.

    I hope you understand, if not, i can just post my source files for you to look at

    Got to go soon though,
    speak later,
    computer
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Barcelona
    Posts
    133
    Rep Power
    13
    why dont you use templates? smarty, for instance.
  18. #10
  19. No Profile Picture
    The Freshmaker
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Smurf Village
    Posts
    335
    Rep Power
    0
    i have a lib.php which contains some functions that cannot be called after headers have been sent.
    ... then don't call those functions after the header's been sent?

    I'm still confused, does lib.php only declare functions or does it actually call/output something? If it only declares functions you should be OK.

    It's valid to use CSS in a function, and to declare it before loading the CSS as long as the CSS has been loaded by the time you call the function.

IMN logo majestic logo threadwatch logo seochat tools logo