1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Using a PHP file inside of my Html website

Discussion in 'Other Languages' started by imamwhat, Feb 9, 2012.

  1. imamwhat

    imamwhat Newbie

    Joined:
    Oct 4, 2010
    Messages:
    6
    Likes Received:
    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.
     
  2. weedsmoker

    weedsmoker Junior Member

    Joined:
    May 2, 2011
    Messages:
    190
    Likes Received:
    79
    Save html file as php (.php extension) and put php code like this for example:

    Code:
    <?php
    php code here
    ?>
    html code here
    
     
    • Thanks Thanks x 1
  3. cuteprinces

    cuteprinces Registered Member

    Joined:
    Apr 27, 2008
    Messages:
    52
    Likes Received:
    1
    Yeah ^^^ is correct
     
  4. SicKk

    SicKk Newbie

    Joined:
    Jan 23, 2012
    Messages:
    19
    Likes Received:
    5
    or make php file with the code and include it with a virtual include like this
    Code:
    <!--#include virtual="the/path/to/file.php" -->
     
  5. backlinks1

    backlinks1 Junior Member

    Joined:
    Jul 13, 2011
    Messages:
    139
    Likes Received:
    43
    it looks like that !
    <html>
    <?php
    php code here
    ?>
    </html>
    but php can work if you install php and My SQL
     
  6. dunker

    dunker Newbie

    Joined:
    Jun 16, 2010
    Messages:
    15
    Likes Received:
    1
    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.
     
  7. 45415

    45415 Junior Member

    Joined:
    Feb 5, 2009
    Messages:
    194
    Likes Received:
    92
    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.
     
  8. thom.holland

    thom.holland Newbie

    Joined:
    Apr 23, 2012
    Messages:
    16
    Likes Received:
    0
    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)
     
  9. Malazath

    Malazath Newbie

    Joined:
    Jan 25, 2012
    Messages:
    28
    Likes Received:
    4
    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.
     
  10. silntbob

    silntbob Newbie

    Joined:
    May 28, 2012
    Messages:
    14
    Likes Received:
    0
    I would recommend using your .htaccess file to do your redirection
     
  11. loki_

    loki_ Registered Member

    Joined:
    May 20, 2012
    Messages:
    63
    Likes Received:
    8
    Location:
    #!/bin/bash/
    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]
     
  12. Blackberry_11

    Blackberry_11 Regular Member

    Joined:
    Apr 17, 2011
    Messages:
    266
    Likes Received:
    19
    It's a job,
    please appoint any one to do it via reputed freelancing site.
     
  13. softx

    softx Newbie

    Joined:
    May 9, 2013
    Messages:
    1
    Likes Received:
    0
    yes ist true
     
  14. johnmacklen

    johnmacklen Registered Member

    Joined:
    Apr 26, 2013
    Messages:
    52
    Likes Received:
    2
    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
    ?>
     
  15. tweakcoder

    tweakcoder Regular Member

    Joined:
    Apr 8, 2012
    Messages:
    238
    Likes Received:
    184
    Occupation:
    PHP Web Developer
    Location:
    India
    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";
    ?>

     
  16. CodingSquared

    CodingSquared Newbie

    Joined:
    Jun 14, 2013
    Messages:
    5
    Likes Received:
    0
    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
    }
    
    ?>
     
  17. gregevskye

    gregevskye BANNED BANNED Jr. VIP Premium Member

    Joined:
    Jul 15, 2013
    Messages:
    309
    Likes Received:
    36
    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.
     
  18. Dhruv11

    Dhruv11 Newbie

    Joined:
    Oct 21, 2012
    Messages:
    33
    Likes Received:
    12
    Make sure to start with php followed by html. Also headers must be sent before any other code even in php.
     
  19. jakson99

    jakson99 Newbie

    Joined:
    May 16, 2013
    Messages:
    21
    Likes Received:
    0
    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
     
  20. edge241

    edge241 Registered Member

    Joined:
    Oct 31, 2013
    Messages:
    85
    Likes Received:
    11
    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