Page 1 of 1

Problems with new PHP version

Posted: Fri Jan 09, 2004 6:04 pm
by bane
I am using Php 4.3.4 now, and some parts of my code can't work.
I used Php 4.0.5 before and this code worked fine.

Now: (WinXP, Apache 1.3.6, Php 4.3.4, register_globals=off)

Please, I need answer for this example (page name one.php):

<?php
if ($page=="two")
{ include ("two.php"); }
else if ($page=="three")
{ include ("three.php"); }
else if ($page=="four")
{ include ("four.php"); }
else
{
?>
<a href="one.php?page=two>Page two</a>
<a href="one.php?page=three>Page three</a>
<a href="one.php?page=four>Page four</a>
<?php
}
?>

When I click on some links, I always get one.php page with lots of errors like: Undefined variable, Undefined index...

I tried to use $_GET, but something is wrong again.

HOW can I make this code to work with Php 4.3.4?

Posted: Fri Jan 09, 2004 6:26 pm
by microthick
It should be:

if ($_GET["page"]=="two")
{ include ("two.php"); }
else if ($_GET["page"]=="three")
{ include ("three.php"); }
else if ($_GET["page"]=="four")
{ include ("four.php"); }


Etc.

But you said that you tried $_GET already... so I dunno.

Posted: Fri Jan 09, 2004 6:43 pm
by bane
Well, I get different pages and this is ok.

But I still have some errors like:

Notice: Undefined index: page in ..... on line ...
(every line where is "if ($_GET["page"]=="......")

What I should do to define "page"?

Posted: Fri Jan 09, 2004 7:47 pm
by Fataqui
Hi

short version

empty() will not return a error if the $var is not defined, isset() will...

$default equals the value of $page, only if $_GET['page'] is not defined or if the $_GET['page'] value does not fall in the (min = 2, max = 4) number that you wish to use for your include();!


[syntax=php]<?
$default = 1;

$page = ( !empty( $_GET['page'] ) && ( $_GET['page'] >= 2 && $_GET['page'] <= 4 ) ) ? $_GET['page'] : $default ;

include( $page . '.php' );

?>[/syntax]


F!

Posted: Mon Jan 19, 2004 1:47 am
by AnonymousPHP
Your error reporting level is set too high in the IIS+PHP configuration.
There is nothing wrong with the code.
Checking is a variable is set is one way to go. You can assign a default value like in Fataqui example.
There is another way using error_reporting() function. You can find out more in PHP manual.

If you include in your code one line at the beginning of the script:

error_reporting(7);

all your problems will be solved. (i think so :roll: ).
This will only show E_ERROR | E_WARNING | E_PARSE.

I hope it will help you.
Bye bye

Posted: Mon Jan 19, 2004 2:49 am
by phpcoder
if u want to use variable as '$page' then u have to turn on ur register_globals=off to register_globals=on otherwise u have to use '$_POST['page']'