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_server_refer/redirect.php –> I need “redirect.php”) to know which this page and include some parts corresponding with leftColumn and rightColumn.

Thank for watching!

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 $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. :slight_smile:

@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! Thank a lot ralph.m. I’ll try it now. Let’s help me if I have any question.

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


<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


<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?

Hi. So sorry! My english is basic. That’s what I want before. I have a problem above.

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 $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!

Not at all! Your post are fine. We just want to make sure we’ve answered the question. :slight_smile: