Problems with new PHP version

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bane
Forum Newbie
Posts: 2
Joined: Fri Jan 09, 2004 6:04 pm

Problems with new PHP version

Post 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?
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post 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.
bane
Forum Newbie
Posts: 2
Joined: Fri Jan 09, 2004 6:04 pm

Post 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"?
Fataqui
Forum Newbie
Posts: 10
Joined: Fri Jan 09, 2004 7:47 pm

Post 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!
AnonymousPHP
Forum Newbie
Posts: 1
Joined: Mon Jan 19, 2004 1:47 am

Post 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
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post 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']'
Post Reply