duanjue9889 2013-10-05 16:59
浏览 19

无法让简单的PHP工作; 简单的elseif图像切换器按计划进行

I can't seem to figure out what the problem is here. I'm hosted on GoDaddy, and I wrote a basic .htaccess file so the website would be password protected since it's for a client. I can't find anything wrong with the php code itself but I'm new to php so I may be missing something obvious. Here's the code:

<?php
$date = date("m,d");

if($date == "10,06"){ 
     echo("<img src="maps/img1.jpg" />");
}
elseif($date == "10,10" or "10,11" or "10,12" or "10,13"){
     echo("<img src="maps/img2.jpg" />");
}
elseif($date == "10,18" or "10,19" or "10,20"){
     echo("<img src="maps/img3.jpg" />");
}
elseif($date == "10,25" or "10,26" or "10,27"){
     echo("<img src="maps/img4.jpg" />");
}
elseif($date == "11,01" or "11,02" or "11,03"){
     echo("<img src="maps/img5.jpg" />");
}
elseif($date == "11,07"){
     echo("<img src="img6.jpg" />");
}
elseif($date == "11,22" or "11,23" or "11,24"){
     echo("<img src="maps/img7.jpg" />");
}
elseif($date == "12,01"){
     echo("<img src="maps/img8.jpg" />");
}
elseif($date == "12,06" or "12,07" or "12,08"){
     echo("<img src="maps/img9.jpg" />");
}
else{
     echo("<img src="maps/img10.jpg" />"); 
}
?>

I'm coding in dreamweaver and the code appears 'dead,' but I can't figure out what is wrong with it. The problem seems to be on this line:

if($date == "10,06"){ echo("<img src="maps/img1.jpg" />");
}

But I don't see anything wrong with it. If I put it in the body of an HTML file, I get the images showing up with a mess of code all around them. If I put it in a .php file, I get this error message:

Parse error: syntax error, unexpected T_STRING in /home/content/##/blahblah/html/test.php on line 12

If this is any clue, I've tried running a simple

<?php echo "hello world"; ?>

And it simply comes up blank. So I have a feeling it's a permissions error, but I haven't the faintest how to fix it. I tried adding this string into the .htaccess file

AddType application/x-httpd-php .html

which only results in an internal server error.

Right now the ONLY thing the .htaccess file has in it is this:

AuthUserFile /home/content/##/blahblah/html/.htpasswd
AuthGroupFile /dev/null
AuthName "EnterPassword"
AuthType Basic

require valid-user

(and of course I have the .htpasswd file in the root as well)

So I probably need to put more stuff into .htaccess but I have no idea what.


EDIT: I fixed the echo and else statement errors (thanks!!), and I tested it on both a .html and a .php. Now it seems the problem is the server doesn't want to read the php in the html file, because it seems to work fine on the .php test. As I mentioned before, I tried adding the AddType application/x-httpd-php .html string into the .htaccess file, but it just messes up the whole website. I'll go to the test.html and it will ask me if I want to download the page after I put that string in.

EDIT2: I seem to have solved the embedding php problem. After a large amount of research, I discovered that GoDaddy allows you to apply custom extensions like so:

Options +ExecCGI
AddHandler x-httpd-php5-3 .mysite

through which I would replace '.mysite' with '.html'

Works like a dream now. (though I have yet to see if this causes other problems in the future)

Thanks to all for correcting my statements---definitely would never have worked without that!

  • 写回答

6条回答 默认 最新

  • duanqian6295 2013-10-05 17:04
    关注

    Every echo function you coded is wrong. Each of them should be like below :

    echo "<img src='maps/img1.jpg' />";
    

    Here is the manual page of echo : php.net/manual/en/function.echo.php

    评论

报告相同问题?