BCNorth Posted November 4, 2010 Share Posted November 4, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/217767-simple-coding-problem-with-echo/ Share on other sites More sharing options...
mikosiko Posted November 4, 2010 Share Posted November 4, 2010 if you header file is complete and correct (you are showing just one line) that should work, add this lines at the begin of any of your php files to see if you catch any error error_reporting(E_ALL); ini_set("display_errors", 1); Quote Link to comment https://forums.phpfreaks.com/topic/217767-simple-coding-problem-with-echo/#findComment-1130359 Share on other sites More sharing options...
kenrbnsn Posted November 4, 2010 Share Posted November 4, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/217767-simple-coding-problem-with-echo/#findComment-1130400 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.