Question

This code used to work in earlier versions of PHP4 but no longer works on my website now that the hosting server has been upgraded to PHP5. Any easy way to alter this code to make it work again?

<?
if ($info == "file1") {include ("file1.html");}
if ($info == "file2") {include ("file2.html");}
if ($info == "file3") {include ("file3.html");}
if ($info == "file4") {include ("file4.html");}
if ($info == "file5") {include ("file5.html");}
?> 

EDIT: yes, this is the code I have on the final website (not a PHP pro here). I call the "$info=_" just in a simple link (I'm wanting to return www.website.com/?info=file), ie:

<a href="?info=file1">Click here to read File 1</a> 
Était-ce utile?

La solution

Based on your edit, it seems that the problem is that you had register_globals on in your old version of php in the php.ini file.

register_globals extracts all global variables so where you normally use $_GET['info'], with register_globals on, you can simply use $info.

This functionality is deprecated in php 5.3 and removed from php 5.4 as it poses a huge security risk.

To solve your problem, you can set the variable before your conditions:

$info = $_GET['info'];
if ($info == "file1") {include ("file1.html");}
...

Autres conseils

If this is the actual code, your issue is the use of the short tags, <? at the start of your PHP block. These are no longer supported by default in PHP5. Instead use

<?php ...code here... ?>

Alternatively, you can ask your provider to set the "short_open_tag" option in php.ini.

By default, short tags <? ?> are not enabled.

Without knowing your error, try using <?php instead of <?

Update: Since you are obviously including the page with the short open tags, in your calling page, you can call:

ini_set('short_open_tag', '1');

I doubt your service provider will set the short open tags attribute for you.

There's an error in your code. Change this:

if ($info == "file5") {include ("file5html");}

To this:

if ($info == "file5") {include ("file5.html");}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top