php-b-grader
php-b-grader

Reputation: 3325

PHP include not executing code

I have an include in the head of my php file:

include 'scripts/tracking_code.php';

In there, I run a basic test with if/else and echo some basic text.

Problem is that nothing is getting printed to screen.

I then just tried to print something a little more basic... The tracking_code.php now simply includes this:

echo "<!-- This is the file -->";

Still nothing?

I know the include is getting included because when I turn E_ALL error reporting, the $_GET[] call throws a "Notice: Undefined index:"

Here is my original code (before simply replacing with "echo" (as above))

<?php

$trackingid = $_GET['trackingid'];

if ( !empty( $trackingid ) ) {
    echo "<!-- trackingid: $trackingid -->";
} else { 
    echo "<!-- trackingid is empty -->";
}
?>

Yet nothing is ever printed?

What am I missing?

Upvotes: 0

Views: 1914

Answers (1)

Is your tracking script echo "<!-- This is the file -->"; or is it

<?php
  echo "<!-- This is the file -->";
?>

Because without the php tags, there's a good chance that your require call actually makes PHP go "this is not actually a PHP file and as such I cannot require it" but with the error/warning repressed due to whatever error reporting settings are active when you run the code.

Upvotes: 3

Related Questions