Jump to content

Converting from PHP4 to PHP5


tigomark

Recommended Posts

Hello,

 

I recently upgraded from PHP 4 to 5 and I have some problems with my page directories now with the upgrade. I have my navigation tree set up as such

 

 

<tr>

<td height="14" width="15"><img src="/images/spacer.gif" width="15"></td>

<td height="14"><p>

<? if ($mid == "Stuff") { echo "<SPAN CLASS=\"curnav\">"; } ?>

<img border="0" src="/images/menu/bullet.gif">

<a href="/Stuff/"><b>Stuff</b>-The talk of the town</a></td>

</tr>

<? if ($mid == "Stuff" || $sitemap == "1") { ?>

<tr>

<td height="14" colspan="2">

<ul><DIV CLASS="subnav">

 

<li><? if ($id == "1") { echo "<SPAN CLASS=\"cursubnav\">"; } ?>

<a href="<? echo "/Stuff/$htmod_dir/$htmod_index"; ?>1/">Stuff</a> </SPAN>

 

<li><? if ($id == "2") { echo "<SPAN CLASS=\"cursubnav\">"; } ?>

<a href="<? echo "/Stuff/$htmod_dir/$htmod_index"; ?>2/">Stuff1</a> </SPAN>

 

<li><? if ($id == "3") { echo "<SPAN CLASS=\"cursubnav\">"; } ?>

<a href="<? echo "/Stuff/$htmod_dir/$htmod_index"; ?>3/">Stuff2</a> </SPAN>

 

<li><? if ($id == "4") { echo "<SPAN CLASS=\"cursubnav\">"; } ?>

<a href="<? echo "/Stuff/$htmod_dir/$htmod_index"; ?>4/">Stuff3</a> </SPAN>

 

<li><? if ($id == "5") { echo "<SPAN CLASS=\"cursubnav\">"; } ?>

<a href="<? echo "/Stuff/$htmod_dir/$htmod_index"; ?>5/">Stuff4</a> </SPAN>

 

</ul></DIV>

</td>

 

<? } ?>

 

The variables of $htmod_dir and $htmod_index are held in an include with values of

$htmod_dir = "e";

$htmod_index = "4,815,162342/523";

This function describes what the mid should be.

 

function current_dir()

{

$path = dirname($_SERVER['PHP_SELF']);

$position = strrpos($path,'/') + 1;

return substr($path,$position);

}

$mid=current_dir();

 

 

$sitemap in defined on a seperate page with

 

$sitemap = "1";

 

On my sitemap page. This will call the menu in a list form to navigate the site so that when I update the menu then the sitemap is updated as well.

 

 

 

For each directory I have a splash.php page that will define what includes should added for each page that will appear in the body

 

$dirtitle = "Stuff";

 

if ($_GET['id'] == "") {

 

$title = "Stuff";

include('../includes/title.php');

include('../pages/Stuff/splash.htm');

 

 

} else if ($_GET['id'] == "2") {

 

$title = "Stuff2";

include('../includes/title.php');

include('../pages/Stuff/l.htm');

include('../pages/Stuff/header.htm');

include('../pages/Stuff/data.php');

include('secureddata.php');

include('unsecureddata.php');

include('homedata.php');

include('../pages/footer.htm');

 

// There is a definition for each variable for the above tree, it just gets a little long for one post.

 

 

 

} else {

 

$title = "Error: 404";

include('../includes/title.php');

include('../pages/errors/404.htm');

include('../pages/sitemap/splash.htm');

 

In PHP 4 everything is okay doky, but now the only thing that will display is the index of each directory. Any other subheading will come up with an ISS 404. It will not display the custom error pages that I set up. I should mention that this is a W.indows I.ss M.ysql P.hp set up with PHP defined as CGI.

 

Any help or suggestions would be great.

Thank you.

Now with the build

 

 

Link to comment
https://forums.phpfreaks.com/topic/38394-converting-from-php4-to-php5/
Share on other sites

There is nothing in that code that is specific to php5. You do realize however that you are comparing string when they should be integers? eg;

 

$id == "1"

 

Should be....

 

$id == 1

 

I also don't see anywhere where you have defined $id.

 

You should be using the longer <?php tags instead of <? unless you have specifically enabled short tags in your php.ini (bad practice).

 

One lest thing, include is not a function but a language construct and therefore does not need brackets around it argument. eg;

 

include('../includes/title.php');

 

should be...

 

include '../includes/title.php';

I would approach this by adding diagnostic print statements throughout your code.  For example, if you know that $_GET['id'] should be 1 but the if statement is taking the wrong branch, print out $_GET['id'] just before.  var_dump() is quite useful for this, as it tells you the type of a variable as well as its value.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.