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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.