Log in

View Full Version : isset/unset



pcbrainbuster
03-13-2007, 04:52 PM
Hello :),

Can anyone please explain the isset and unset functions in php in relation to javascript (this will make it easier)

boxxertrumps
03-13-2007, 05:08 PM
I have a script.

<?php
$var = "some string"
if(isset($var)) { //Returns true, the variable is set.
unset($var); // undoes the variable
echo $var; //echoes nothing.
}
?>

pcbrainbuster
03-13-2007, 05:16 PM
Thanks for that simple example !

pcbrainbuster
03-13-2007, 05:19 PM
Is there anything else to isset function apart from checking if things are set ?

boxxertrumps
03-13-2007, 05:31 PM
I dont think so.

pcbrainbuster
03-13-2007, 05:43 PM
Well thanks for your help :)

Twey
03-13-2007, 06:04 PM
It can check if a given item exists in an array, too.

pcbrainbuster
03-13-2007, 06:28 PM
What do you mean ? do you mean something like isset(sesion_start()) ?

boxxertrumps
03-13-2007, 07:03 PM
No he means:

<?php
$arr = array(
"key"=>"val",
"num"=>"1234",
"letter"=>"abc",
"nonalphnum"=>"!@#$"
);
if(isset($arr["num"])){
echo "The value is set"; //echos if it is set
echo $arr["key"]; //echos "val"
unset($arr["key"]);
echo $arr["key"]; //echos nothing, because it doesnt exist.
}
?>

pcbrainbuster
03-13-2007, 09:03 PM
OK thanks i see :)

Twey
03-13-2007, 10:02 PM
echo $arr["key"]; //echos nothing, because it doesnt exist.Also throws a warning.

pcbrainbuster
03-13-2007, 10:04 PM
Thanks :), i understand the non-existing part but don't understand that thing about warning part...

pcbrainbuster
03-13-2007, 10:08 PM
And one more thing :), how do you record a persons ip address (PHP)

Twey
03-13-2007, 11:49 PM
i understand the non-existing part but don't understand that thing about warning part...There are three levels of message in PHP: error, warning, and informational. By default, PHP only displays error messages, which indicate when something's gone wrong and the script is unable to continue. However, it can also display warning messages, which highlight bad coding practices (such as accessing non-existent variables or array elements) and other potential problems, and informational messages, which just give a information about what something is doing. To show them all (and I recommend doing this when debugging a script), call:
error_reporting(E_ALL);
how do you record a persons ip addressThe IP address of the client (note that this may also be a proxy) is stored in $_SERVER['HTTP_REMOTE_ADDR'].

pcbrainbuster
03-14-2007, 12:21 AM
Thanks for your posts guys :), just one question to twey - HOW DO YOU KNOW EVRYTHING ?!! :)

Twey
03-14-2007, 12:27 AM
I don't... you evidently weren't here to see mwinter in action :)

boxxertrumps
03-14-2007, 12:44 AM
Speaking of mwinter... were has he gone?

he hasnt posted scince the holidays...

pcbrainbuster
03-14-2007, 07:59 AM
So are you lot saying that mwinter was the best ?

pcbrainbuster
03-14-2007, 08:01 AM
One more question - is there a "dictionary" for php that lists all those functions ? eg HTTP_REMOTE_ADDR,....

Twey
03-14-2007, 08:44 AM
Speaking of mwinter... were has he gone?We're not sure... djr33 emailed him, but there was no response.
is there a "dictionary" for php that lists all those functions ? eg HTTP_REMOTE_ADDR,....They're not functions, but yes: http://www.php.net/manual/en/reserved.variables.php#reserved.variables.server.

tech_support
03-14-2007, 08:45 AM
www.PHP.net

//Oops... Posted at same time, Twey.