SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Hybrid View

  1. #1
    SitePoint Member rIGO's Avatar
    Join Date
    Jan 2002
    Location
    Malta
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP includes & iFRAME

    hey guys,

    im trying to find an alternative solution to iFRAME as most browers do not like iFRAME.

    now i was trying to use PHP and tried the following...
    PHP Code:
    <?php
          
    if ($show == "") {
            include (
    "main.php");
          } else {
             include (
    "$show.php");
          }
    ?>
    now in theory if i do call index.php?show=news i should be calling news.php in the index page right?? for some reason it calling the news page seperately and not in the index page.

    any ideas?
    rIGO

  2. #2
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Try

    <?php
    if ($_GET['show'] == "" ) {
    include 'main.php';
    } else {
    include $show.'.php';
    }
    ?>
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  3. #3
    SitePoint Member rIGO's Avatar
    Join Date
    Jan 2002
    Location
    Malta
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tried it.... didnt work.
    rIGO

  4. #4
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $show 
    addslashesstrip_tags$_GET['show'] ) );

    if (empty(
    $show))
    {
        include(
    'main.php');
    }
    else
    {
        include(
    $show '.php');
    }
    ?>
    Mike
    It's not who I am underneath, but what I do that defines me.

  5. #5
    SitePoint Member rIGO's Avatar
    Join Date
    Jan 2002
    Location
    Malta
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok now it works.... but i have another problem... in news i want restricted access so i have created a session. obviously when i call index.php?show=news this error comes up

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent

    any ideas...how i can arrange it?
    rIGO

  6. #6
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    You have to put session_start() before any info is sent to the browser. IE

    <?php
    session_start();
    $show = addslashes( strip_tags( $_GET['show'] ) );

    if (empty($show))
    {
    include('main.php');
    }
    else
    {
    include($show . '.php');
    }
    ?>
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  7. #7
    SitePoint Member rIGO's Avatar
    Join Date
    Jan 2002
    Location
    Malta
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by The New Guy
    You have to put session_start() before any info is sent to the browser. IE

    <?php
    session_start();
    $show = addslashes( strip_tags( $_GET['show'] ) );

    if (empty($show))
    {
    include('main.php');
    }
    else
    {
    include($show . '.php');
    }
    ?>
    ok...but that starts a session even when im in main.php. is it wise to add a session and i do not use it? i only need the session when $show=news.
    rIGO

  8. #8
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    UK
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't matter when you start the session. Also, unless you use output buffering you don't have choice because, as The New Guy says, you cannot start a session after any characters have been sent to the client's browser.

  9. #9
    SitePoint Member rIGO's Avatar
    Join Date
    Jan 2002
    Location
    Malta
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok...i got news.php working with that... but now i get the following error for main.php (main.php does not need session_start):

    session_start() [function.session-start]: Cannot send session cookie - headers already sent
    rIGO

  10. #10
    SitePoint Member rIGO's Avatar
    Join Date
    Jan 2002
    Location
    Malta
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry news.php doesnt work with this method... the error comes again.

    session_start() must be specified somewhere else...i guess...before the actual headers. right?
    rIGO

  11. #11
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    UK
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In a nutshell, session_start() should be specified before any headers are sent to the client's browser. Stick it at the top of the page.


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
  •