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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.