Jump to content

how to use other PHP file and remind the same design page

Recommended Posts


i am new for the PHP, i had the experienced before to do a login system page but what i want it is HTML and PHP file to separate

i dont want PHP with HTML together to 1 file , cause professional people will more likely to use 2 file rather than 1 file

easy to maintain and edit


how to use the external PHP file coding without re-design whole page cause normally what i tested before was link or turn to other new page and result will come out but the design was totally gone


so have any ways and suggestion to do that ...


in the end, im sorry i not well in english and my knowledge of PHP still quite new , thanks you so much


Link to post
Share on other sites

You can't separate one from the other, the end result is to return from server, php code as html into a page which is inserted into a template at a specific location using php include.


A template page usually consists of head (<head>...</head>) content, nav content, main content area, and footer content. Any of these could use php to gather content from mysql database for specific page.

Link to post
Share on other sites

To: dsonesuk


Thank you so much for reply and the answer too

That mean, PHP page in the end also need to insert the HTML content like nav bar ,footer all that (copy from the previous page design code)

Okok,i get it , but what i saw other people of PHP code , they dont have any html content , just start as <?php ...?>

so how they work and connected all the code,cause if dont have any html content for design when running the page , the result will show it but the design will gone all ....

no way to maintain the design or page and run other php page ...

isnt ajax will work like that ?

im sorry for my english not well...hope you understand what i mean ...


Thanks for helping , once again :good:

Link to post
Share on other sites

Yes! you can make whole of html code within a php page echo/print out as a php text string, if you want to go that way.

echo '<!DOCTYPE html>'."\n"
echo '<html>'."\n"
echo '<head>'."\n"

 echo '</head>'."\n"
    echo '<body>'."\n"
        echo '<div id="test"></div>'."\n"
        echo '<input type="button" value="Change">'."\n"
    echo '</body>'."\n"
echo '</html>'."\n"


echo <<<EOT
        <div id="test"></div>
        <input type="button"value="Change">

AJAX runs AFTER a page is returned from server as html and fully rendered and is triggered by a specific event captured by JavaScript. it uses JavaScript to send a request for data from php file which is returned as html to be inserted to specific location (usually by a id ref of specific element) without the need to reload the page again. IT should be added as a improved method over a totally php method which causes a reload of a page, as JavaScript is required to be enabled for the AJAX method to work.

Link to post
Share on other sites

To: dsonesuk


Thank you so much

Thanks for given me the example and explanation

Thanks for helping

i will try next time


but what i seen people php page before was whole php code and not embed any html code and especially not write it on echo to print out

just like declare a variable and assign the value too ,if not mistaken


so how to run it ... if run it ... how to connect and the page may re-design again @@


thanks again :good:

Link to post
Share on other sites

$head ='<!DOCTYPE html>'."\n";
$head.= '<html>'."\n";
$head.=  '<head>'."\n";
$head.=  '</head>'."\n";

$body = '<body>'."\n";
$body.= '<div id="test"></div>'."\n";
$body.= '<input type="button" value="Change">'."\n";
$body.= '</body>'."\n";
$html_close  ='</html>'."\n";

echo $head.$body.$html_close;

But you could divide 1st post#4 example into two or three separate php files (head.php, content.php, footer.php)


Then include them in a php template file using


include 'head.php';
include 'content.php';
include 'footer.php';


This will gather php generated html text string and include contents in the php template page.

Link to post
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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