SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast greedyman's Avatar
    Join Date
    Jun 2012
    Location
    New World
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How do I take the name of page url?

    I have a template. This template include header, leftColumn, rightColumn and footer. In these, header and footer is no change in any page. I want to take the name of them (example: http://localhost/Demo/function_serve...r/redirect.php --> I need "redirect.php") to know which this page and include some parts corresponding with leftColumn and rightColumn.

    Thank for watching!

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,200
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    Hey greedyman, I don't know PHP, just to warn you (though I like to tinker with the basics), but here's perhaps a simple way to do what you want:

    PHP Code:
    <?php $page basename($_SERVER['PHP_SELF']); 

    if (
    $page == "redirect.php") {
        include 
    $_SERVER["DOCUMENT_ROOT"] . "/folder/file.php";
        };
    ?>
    This is just me tinkering. I'm sure someone has a better answer, from which I'll learn too.

  3. #3
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,146
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Hey greedyman, I don't know PHP, just to warn you (though I like to tinker with the basics), but here's perhaps a simple way to do what you want:

    PHP Code:
    <?php $page basename($_SERVER['PHP_SELF']); 

    if (
    $page == "redirect.php") {
        include 
    $_SERVER["DOCUMENT_ROOT"] . "/folder/file.php";
        };
    ?>
    This is just me tinkering. I'm sure someone has a better answer, from which I'll learn too.
    @ralph.m ; I think that is a fine solution. First time I read the question, I wasn't exactly sure what the original poster wanted, after seeing your response and re-reading his question, the solution seems to fit what I now believe he wants.

  4. #4
    SitePoint Enthusiast greedyman's Avatar
    Join Date
    Jun 2012
    Location
    New World
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Hey greedyman, I don't know PHP, just to warn you (though I like to tinker with the basics), but here's perhaps a simple way to do what you want:

    PHP Code:
    <?php $page basename($_SERVER['PHP_SELF']); 

    if (
    $page == "redirect.php") {
        include 
    $_SERVER["DOCUMENT_ROOT"] . "/folder/file.php";
        };
    ?>
    This is just me tinkering. I'm sure someone has a better answer, from which I'll learn too.
    Hi! Thank a lot ralph.m. I'll try it now. Let's help me if I have any question.

  5. #5
    SitePoint Enthusiast greedyman's Avatar
    Join Date
    Jun 2012
    Location
    New World
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Hey greedyman, I don't know PHP, just to warn you (though I like to tinker with the basics), but here's perhaps a simple way to do what you want:

    PHP Code:
    <?php $page basename($_SERVER['PHP_SELF']); 

    if (
    $page == "redirect.php") {
        include 
    $_SERVER["DOCUMENT_ROOT"] . "/folder/file.php";
        };
    ?>
    This is just me tinkering. I'm sure someone has a better answer, from which I'll learn too.
    Hi! Thank a lot ralph.m. I'll try it now. But my page have four columns, three columns in these is change when I direct to any page. I don't want copy code from this file to that file and then use the code of your. Example:

    index.php
    PHP Code:
    <div id="indexLeftColumn">
        <
    div id="navigation">
            
    // if 'index.php' then include ('abc.php');
        
    </div><!-- end # -->
    </div><!-- end #indexLeftColumn -->
        
    <div id="indexRightColumn">
            <
    div id="innner">
                
    // if 'category.php' then include('def.php');
        
    </div><!-- #inner -->
    </div><!-- end #indexRightColumn --> 
    cart.php
    PHP Code:
    <div id="indexLeftColumn">
        <
    div id="navigation">
            
    // if 'cart.php' then include ('c.php');
        
    </div><!-- end # -->
    </div><!-- end #indexLeftColumn -->
        
    <div id="indexRightColumn">
        <
    div id="innner">
            
    // if 'cake.php' then include('d.php');
        
    </div><!-- #inner -->
    </div><!-- end #indexRightColumn --> 
    index.php's code and cart.php's code are similar. How can I arrange the main page and include page to more easy?

  6. #6
    SitePoint Enthusiast greedyman's Avatar
    Join Date
    Jun 2012
    Location
    New World
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    @ralph.m ; I think that is a fine solution. First time I read the question, I wasn't exactly sure what the original poster wanted, after seeing your response and re-reading his question, the solution seems to fit what I now believe he wants.
    Hi. So sorry! My english is basic. That's what I want before. I have a problem above.

  7. #7
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,200
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    I'm afraid I don't quite understand the question. If you just want to include things in those places, you could do something like this:

    PHP Code:
    <?php $page basename($_SERVER['PHP_SELF']); ?>

    <div id="navigation"> 
        <?php if ($page == "cart.php") { 
            include 
    $_SERVER["DOCUMENT_ROOT"] . "c.php"
        }; 
    ?> 
    </div>
    But if you want a more sophisticated template that serves all pages at once, youll have to set things up a little differently. (What I'm suggesting is just a simple noob solution.)

  8. #8
    SitePoint Enthusiast greedyman's Avatar
    Join Date
    Jun 2012
    Location
    New World
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    I'm afraid I don't quite understand the question. If you just want to include things in those places, you could do something like this:

    PHP Code:
    <?php $page basename($_SERVER['PHP_SELF']); ?>

    <div id="navigation"> 
        <?php if ($page == "cart.php") { 
            include 
    $_SERVER["DOCUMENT_ROOT"] . "c.php"
        }; 
    ?> 
    </div>
    But if you want a more sophisticated template that serves all pages at once, youll have to set things up a little differently. (What I'm suggesting is just a simple noob solution.)
    Hi. Sorry, I quite silly. Thank all!

  9. #9
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,200
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by greedyman View Post
    Sorry, I quite silly.
    Not at all! Your post are fine. We just want to make sure we've answered the question.


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
  •