Using a PHP file inside of my Html website

imamwhat

Newbie
Joined
Oct 4, 2010
Messages
6
Reaction score
1
Hey there i have a website that is made using html. I have a php file that i would like to use that separates the traffic and sends mobile to one link and desktops to another link. How do i use the php file in the html? Any help would be widely appreciated.
 
Save html file as php (.php extension) and put php code like this for example:

Code:
<?php
php code here
?>
html code here
 
or make php file with the code and include it with a virtual include like this
Code:
<!--#include virtual="the/path/to/file.php" -->
 
it looks like that !
<html>
<?php
php code here
?>
</html>
but php can work if you install php and My SQL
 
You'll have to make sure that your server supports PHP (it has to be able to interpret the actual PHP code and do what the code tells it to do). The easiest way to find this out might be this:

1) Rename your .html file into a .php file.
2) Put this somewhere in your new .php file:
PHP:
<?php echo "PHP seems to be working."; ?>
3) Run this PHP script by visiting the .php file with your browser.
 
If you are redirecting users, make sure you put the PHP code first, before any HTML code. Otherwise you will get a "headers already sent" error, when redirecting user.
 
Make sure to do it clean, keep the HTML separate from the PHP code and include it into your PHP file.
Consider using .tpl templates (Google search)
 
Like state above you can just rename your page, but if you are worried about your rankings you can easily do add a bit of code to your .htaccess file (Depending on your server setup) to change the file extensions back to HTML.
 
Changing all html files to php could be a lot of work if you have many html file(the reason why pure html files are a nasty idea-changing one thing could mean hours of work). So i suggest using the .htaccess options instead. Assuming you are running an apache server you need to add the following to your .htaccess:

Code:
[COLOR=#000000][FONT=monospace]AddType application/x-httpd-php .html .htm
That will tell the server to read html files as php files.

And then what everyone suggested
Code:
<?php
include "my_included_file.php";
?>
[/FONT][/COLOR]
 
hi..
There are 2 way to use HTML on your PHP page but i describe simple one. If you have any problem about that i'll tell you next one.So here we go...
To put the HTML outside of your PHP tags.You can even put it in the middle if you close and reopen the <?php -and- ?> tags.
<?php
//your php code here
?>


<?php
//more php code
?>
 
1. Direct Put code in HTML

<html>
<body>
<?php
//Your code here
?>
</body>
</html>

2. Inherit PHP file using include

<?php
include "file.php";
?>


3. Inherit PHP file using require

<?php
require "my_included_file.php";
?>

 
Make sure your html file has .php extension instead of .html. Here is how to detect mobile users:


Code . Google ---> Mobile_Detect


Code:
[B]<?[/B]php [B]include[/B] [COLOR=#DD1144]'Mobile_Detect.php'[/COLOR]; 
[COLOR=#008080]  $detect[/COLOR] [B]=[/B] [B]new[/B] Mobile_Detect();

if($detect->isAndroidOS() || [COLOR=#008080]$detect[/COLOR][B]->[/B][COLOR=#008080]isiOS[/COLOR]()){
    // redirect the user
}

?>
 
You cannot run php on a .html file. You should to save it as .php and then use php code for processing. <?php?> in this shape.
 
Make sure to start with php followed by html. Also headers must be sent before any other code even in php.
 
You cant use php code in html file you have to change 1st its extinction to .php
then
<?php
php code;
?>

<html>
HTML CODE
</html>
you can use like this
 
definitely include the php file into the html code rather than having it all in one file. Makes it much neater and easier to understand
 
Back
Top