Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 3rd, 2004, 10:15 AM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default pass variable into function and retaining value

I have a function that displays the footer on the web pages that uses an image reference. To reference the location of the directory I have created a variable called $image_path that holds the directory location of the images. My code looks like this:

Code:
$image_path="http://127.0.0.1/testsite/images";

function footer()
{
   global $image_path;
   echo "<img src=\"$image_path/footer.gif\" alt=\"#\" name=\"footerImage\" width=\"11\" height=\"14\" border=\"0\" id=\"footerImage\">";
}
I several different footers for different sections of the website.
When I come to call the function it displays it without any problem, but I get the error message:

Fatal error: Cannot redeclare footer() (previously declared in C:\Progra~1\Apache Group\Apache2\htdocs\testsite\includes\common\inc_ common.php:11) in C:\Progra~1\Apache Group\Apache2\htdocs\testsite\includes\common\inc_ common.php on line 9

I have had a look through the PHP books and it looks like that I am doing the right thing in calling the variable and declaring it as global within the function.

Am I doing it wrong?

Thanks.

Michael.
__________________
Michael.
  #2 (permalink)  
Old August 3rd, 2004, 10:36 AM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

problem solved!!!

I was recalling the include file again at the bottom of the web page thats why it was saying there was a redeclare.

silly me!
  #3 (permalink)  
Old August 4th, 2004, 06:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As a matter of interest, why are you using the full URL ("http://127.0.0.1/testsite/images")?

If / is the root directory of your site, and testsite is a subdirectory of it (which is what appears to be happening) then you could point to the images subdirctory via:
<img src="/testsite/images/imagename.png" width... height... etc. />

The leading slash indicates "root of website".

HTH
Dan
  #4 (permalink)  
Old August 4th, 2004, 06:47 AM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Daniel,

I dont think that I have configured my Apache correctly to do that.

When I put in the / (slash) it goes to the Apache root and I get my perosonal page that I set up.



Michael.


Similar Threads
Thread Thread Starter Forum Replies Last Post
send variable in function to another function schoolBoy Javascript How-To 6 March 3rd, 2007 09:16 AM
Pass Value to XSLT variable bonekrusher XSLT 3 October 9th, 2006 10:16 AM
pass java variable to xsl variable kathy1016cats XSLT 1 June 14th, 2006 06:23 PM
pass variable kapi.goel C# 1 January 6th, 2006 05:54 AM
pass form elements variable vickyj Classic ASP Basics 0 October 29th, 2005 04:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.