Jump to content

Simple Coding Problem with "Echo"


BCNorth

Recommended Posts

Hi all - I am a novice when it comes to PHP, but I have managed to use it successfully many times. I have an issue where I can not get a variable to echo when I am calling it from within a file that is using SSI. Here is a basic example that should explain it better.

 

In the /index.php file:

<?php 
$photo1="photo1.jpg";
$photo2="photo2.jpg";
?>

<?php include('http://www.DOMAIN.com/includes/header.php'); ?>

 

In the /header.php file:

<img src="http://www.DOMAIN.com/photos/<?php echo $photo1; ?>">

 

 

When I try to echo $photo1 from within the /header.php file it simply does nothing, even though the variable is declared before the call for the include file.

 

If I try to do the echo with the IMG tag from within the /index.php file, it works no problem -but that wont work without a MAJOR site redesign with how things are configured.

 

Question is, why does this not work, and how can I fix it?

 

Huge thanks from this Newb!

Link to comment
https://forums.phpfreaks.com/topic/217767-simple-coding-problem-with-echo/
Share on other sites

If the included file is in the same domain as the including script, do not use a URL in the include statement, just us a path to the file. When you use a URL, that url gets process via PHP and just the results are included in the script.

 

Just use

<?php
$photo1="photo1.jpg";
$photo2="photo2.jpg";

include ('includes/header.php');
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.