Please help a newbie - PHP is running, but code is not executed

This is a discussion on Please help a newbie - PHP is running, but code is not executed within the PHP Language forums, part of the PHP Programming Forums category; Hello, I hope someone will be able to help me on this. I am not very experienced with PHP, doing ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-15-2008
Alan Silver
 
Posts: n/a
Default Please help a newbie - PHP is running, but code is not executed

Hello,

I hope someone will be able to help me on this. I am not very
experienced with PHP, doing ASP.NET normally. I have a requirement to
use a third-party set of PHP pages on a site, and it's not running
properly. I don't think the problem is with the pages though, I think
PHP might not be running correctly.

The server is Windows 2003 Server with IIS and all the latest patches,
service packs, etc. I have PHP 5.2.3 running, and if I create a small
PHP page with just

<?php phpinfo(); ?>

in it, I get the expected information. This implies that PHP is running
OK. I have tried a couple of other basic PHP scripts, and they seem to
run OK as well. I went through the examples in the "simple tutorial" at
www.php.net and got exactly the results predicted.

However, if I try to run the pages I'm supposed to be installing, PHP
doesn't run. The code in the file is sent to the browser as plain text.
If I view the source of the page, I can see some (although not all) of
the PHP code in there. If I rename the PHP to have a .html extension, it
looks exactly the same. This sounds like the page is not being executed.

For example, there is code like this in the page...

<input type="text" name="db_user" value="<?=$CFG_db_user?>" />

The browser shows a text box with <?=$CFG_db_user?> inside. Obviously
the code isn't being executed.

Does anyone have a clue what is going on here? I realise it may be hard
without seeing the page, but it's not currently on a production server.

If there's any more info I can supply, please let me know.

TIA

--
Alan Silver
(anything added below this line is nothing to do with me)
Reply With Quote
  #2 (permalink)  
Old 01-15-2008
Paul Lautman
 
Posts: n/a
Default Re: Please help a newbie - PHP is running, but code is not executed

Alan Silver wrote:
> Hello,
>
> I hope someone will be able to help me on this. I am not very
> experienced with PHP, doing ASP.NET normally. I have a requirement to
> use a third-party set of PHP pages on a site, and it's not running
> properly. I don't think the problem is with the pages though, I think
> PHP might not be running correctly.
>
> The server is Windows 2003 Server with IIS and all the latest patches,
> service packs, etc. I have PHP 5.2.3 running, and if I create a small
> PHP page with just
>
> <?php phpinfo(); ?>
>
> in it, I get the expected information. This implies that PHP is
> running OK. I have tried a couple of other basic PHP scripts, and
> they seem to run OK as well. I went through the examples in the
> "simple tutorial" at www.php.net and got exactly the results
> predicted.
> However, if I try to run the pages I'm supposed to be installing, PHP
> doesn't run. The code in the file is sent to the browser as plain
> text. If I view the source of the page, I can see some (although not
> all) of the PHP code in there. If I rename the PHP to have a .html
> extension, it looks exactly the same. This sounds like the page is
> not being executed.
> For example, there is code like this in the page...
>
> <input type="text" name="db_user" value="<?=$CFG_db_user?>" />
>
> The browser shows a text box with <?=$CFG_db_user?> inside. Obviously
> the code isn't being executed.
>
> Does anyone have a clue what is going on here? I realise it may be
> hard without seeing the page, but it's not currently on a production
> server.
> If there's any more info I can supply, please let me know.
>
> TIA


He he, I could maybe use your help as I am having to do a few asp/MSSQL
pages and my experience is php/MySQL.

Anyway, your problem is that <? is what is called a "short open tag" and in
the more recent releases of php their use is disabled by default.

So instead of <?=$CFG_db_user?> use <?php echo $CFG_db_user;?>


Reply With Quote
  #3 (permalink)  
Old 01-16-2008
Jerry Stuckle
 
Posts: n/a
Default Re: Please help a newbie - PHP is running, but code is not executed

Alan Silver wrote:
> Hello,
>
> I hope someone will be able to help me on this. I am not very
> experienced with PHP, doing ASP.NET normally. I have a requirement to
> use a third-party set of PHP pages on a site, and it's not running
> properly. I don't think the problem is with the pages though, I think
> PHP might not be running correctly.
>
> The server is Windows 2003 Server with IIS and all the latest patches,
> service packs, etc. I have PHP 5.2.3 running, and if I create a small
> PHP page with just
>
> <?php phpinfo(); ?>
>
> in it, I get the expected information. This implies that PHP is running
> OK. I have tried a couple of other basic PHP scripts, and they seem to
> run OK as well. I went through the examples in the "simple tutorial" at
> www.php.net and got exactly the results predicted.
>
> However, if I try to run the pages I'm supposed to be installing, PHP
> doesn't run. The code in the file is sent to the browser as plain text.
> If I view the source of the page, I can see some (although not all) of
> the PHP code in there. If I rename the PHP to have a .html extension, it
> looks exactly the same. This sounds like the page is not being executed.
>
> For example, there is code like this in the page...
>
> <input type="text" name="db_user" value="<?=$CFG_db_user?>" />
>
> The browser shows a text box with <?=$CFG_db_user?> inside. Obviously
> the code isn't being executed.
>
> Does anyone have a clue what is going on here? I realise it may be hard
> without seeing the page, but it's not currently on a production server.
>
> If there's any more info I can supply, please let me know.
>
> TIA
>


Paul gave you the reason. Now you should take this back to whomever
wrote that junk and make them fix it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Reply With Quote
  #4 (permalink)  
Old 01-16-2008
Toby A Inkster
 
Posts: n/a
Default Re: Please help a newbie - PHP is running, but code is not executed

Paul Lautman wrote:

> Anyway, your problem is that <? is what is called a "short open tag" and
> in the more recent releases of php their use is disabled by default.
>
> So instead of <?=$CFG_db_user?> use <?php echo $CFG_db_user;?>


Or (less work for you) find php.ini and switch the short open tag option
on.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 16 days, 20:58.]

Gnocchi all'Amatriciana al Forno
http://tobyinkster.co.uk/blog/2008/0...llamatriciana/
Reply With Quote
  #5 (permalink)  
Old 01-16-2008
Alan Silver
 
Posts: n/a
Default Re: Please help a newbie - PHP is running, but code is not executed

In article <na0165-9lc.ln1@ophelia.g5n.co.uk>, Toby A Inkster
<usenet200712@tobyinkster.co.uk> writes
>Paul Lautman wrote:
>
>> Anyway, your problem is that <? is what is called a "short open tag" and
>> in the more recent releases of php their use is disabled by default.
>>
>> So instead of <?=$CFG_db_user?> use <?php echo $CFG_db_user;?>

>
>Or (less work for you) find php.ini and switch the short open tag option
>on.


Thanks to both of you for your help. I tried changing php.ini and the
pages worked fine.

If I went through all the .php files in this collection and did a global
find and replace for "<?" to "<?php" would that do the trick, or is
there likely to be anything that might get thrown out by this? Obviously
I would have to check that they hadn't used any <?php tags, as this
change would result in <?phpphp which would probably cause even more
problems!

Thanks again

--
Alan Silver
(anything added below this line is nothing to do with me)
Reply With Quote
  #6 (permalink)  
Old 01-16-2008
Alan Silver
 
Posts: n/a
Default Re: Please help a newbie - PHP is running, but code is not executed

In article <2YednTuHLtKDyhDanZ2dnUVZ_gSdnZ2d@comcast.com>, Jerry Stuckle
<jstucklex@attglobal.net> writes
>Paul gave you the reason. Now you should take this back to whomever
>wrote that junk and make them fix it.


Don't worry, I will! They tried to convince me that PHP wasn't working,
even though I pointed out that my (admittedly simple) test pages had
worked fine. Now I know what the problem is, I can address it directly.

Thanks

--
Alan Silver
(anything added below this line is nothing to do with me)
Reply With Quote
  #7 (permalink)  
Old 01-16-2008
Toby A Inkster
 
Posts: n/a
Default Re: Please help a newbie - PHP is running, but code is not executed

Alan Silver wrote:

> If I went through all the .php files in this collection and did a global
> find and replace for "<?" to "<?php" would that do the trick, or is
> there likely to be anything that might get thrown out by this?


Search and replace ought to be fine. Just remember that there are three-
types of shorttag:

<? ... ?>
<% ... %>
<?= ... ?>

The first two should be replaced with:

<?php ... ?>

The last one should be replaced with:

<?php echo ... ?>

The files you need to be careful with are XML files or PHP files that
generate XML output -- this is because '<?' is a commonly used construct
in XML to introduce a "processing instructions", such as an XML version
hint, or link to a CSS stylesheet or XSLT transformation.

Indeed, it's because of this '<?' confusion with XML that shorttag is
disabled by default in more recent versions of PHP. Careful authors can
author XML with PHP with shorttag enabled and not have any problems. But
not everyone is careful. ;-)

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 16 days, 23:29.]

Gnocchi all'Amatriciana al Forno
http://tobyinkster.co.uk/blog/2008/0...llamatriciana/
Reply With Quote
  #8 (permalink)  
Old 01-16-2008
Alan Silver
 
Posts: n/a
Default Re: Please help a newbie - PHP is running, but code is not executed

In article <4h9165-9lc.ln1@ophelia.g5n.co.uk>, Toby A Inkster
<usenet200712@tobyinkster.co.uk> writes
>Search and replace ought to be fine.

<snip>

Thanks for that. I have had quite a bit of hassle with this code, even
after sorting out the short tags, and it looks like we might just drop
the whole thing. The code doesn't seem very good, and the support from
the company who wrote it is poor. I think we'll do without it ;-)

Thanks for the help.

--
Alan Silver
(anything added below this line is nothing to do with me)
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:44 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0