Why Doesn't This Run Index.html ?

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
abrogard
New php-forum User
New php-forum User
Posts: 22
Joined: Sat Oct 14, 2006 2:25 am

Mon Apr 09, 2018 2:19 pm

Why doesn't this code display the index.html ?

It is running on a win10 machine with IIS.

The directories exist, the html files exist, the directories are known to IIS.

I just get a blank white screen. What can I do to know what's happened, where it's at? Something I can put in the code perhaps?


Code: Select all

<?php
$user = $_SERVER["LOGON_USER"];
echo $user;

switch ($user) {

    echo "here we are in the php scripts";
    case "diana":
        echo "hello diana";
		{header('Location: diana/index.html');}
        break;
    case "roger":
        echo "hello roger";
		{header('Location: roger');}
        break;
    case "dave":
        echo "hello dave";
                {header('Location: guest/index.html');}
        break;
	case "anon":
        echo "hello anon";
		{header('Location: guest/index.html');}
        break;
}
?>

Phi11W
New php-forum User
New php-forum User
Posts: 17
Joined: Thu Aug 17, 2017 3:37 am

Tue Apr 10, 2018 2:57 am

Does IIS know what to do with PHP code?

Assuming that it does, does this display anything?

Code: Select all

<?php
echo 'Hello World' ; 
Regards, Phill W.
Regards,
Phill W.

abrogard
New php-forum User
New php-forum User
Posts: 22
Joined: Sat Oct 14, 2006 2:25 am

Tue Apr 10, 2018 3:40 am

yes IIS knows what to with PHP. It run phpinfo() perfectly.

I don't think it is running the script at all.

think I read somewhere about a similar hassle turned out to be because of a bad word processor writing some characters that threw everything off....

I did it in notepad. I'll try something different... kompozer maybe...

God i hate this colour scheme.. can I change it?

I looked at the files and the 'bad' one had FFFE at the start where the other one didn't.

So I recreated it in PSPad and got rid of that. But it didn't help. I just get a white page. Must be something wrong with the code?

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 719
Joined: Mon Feb 22, 2016 5:52 pm

Tue Apr 10, 2018 6:39 am

Just need to check a few things:
It ran phpinfo() perfectly.
Are your directories (guest & diana) in the same location as your phpinfo.php file?

abrogard
New php-forum User
New php-forum User
Posts: 22
Joined: Sat Oct 14, 2006 2:25 am

Tue Apr 10, 2018 12:42 pm

No, they are not.
So they have to be known to IIS by setting them up as 'virtual directories', which has been done.

But that's a good thought.I"ll try other scripts leaving out those bits.

It would be nice if I could know it was trying to run the script but I think with PHP it either all runs or nothing - right?

edit: I commented out the 'header' line leaving just the echo.

But nothing echoed. I just get blank white pages.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 719
Joined: Mon Feb 22, 2016 5:52 pm

Tue Apr 10, 2018 1:48 pm

The server can only operate in certain areas, known as the server root, in order for a php script to be executed, it must be in this area. If your files end with the extension .html, you need to make sure that the server will serve these as well.

abrogard
New php-forum User
New php-forum User
Posts: 22
Joined: Sat Oct 14, 2006 2:25 am

Tue Apr 10, 2018 3:54 pm

My machine is always reporting errors connecting with php-forum's server. I have to try two or three times.

Anyway I've found the solution. Well, no, I haven't found the solution but I've now got a working script. But I don't know why it works now when it wouldn't before.

I started from an almost fully commented out script just adding bits back in while ever it continued to work.

Got to where it was all added in except the ?> so I figured that must have been the problem though I couldn't understand why.

But then I uncommented that - expecting it to fail. But it didn't.

It's all running.

This is the script that now performs perfectly:

Code: Select all

<?php
echo 'Hello World' ; 
$user = $_SERVER["LOGON_USER"];
echo $user;
          switch ($user) {

//   echo "here we are in the php scripts";
    case "diana":
        echo "hello diana";
	{header('Location: diana/index.html');}
        break;
   case "roger":
       echo "hello roger";
		{header('Location: roger');}
        break;
   case "dave":
      echo "hello dave";
               {header('Location: guest/index.html');}
       break;
	case "anon":
       echo "hello anon";
		{header('Location: guest/index.html');}
       break;
}
  phpinfo(); 
  
  ?>
not quite the same as the original. changed while I was playing with it. but where's the difference that makes it work now?

Enache
New php-forum User
New php-forum User
Posts: 7
Joined: Mon Apr 02, 2018 1:19 pm

Wed Apr 11, 2018 10:11 am

Code: Select all

switch ($user) {

    echo "here we are in the php scripts";
    case "diana":
This was in your 1st example, but in the second "working" one you commented out that 2nd line. It would have been causing a syntax error. You might benefit from finding your PHP error log and checking it for errors when things like this happen.

I'll not comment on the other issues with the code. :P

abrogard
New php-forum User
New php-forum User
Posts: 22
Joined: Sat Oct 14, 2006 2:25 am

Wed Apr 11, 2018 1:19 pm

Well thanks for that. What's the reason that would have broken it? You don't want to say? I'll figure it out.

I obviously know no PHP. I'm using it because I have to. So far. I think.

Maybe I will have to switch to an ASP IIS installation whatever that is and maybe then I won't need PHP. Until then I struggle on.

I can't see the code on screen on your reply because of this colour scheme.

Is it possible to change it?

Post Reply