...

View Full Version : Help! PHP code to display .HTML pages..



arslan89
12-07-2010, 01:11 AM
Hey, I haven't worked on PHP and HTML for a while, so I am trying to get back into it and make a website..

What PHP code do I have to use to make it so that I can make links on my index.php page that people can click, and the content on those .html pages.. will be displayed in index.php layout page..

I have done this before, but I totally forgot.. the links were similar to '?id=aboutme.html' .... that would basically put the content of .html in my index.php page.. however.. when you first visit the index.php page... it will have a default page (such as news or other content already being displayed.. How do I do that?

I want my news to be displayed by default.. and then.. have links to the .html pages.. my news is located at '/public_html/new/news/news.php' ... so how will I implement that by default.. and then also have the functionality of having '?id=' pages.. ?

Thanks in advance!

mlseim
12-07-2010, 01:28 AM
<?php

// set the default page
$page="/public_html/new/news/news.php";

// if there is an incoming URL variable, let's use that instead ...
if(isset($_GET['id'])){
$page=$_GET['id'];
}

// You have to be careful about this ...
// Basically, you are allowing the user to put in any file (or script) they choose.

// Later on, if you "include" that file, you would be allowing the user to display/execute any file,
// including such things as "config.php" ... that's a bad breach of security.
// But, I wanted to answer your question as you stated.
?>

<html>
<body>
The rest of your page here.<br />
<br />
Now, we can include the content you wanted:<br />
<?php include($page)?>
<br />
</body>
</html>

arslan89
12-07-2010, 01:44 AM
That was awesome! Yeah it worked great. I see that you mentioned a security flaw in that code... is there any way to prevent that? I mean, how else would I be able to have ONE layout page (index.php) and have multiple pages be displayed within that layout page? I thought everyone followed this method ?

mlseim
12-07-2010, 01:59 AM
You put your content either in a MySQL database, with id numbers for "articles and content",
or put them into their own text files with names like p12.html, and p23.html

You then use an id code like: id=23

Check to make sure id is an integer only,
and then put it together to form your filename:


<?php

// set the default page
$page="/public_html/new/news/news.php";

// if there is an incoming URL variable, let's use that instead ...
if(isset($_GET['id'])){
$id=$_GET['id'];
if(is_numeric($id)){
$page="p".$id.".html";
}
}
?>

<html>
<body>
The rest of your page here.<br />
<br />
Now, we can include the content you wanted:<br />
<?php include($page)?>
<br />
</body>
</html>





.

arslan89
12-08-2010, 05:04 AM
Hey, thanks so much for your help. I did that and it worked great. Thank you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum