inserting php file into same page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spencermjax
Forum Newbie
Posts: 4
Joined: Tue Nov 23, 2004 10:35 am

inserting php file into same page

Post by spencermjax »

I have an html page with a link
(<a href="?page=website" >Website Templates</a>) that I want to return info to another location on the same page. The following is the location of the data to be inserted.
(
<?PHP $file = $_GET["page"]; if (!isset($file)) { include"./website.php"; } else { include "$file.php"; } ?>
)

Is there anything wrong with it? It does not seem to be working. The incomming data is in a .php file.

Thanks.
kanaps
Forum Newbie
Posts: 13
Joined: Tue Nov 23, 2004 9:23 am
Location: UK
Contact:

Post by kanaps »

If I anderstood all correct you can do following

$ling= "<a href=\"?page=website\" >Website Templates</a>";


//and you can paste this link as many times as you like and where you like it.

print $link;print $link;print $link;print $link;print $link;
spencermjax
Forum Newbie
Posts: 4
Joined: Tue Nov 23, 2004 10:35 am

Post by spencermjax »

Unfortunitely that did not seem to work. The link looked like this

$link= 'Website Templates';
kanaps
Forum Newbie
Posts: 13
Joined: Tue Nov 23, 2004 9:23 am
Location: UK
Contact:

Post by kanaps »

yes, but if you click on your link you will be sent to ?page=website if you need to be send to index.php, just change "?page=website" with "index.php"
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

$file will ALWAYS be set, you defined it

do

if (isSet($_GET['file'])) {
include $GET['file'].'php';
}



be warned though, that is a security hole waiting to be exploited

try a search on this board for :
include security
and youll see why
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

<?
function goto($page)
{

$acceptable = array('index','main','page4','page10');

if (in_array($page,$acceptable) && file_exists($page'.php'))
{

return $page'.php';

}
else
{

return 'denied.php';

}
}

include goto($_GET['page']);

?>

In a nutshell this is what I do to validate included pages
spencermjax
Forum Newbie
Posts: 4
Joined: Tue Nov 23, 2004 10:35 am

Post by spencermjax »

I'm very new to this. In the above code will that function go in the <head> tags? If so what will the link code look like? and what will the code look like where I want the file to be inserted?
spencermjax
Forum Newbie
Posts: 4
Joined: Tue Nov 23, 2004 10:35 am

Post by spencermjax »

Thanks for the help. Problem resoled. I simply did not have my MIME types set on my sever. My orginal codewas just fine but thanks for the input anyway.
Post Reply