Jump to content

If condition: "is this page" = "do this"


Norman

Recommended Posts

I have created my first inluded header.php/fotter.php. I want to know how do I set some coditionals that define things like "if is this page" = "show this", "if is that page" = "show that", etc. How do I do? Also, I would like to know if the <?php include 'header.php'; ?> is a secure method or not. Thanks in advance! :)

Link to comment
Share on other sites

Well you could put it like.if ($_GET['page']=='index') { //whatever}Get the picture?
Then, should I put the the name of the .php page? For example, if I have a page called 'test.php', and I waht to show something on my header if is that page, should I put it like this..
if ($_GET['page']=='test) {  //whatever}

Or am I wrong?

If there are a lot of different possibilities I usually set a variable before including.
<?php  $page = 'home';  include 'header.php';  ...

And for what does that variable stands for? I mean.. what does it define befoure I include my header.php?
Link to comment
Share on other sites

It defines the page name so that the include file knows which page you're on. You don't need to use $_GET.

<?php$page = 'home';include 'header.php';?>

header.php

<?phpif ($page == 'home'){  echo 'This is the home page';}?>

Link to comment
Share on other sites

Thanks you for your replies. Also, how do I do to set more that one page into my "if ($page ==.."? Example: if ($page == 'home,test,test2'{ echo 'This is the home, test and test2.';}And is that (include 'header.php':) a secure method?

Link to comment
Share on other sites

Also, how do I do to set more that one page into my "if ($page ==.."?
You mean like
if ($page == "home" || $page == "test" || $page == "test2") {	echo "This is the home OR test OR test2";}

Or

if ($page == "home") {	echo "This is home";} else if ($page == "test") {   echo "This is test";} else if ($page == "test2") {   echo "This is test2";}

And is that (include 'header.php';) a secure method?

Yes. Its like pasting the file for inclusion into the file it is called from.

Link to comment
Share on other sites

You mean like [cut]
Yup, thanks!
Yes. Its like pasting the file for inclusion into the file it is called from.
And for example, couldn't an hacker (or maybe a cracker) include another file replacing my header.php in order to damage my site?
Link to comment
Share on other sites

And for example, couldn't an hacker (or maybe a cracker) include another file replacing my header.php in order to damage my site?
They could but that would be a filesystem insecurity (as that would be how they got their file there in the first place), and it wouldn't be prevented by removing the include() call, as they could just go to the URL of their file directly. So as long as you don't leave insecure file uploading scripts lying around on your site or have a really simple FTP password you should be fine.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...