Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 9 of 9

Thread: Need PHP help

  1. #1
    Join Date
    Sep 2005
    Location
    Earf lolzzz!!1oneone!shift!
    Posts
    803
    Tokens
    0

    Default Need PHP help

    I have a header.php and I need the file to change depending on which page includes it.

    Basically, say I open a page called 1.php. This page includes header.php. I need header.php to change because it is being called by 1.php. Then, I need it to change again if it is called by 2.php etc etc.

    I don't know if this is possible. I asked my IT teacher who told me it would probably be done using sessions, but I have no idea how to do that.

  2. #2
    Join Date
    Feb 2008
    Location
    North Carolina, USA.
    Posts
    172
    Tokens
    0

    Default

    Your IT teacher is crazy then.

    Let me get this correct.

    1.php
    -> Header.php
    2.php
    -> Header.php
    3.php
    -> Header.php

    You could just set a variable?

    in:

    PHP Code:
    <?php
    $bla 
    "bla";
    include 
    "header.php";
    ?>
    In header.php

    PHP Code:
    <?php
    echo $header;
    ?>
    If your using a function in header.php your going to need to define that variable as a global.

  3. #3
    Join Date
    Sep 2005
    Location
    Earf lolzzz!!1oneone!shift!
    Posts
    803
    Tokens
    0

    Default

    Here's some psuedo code for people to help them understand.

    If header.php is being called from 1.php, I need a certain part of the document to echo 1.

    If header.php is being called from 2.php, I need a certain part of the document to echo 2.

    Etc.

    1.php and 2.php aren't their real filenames though.

  4. #4
    Join Date
    Feb 2008
    Location
    North Carolina, USA.
    Posts
    172
    Tokens
    0

    Default

    Well the easiest way I can think of right now is the way I said.

    if 1.php was named bla.php:

    bla.php:

    PHP Code:
    <?php
    // BLA.php

    $name "bla";
    include 
    "header.php";
    ?>
    header.php

    PHP Code:
    <?php
    // Header

    echo "This page is being called from: $name";

    ?>

  5. #5
    Join Date
    Jul 2005
    Posts
    1,653
    Tokens
    50

    Latest Awards:

    Default

    PHP Code:
    <?php
    if($_SERVER['REQUEST_URI'] == '/1.php') {
    echo 
    '1';
    } elseif(
    $_SERVER['REQUEST_URI'] == '/2.php') {

    } else {

    }
    ?>
    Not complete, but you get the idea, check out if the reserved variable I used is the correct one and make sure it uses the / and not just 1.php

  6. #6
    Join Date
    Feb 2008
    Location
    North Carolina, USA.
    Posts
    172
    Tokens
    0

    Default

    Totally forgot about REQUEST_URI, even though I used it in my script less then an hour ago.

  7. #7
    Join Date
    Jan 2007
    Location
    Canada eh?
    Posts
    766
    Tokens
    75

    Default

    1.php
    PHP Code:
    <?php
    include('header.php?num=1');
    ?>
    header.php
    PHP Code:
    <?php
    echo $_GET['num']; // It will echo whatever '?num=' is
    ?>
    That would be another way to do it.... maybe not exactly what you're looking for but it can be modified for your exact needs

  8. #8
    Join Date
    Feb 2008
    Location
    North Carolina, USA.
    Posts
    172
    Tokens
    0

    Default

    You can't include files with variables.. it can only be direct filenames.

  9. #9
    Join Date
    Sep 2005
    Location
    Earf lolzzz!!1oneone!shift!
    Posts
    803
    Tokens
    0

    Default

    I'll try Ryan's way and post back with any problems. Thanks a lot guys, +rep to all

Posting Permissions

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