Page 1 of 2

php question

Posted: Sat Dec 01, 2007 10:16 pm
by srod
Hi,

I know this isn't a php forum, but I can't see as I'll be doing any harm by asking a few resident php experts around these parts for some basic assistance! :)

Here's the problem. I'm learning php as fast as my little brain will allow and everything is running dandy on my local development machine.

Having just uploaded some of these test scripts onto the web I am finding that those scripts residing within .php files run fine. However, when embedding some php code into a html page via the <?php... ?> tags, I find that the page is not being passed to the php module on the server; the php tags are not being processed!

I've contacted the host company about this but my feeling is that they will not make the necessary adjustments to the .htaccess file (if one even exists on a Windows server?)

Now, I can get around this problem by having my webpage hand control completely to a php script which then generates the remainder of the html as appropriate. My question, therefore, is whether there is a html command which will cause a php script to be executed? I guess I'm basically asking if there's a way of having a html page redirect the user's browser to a php script?

Thanks in advance.

Posted: Sat Dec 01, 2007 10:28 pm
by srod
Okay, managed a redirection via javascript; but there must be a better way of dynamically running a php script?


**EDIT : actually, this works very well! :)

Posted: Sat Dec 01, 2007 10:43 pm
by LuCiFeR[SD]
how can I put this old mate... if you for example are editing a file called index.html and put some php in it... it doesn't work... the reason php doesn't know it exists.... now if you renamed that file index.php it would work... and you wouldn't need to change a line of code in the html. so, simplest way to fix it.... rename the page you are working on and update the links.

as for "redirection" you just redirecting to another page or something?

Code: Select all


<?php
header( 'Location: http://www.satanicdreams.com/satanicdreams/index.php' ) ;
exit;
?>
it is just that simple in php

Posted: Sat Dec 01, 2007 10:49 pm
by srod
how can I put this old mate... :wink:, Apache servers can run php scripts through an add on module and can then be configured to deal with not just php files, but html ones aswell. This means that all html files are passed to the php module before being transferred to the client. This in turn means that you can embed php code within html files and have it executed before the server passes on the resulting html etc. This is very useful and runs well on my local host here.

As for your suggestion; I don't really want visitors to my site having to enter something like 'www. fabcode.php' ! No sir! :)

Configuring an Apache server to pass html files to the php module is easy, but I do not have access to the appropriate files on the remote server.


**EDIT : as for the redirection, I need to redirect from the client browser, not from the server itself because I'm redirecting from html not from php. As I say I have the redirection working through a little Javascript.

Posted: Sat Dec 01, 2007 10:54 pm
by LuCiFeR[SD]
aye, I see where you are coming from, but 99.9 percent of servers are not setup to parse php via html file extensions. It is just a mime types issue really with the server. but if it was your index page that is redirecting.....just rename the damn index to have a php file extension lol. saves all the bother as apache will quite happilly load either extension

edit: well if the javascript works lol.... its near enough :P

Posted: Sat Dec 01, 2007 10:59 pm
by srod
Yes, I've used url masking combined with javascript so that when the user types in www.mydomain.com the index.html file immediately (using javascript) redirects the browser to mydomain.php.

The user will still only ever see www.mydomain.com in the address bar of their browser though (thanks to the masking).

Works well, but just seems a little backward to me. I don't know why servers are not configured automatically to pass html files to the php engine etc. Or at least give me the option of adding a .htaccess file which I can use to achieve my goals?

Thanks for the replies.

Posted: Sat Dec 01, 2007 11:14 pm
by Trond
I don't know why servers are not configured automatically to pass html files to the php engine etc.
Because all the 100000+ static html pages on that server will have to go through php as well as the php files, which will cause a massive performance drop.

Posted: Sat Dec 01, 2007 11:17 pm
by srod
Yes, I was kind of mulling that thought over whilst posting! :) Still, I stick to my second assertion regarding .htaccess files!

Posted: Sun Dec 02, 2007 12:15 am
by traumatic
I'm not sure if I fully got this right, but if it's a windows server chances are
high that it's not even running apache but IIS instead.
If so, there's no .htaccess available.

If the server is running apache, your provider should really allow you to
access the .htaccess. I've never come across any provider that forbids
that. I mean, how do you setup error-documents for example?

Posted: Sun Dec 02, 2007 12:19 am
by srod
Haven't heard from them as yet, but I do think that my domain is hosted on a Windows server. I think a few years ago when I first used this service I had a choice of server; Linux (Apache) or Windows server 2003. Some stupid idiot decided that Windows would be the best choice! :?

Posted: Sun Dec 02, 2007 12:21 am
by traumatic
What does

Code: Select all

<?php phpinfo(); ?>
say?

Posted: Sun Dec 02, 2007 12:22 am
by srod
Hey, I didn't think of that! One mo...

Posted: Sun Dec 02, 2007 12:25 am
by traumatic
is it purecoder.net? then it's an IIS, see here:

http://www.purecoder.net/blarp.php
HTTP Error 404 - File or directory not found.
Internet Information Services (IIS)
So there's next to no chance to change the server's behaviour on your own.
On apache, a simple

Code: Select all

addtype application/x-httpd-php .html
inside your .htaccess would do the trick. Sorry!

Posted: Sun Dec 02, 2007 12:26 am
by srod
:)

I ran the phpinfo() function :

Code: Select all

System  Windows NT IIS6110 5.2 build 3790  
Build Date  Aug 16 2006 01:13:15  
Server API  ISAPI  
Virtual Directory Support  enabled  
Configuration File (php.ini) Path  C:\WINDOWS\php.ini  
PHP API  20020918  
PHP Extension  20020429  
Zend Extension  20050606  
Debug Build  no  
Zend Memory Manager  enabled  
Thread Safety  enabled  
Registered PHP Streams  php, http, ftp, compress.zlib  
Guess I should look into moving to one of their linux servers.

Posted: Sun Dec 02, 2007 12:27 am
by traumatic
srod wrote:

Code: Select all

System  Windows NT IIS6110 5.2 build 3790  
Sincere condolences! ;)