Page 1 of 2

PHP code not executing, but shown in HTML source code

Posted: Mon Apr 12, 2010 3:58 am
by loweauto
I'm trying to include the contact-script.php file on this page of a site: http://www.karmera.de/index.php?go=shop

But it doesn't do anything, and instead, shows the PHP include in the source code. Do you have any ideas as to why?

To give you a better understanding of my site, index.php looks like this:

Code: Select all

<?php 

$go = "index" ; 

if ($_GET["go"])
        $go = $_GET["go"] ;

$body = "html/{$go}.html" ;
$head = "html/_{$go}.html" ;

if (!file_exists($body)) {      
        $body = "html/index.html" ; 
}

if (!file_exists($head)) {
        $head = "html/_index.html" ;
}

$CONTENT = implode('', file($body)) ;
$HEAD = implode('', file($head)) ;
        
include "layout.html" ;

?>
The index.php file opens an include to include the content depending on "index.php?go=contact", for example, and the contact.html resides in root/html/contact.html, and it's just the sheer content (in a div). It then includes a http://www.karmera.de/layout.html file, where there's the design, etc.

As you noticed, there are both .html and .php files, but the thing is - I don't think that should be a problem, as the master file is a .php - so code should execute. To be safe, I even modified htaccess:

Code: Select all

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
What do you think the problem is, and how can I solve it?

Also, any other advice is appreciated!

Thank you for your time.

P.S. When you go to: http://www.karmera.de/html/shop.html it gives the following errors:
Warning: include(./contact-app/common.php) [function.include]: failed to open stream: No such file or directory in /www/htdocs/w0086c88/karmera/contact-script.php on line 8

Warning: include(./contact-app/common.php) [function.include]: failed to open stream: No such file or directory in /www/htdocs/w0086c88/karmera/contact-script.php on line 8

Warning: include() [function.include]: Failed opening './contact-app/common.php' for inclusion (include_path='.:/usr/share/php:..') in /www/htdocs/w0086c88/karmera/contact-script.php on line 8

Re: PHP code not executing, but shown in HTML source code

Posted: Mon Apr 12, 2010 5:21 am
by marty pain
To be honest, your example is not very clear, at least not to me.

You are trying to include a HTML file that contains PHP?

Basically, if you want to include a PHP file (that can of course hold HTML)into your page, do this:

Code: Select all

<?php
  //location of files and default page
  define('FILE_LOCATION', 'html/');
  define('DEFAULT_PAGE','html/default.php');

  if(isset($_GET['page'])) {
    $page = $_GET['page'];
    $location = FILE_LOCATION.$page

    if(file_exists($location)) {
      include($location);
    }
    else {
      include(DEFAULT_PAGE);
    }
  }
  else {
    include(DEFAULT_PAGE);
  }
?>
if you want to include another HTML page do this:

Code: Select all

<?php
  //location of files and default page
  define('FILE_LOCATION', 'html/');
  define('DEFAULT_PAGE','html/default.html');

  if(isset($_GET['page'])) {
    $page = $_GET['page'];
    $location = FILE_LOCATION.$page

    if(file_exists($location)) {
      $pageHTML = get_file_contents($location);
    }
    else {
      $pageHTML = get_file_contents(DEFAULT_PAGE);
    }
  }
  else {
    $pageHTML = get_file_contents(DEFAULT_PAGE);
  }

  echo $pageHTML;
?>
Hopefully these ruff examples are helpful.

Re: PHP code not executing, but shown in HTML source code

Posted: Mon Apr 12, 2010 6:48 am
by loweauto
marty pain wrote:To be honest, your example is not very clear, at least not to me.

You are trying to include a HTML file that contains PHP?

Basically, if you want to include a PHP file (that can of course hold HTML)into your page, do this:

Code: Select all

<?php
  //location of files and default page
  define('FILE_LOCATION', 'html/');
  define('DEFAULT_PAGE','html/default.php');

  if(isset($_GET['page'])) {
    $page = $_GET['page'];
    $location = FILE_LOCATION.$page

    if(file_exists($location)) {
      include($location);
    }
    else {
      include(DEFAULT_PAGE);
    }
  }
  else {
    include(DEFAULT_PAGE);
  }
?>
if you want to include another HTML page do this:

Code: Select all

<?php
  //location of files and default page
  define('FILE_LOCATION', 'html/');
  define('DEFAULT_PAGE','html/default.html');

  if(isset($_GET['page'])) {
    $page = $_GET['page'];
    $location = FILE_LOCATION.$page

    if(file_exists($location)) {
      $pageHTML = get_file_contents($location);
    }
    else {
      $pageHTML = get_file_contents(DEFAULT_PAGE);
    }
  }
  else {
    $pageHTML = get_file_contents(DEFAULT_PAGE);
  }

  echo $pageHTML;
?>
Hopefully these ruff examples are helpful.
thanks for your help!

i'll look into your examples, but the main problem is that php code simply doesn't work on my site.. in the way i've designed it, that is
if you take a look here: http://www.karmera.de/index.php?go=shop

there's meant to be php code after the TBD, if you look in the source code of the page - it shows up there! so something isnt working.. not sure why.. maybe its because of the way my site is laid out? (see my first post for that)

let me know what u think, thanks!

Re: PHP code not executing, but shown in HTML source code

Posted: Mon Apr 12, 2010 8:16 am
by roders
Normally if you're script is calling the correct file it should work. Are you sure that the the file is not being called as withing layount.html? I can't see anything that can go wrong. You might want to try a few static pages like for example where its calling the file just add include("contact-script.php"); see if it changes things.

Re: PHP code not executing, but shown in HTML source code

Posted: Mon Apr 12, 2010 9:15 am
by loweauto
roders wrote:Normally if you're script is calling the correct file it should work. Are you sure that the the file is not being called as withing layount.html? I can't see anything that can go wrong. You might want to try a few static pages like for example where its calling the file just add include("contact-script.php"); see if it changes things.
hi,
actually yeah, i made a seperate test page, without my design: http://www.karmera.de/test2.php

and it works.. so the problem must be with my design.. so something about how it's made, e.g.:

[text]/index.php[/text] calls [text]/html/index.html[/text] and includes [text]/layout.html[/text]

(the code of index.php is in my previous post..)

Re: PHP code not executing, but shown in HTML source code

Posted: Mon Apr 12, 2010 9:22 am
by roders
In which 1 is contact-script.php being called??

Re: PHP code not executing, but shown in HTML source code

Posted: Mon Apr 12, 2010 9:29 am
by loweauto
roders wrote:In which 1 is contact-script.php being called??
that's inside: /html/index.html

and i have tried renaming it .php (actually all files to .php) - and that didn't work either

Re: PHP code not executing, but shown in HTML source code

Posted: Mon Apr 12, 2010 10:06 am
by roders
In your .htaccess at this as well
[text]Addhandler application/x-httpd-php .html .php .htm [/text]
And where the file is being called you need to call it as such

Code: Select all

<!–#include virtual=”html/fileyouwanttocall.php” –>

Re: PHP code not executing, but shown in HTML source code

Posted: Mon Apr 12, 2010 12:35 pm
by loweauto
roders wrote:In your .htaccess at this as well
[text]Addhandler application/x-httpd-php .html .php .htm [/text]
And where the file is being called you need to call it as such

Code: Select all

<!–#include virtual=”html/fileyouwanttocall.php” –>
i added the .php to htaccess, and put: <!–#include virtual="/contact-script.php" -> in the html/shop.html file, but nothing works - now even this shows in the source code

(should i have put <? tags around it?)

Re: PHP code not executing, but shown in HTML source code

Posted: Tue Apr 13, 2010 4:33 am
by roders
Sound like a config problem to me. Does your server have htaccess enable?

Re: PHP code not executing, but shown in HTML source code

Posted: Tue Apr 13, 2010 7:40 am
by loweauto
roders wrote:Sound like a config problem to me. Does your server have htaccess enable?
yea, htaccess works..

Re: PHP code not executing, but shown in HTML source code

Posted: Tue Apr 13, 2010 8:19 am
by roders
where is you htaccess file saved??

Re: PHP code not executing, but shown in HTML source code

Posted: Tue Apr 13, 2010 10:23 am
by loweauto
roders wrote:where is you htaccess file saved??
lol, in the root dir ;) don't worry

Re: PHP code not executing, but shown in HTML source code

Posted: Tue Apr 13, 2010 11:07 am
by roders
did u fix the problem?

Re: PHP code not executing, but shown in HTML source code

Posted: Tue Apr 13, 2010 11:15 am
by loweauto
roders wrote:did u fix the problem?
yes, but by re-doing the html design of the site