bad_gui Posted March 7, 2008 Share Posted March 7, 2008 I am trying to learn php with the Welling & Thompson book. I am updating and customizing a package that will search an archive of documents on my hard drive- no remote access. This works with php4 but when I upgraded my distro it came with php5.2 and now the index.php has problems. The first problem is an echo statement that has the second quote escaped (by the percent?). I haven't found why php5 treats this code differently than php4. I would like to make the code work for both versions. <? session_start(); include 'data.php'; $reload_to_install = str_replace("index", "install", $_SERVER['PHP_SELF']); if (!isset($database_host)) header("Location: http://$_SERVER[HTTP_HOST]$reload_to_install"); if (!isset($_GET["from"])) { $from = '0'; } else { $from = $_GET["from"]; } if (!empty($_SESSION["user"])) $username = explode ('@', strtoupper($_SESSION["user"])); /////////////start define functions////////////////////// function show_results($result,$select,$from,$show) { include 'data.php'; $i = $from; $link = mysql_connect($database_host, $database_user, $database_password); mysql_select_db ($database_name); echo ' <TABLE BORDER="0" CELLPADDING="5" CELLSPACING="5" WIDTH="100%">'; while ($paper = mysql_fetch_array($result)){ $i = $i + 1; Here is what I see in my browser: ; while ($paper = mysql_fetch_array($result)){ $i = $i + 1; echo " $i. $paper[authors] $paper[title] $paper[journal] $paper[date1] "; if ($show == 'abstract') { print "Brief"; } else { print "Abstract"; } if (isset($_SESSION["auth"])) { echo " | Quote Link to comment Share on other sites More sharing options...
matto Posted March 7, 2008 Share Posted March 7, 2008 If you are seeing php code in your browser your server doesn't know how to process PHP. Sounds like to need to re-configure your webserver Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 7, 2008 Share Posted March 7, 2008 Always use a full opening php tag <?php Quote Link to comment Share on other sites More sharing options...
bad_gui Posted March 7, 2008 Author Share Posted March 7, 2008 O.K. so now when I change the starting <? to <?php the index.php script is ignored and the browser loads another one, intsall.php, from the same directory Why? While poking around my php.ini file I found this. Where can I read more about code differences between php4 and php5 since my book covers php5? ;;;;;;;;;;;;;;;;;;;; ; Language Options ; ;;;;;;;;;;;;;;;;;;;; ; Enable the PHP scripting language engine under Apache. engine = On ; Enable compatibility mode with Zend Engine 1 (PHP 4.x) zend.ze1_compatibility_mode = Off ; Allow the <? tag. Otherwise, only <?php and <script> tags are recognized. ; NOTE: Using short tags should be avoided when developing applications or ; libraries that are meant for redistribution, or deployment on PHP ; servers which are not under your control, because short tags may not ; be supported on the target server. For portable, redistributable code, ; be sure not to use short tags. short_open_tag = Off ; Allow ASP-style <% %> tags. asp_tags = Off Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 7, 2008 Share Posted March 7, 2008 Read about the changes in the fine manual. Ken Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 7, 2008 Share Posted March 7, 2008 The short open tag is a configuration option. It has nothing to do with php4 vs php5. The short open tag was a lazy-way short cut that results in non-portable code and simply should not be used by anyone. Short open tags created two ways of accomplishing the same thing. However all other php configuration options are detectable at runtime by the code and the code can take an appropriate action if something is not available, but because code won't even run if it is using short open tags and the option is not turned on, your code will fail. To produce code that will always be parsed, only use full <?php tags. There are sections in the php manual that lists the differences between php4 and php5 - http://www.php.net/manual/en/faq.migration5.php http://www.php.net/manual/en/migration5.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.