[Q]

Problems with the Linux version of XAMPP, questions, comments, and anything related.

[Q]

Postby Eng_A_Moktar » 10. December 2009 13:13

I'm used to write my php scripts shortly, like this way
if($_GET['var'])
instead of
if (isset($_GET['var']))

it works fine on my localhost, before i moved to XAMPP,
"I believe XAMPP is better or even the best, so i moved to .."

but when i'm testing my old scripts on xampp i get this error with script like this one
Code: Select all
<?php
   if($_GET['var']){
      echo $_GET['var']   ;
   }else{
      echo "err";   
   }
?>


the error :
Code: Select all
Notice: Undefined index: var in /opt/lampp/htdocs/account/ro.php on line 2
err


I wanna some way to get over this, so not have to change my scripting way or all my files :?:
any ideas ?
thanks a lot :wink:
Eng_A_Moktar
 
Posts: 7
Joined: 10. December 2009 13:03

Re: [Q]

Postby Wiedmann » 10. December 2009 13:17

Search the PHP Manual for error_reporting.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: [Q]

Postby Eng_A_Moktar » 10. December 2009 13:18

thanks for fast response
it works fine every where, but in xampp it gives me that errors
Eng_A_Moktar
 
Posts: 7
Joined: 10. December 2009 13:03

Re: [Q]

Postby Altrea » 10. December 2009 14:20

It's best practice not to ignore unset variables/arraykeys.
If you want to shorten your Code this way, you can use an own function.

like this:
http://stackoverflow.com/questions/376623/php-printing-undefined-variables-without-warning
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: [Q]

Postby Eng_A_Moktar » 10. December 2009 14:36

no, you did not understand me,
i have something like this

if ($_GET['userid']){
//do something
}elseif($_GET['userlevel']){
//do something
}

or
if ($_SESSION){
//do something
}

all this doesn't work
i'm not seekin for hide the error message
Eng_A_Moktar
 
Posts: 7
Joined: 10. December 2009 13:03

Re: [Q]

Postby Altrea » 10. December 2009 15:21

in your first example you use this code:

Code: Select all
<?php
   if($_GET['var']){
      echo $_GET['var']   ;
   }else{
      echo "err";   
   }
?>


Looks like a simple "if a variable isset, take this value, else take a default value.
This example can be found in the postet link.

to use isset() is a best practice. thats it.
If you don't want to use it, because its too long and unreadleble for you, you must use an own workaround (or switch off your error_messages with an @ or the error_reporting() function, which both is very sloppy to simply not show existent messages)

An if-statement is simply a boolean true or false choice.
Code: Select all
if ($_GET['userid'])

simply means, if the value of $_GET['userid'] is true...

if you want to check whether or not a variable isset or has some value, use isset() or empy()
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: [Q]

Postby Eng_A_Moktar » 10. December 2009 15:25

I'm with you in all
but the simple question is :
why it was not that way in AppServ ??
Eng_A_Moktar
 
Posts: 7
Joined: 10. December 2009 13:03

Re: [Q]

Postby Altrea » 10. December 2009 15:30

well...

maybe different php default settings.
or different php behavior because of a newer php version?

can't say anything about your old and new webserver package ^^
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: [Q]

Postby Eng_A_Moktar » 10. December 2009 15:37

some login pages were made with dreamweaver,
session are not working fine
the $MM_Username is not defined in XAMPP, but it works fine in my AppServ, and my site !

I really wanna move to xampp
thanks for being patient..
Eng_A_Moktar
 
Posts: 7
Joined: 10. December 2009 13:03

Re: [Q]

Postby Wiedmann » 10. December 2009 15:42

i'm not seekin for hide the error message

Sure. Exactly that's you want in your first post.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: [Q]

Postby Eng_A_Moktar » 10. December 2009 15:55

thanks again
but no o'm not seeking for hide error messages
again
i have :
if ($_GET['cat']){
//do cat thing
}elseif($_GET['userid']){
//do something else
}

this is not working
and the DW login session variables
Eng_A_Moktar
 
Posts: 7
Joined: 10. December 2009 13:03

Re: [Q]

Postby Wiedmann » 10. December 2009 16:03

Code: Select all
if ($_GET['cat']){
//do cat thing
}elseif($_GET['userid']){
//do something else
}

this is not working

Sure, that is working.
But in a default XAMPP installation (and many other PHP installations) you have additionally a "Notice".
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: [Q]

Postby Eng_A_Moktar » 10. December 2009 16:14

Thank so very much
you were very kind and helpful
Eng_A_Moktar
 
Posts: 7
Joined: 10. December 2009 13:03


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 27 guests