I need to alternate a header image depending upon the page on a website I am working on. Unfortunately I absolutely nothing about PHP and really need some help here. I asked customer support and they told me to add: <?php $mypage = strtolower($this_filename); switch ($mypage){ case "pagename1.php": $header_image = "some_file1"; break; case "pagename2.php": $header_image = "some_file2"; break; case "pagename3.php": $header_image = "some_file3"; break; case "pagename4.php": $header_image = "some_file4"; break; } ?> Code (markup): I've tried this out, only changing the $header_image = "some_file" and the case "pagename.php" to my own image paths and file names. Unfortunantly, it does nothing for me and I really don't know where I am going wrong because, as I have said I know NADA about PHP but I really need this to work so I don't have to attempt to edit each page. I have Googled this for hours and am no closer to really understanding it. For instance, $mypage = strtolower($this_filename); Code (markup): means nothing to me. Can anyone help me, please? - Theresa
you should learn html first, then javascript, php, flash... $mypage = strtolower($this_filename); //convert filename to lower case
I know html and css, slowly but surely attempting to learn javascript (I'm not an idiot, I just don't know PHP). And I have already tried the script, exactly as you see it, lowercase everything (because that's what xhtml has taught me ) except adding my own image paths etc. This is basically what I have coded. <?php $mypage = strtolower($this_filename); switch ($mypage){ case "pagename1.php": $header_image = "imgs/some_file1.gif"; break; case "pagename2.php": $header_image = "imgs/some_file2.gif"; break; } ?> Code (markup):
Your code looks fine except that the variable $this_filename is unassigned. Try the following code: <?php $this_filename = $_SERVER['PHP_SELF']; $mypage = strtolower($this_filename); switch ($mypage){ case "pagename1.php": $header_image = "imgs/some_file1.gif"; break; case "pagename2.php": $header_image = "imgs/some_file2.gif"; break; } ?> Code (markup): For this code to work, you need to make sure the php script (pagename1.php etc.) and the "imgs" folder are in the same directory.