Jump to content

Including PHP in PHP


trackandfield

Recommended Posts

I'm trying to include a page on another php page, and I'm not sure what function to use. Typically I would include a page with:

 

<?php include 'filename.php'; ?>

 

However, the larger page already begins with "<?php"... How do I include, or "call up", a PHP page in a PHP script?

 

Thanks!

 

Sean

Link to comment
https://forums.phpfreaks.com/topic/61870-including-php-in-php/
Share on other sites

 

 

you can use 

 include('config.php');

And you don't need to use php tag again for this function.

 

noussh

 

It is not required, but it is alright if you do it.

 

The reason I would include them is incase someone wanders your site and finds filename.php, whoops all of your code is visible to everyone.

 

The <?php and ?> will hide that code incase someone accidentally finds that page.

 

Edit: Just re-read the question and found it confusing.

 

The filename.php file should have the <?php tags.

 

However to include a file inside a php file already, if you are working within the tags you do not need them again and it will throw a syntax error:

 

//included.php

<?php
echo 'here';
?>

 

//wheretoinclude.php

<?php
echo 'Welcome we are ';
include('included.php');
echo '!!!';
?>

 

The example above is how it should be done.

Link to comment
https://forums.phpfreaks.com/topic/61870-including-php-in-php/#findComment-308084
Share on other sites

I tried include('...'); , but the page ends up printing the actual code (see large print in upper right hand corner): http://www.jockandbuttons.com/ggh/news/news.php?action=detail&id=1185390632

 

To be more specific: I'm trying to include the PHP page within HTML code that is displayed by a PHP script. So within the actual PHP script beginning with <?php , some HTML will be displayed that tries to call up the other PHP page:

 

echo "

<div id='column_left_interior'>

<?php include 'news.php'; ?>

</div>

 

However, it won't show up! Any thoughts? Thanks...

Link to comment
https://forums.phpfreaks.com/topic/61870-including-php-in-php/#findComment-308086
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.