Ninjakreborn Posted July 17, 2006 Share Posted July 17, 2006 I was told this wasn't affective, I didn't believe but I think I was shown first hand.I was writing up some scripts, I wanted someone to have to enter an email address before gaining accessIt is for a client that has yahoo server, and there php ini settings are aweful, register globals is on for one, a nother you can't see your errors, and unless you can log into there account you can't even see the error logs, it's a nightmare working with yahoo, anyway, I also had to cuss them out on the phone 2 times, for not giving proper tech support, for like 3 different clients, enough rambling, well I set up a gateway page, it was easier for me to keep up with, with yahoo server, I co uldn't debug when using a form on the same page, so I put it in another page, an dran all the link access through that.I tried with my form at first like thisif (isset($emailaddress)) and it didn't work I changed it to $emailaddress != ""and it workedbut then I don't understnad thiswhen I build a newsletterif (isset(subscribe))if (isset(unsubscribe))that is how I always differentiate my 2 scripts and I do them on the same page, any one got any wisdow to shed on this subject.By the way[code]if(!(getmxrr(substr(strstr($_POST['email'], '@'), 1), $temp)) || checkdnsrr(gethostbyname(substr(strstr($_POST['email'], '@'), 1)), "ANY")) { $errorhandler .= "The Domain name for the email address does not exist<br />";}[/code]This tests the email address to 100% make sure the dns server exists. It doesn't say whether the email is valid but it's checks to make sure the domain name exists atleast, another thing to help decrease the chance of bad emails. Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/ Share on other sites More sharing options...
wildteen88 Posted July 17, 2006 Share Posted July 17, 2006 [quote]I tried with my form at first like thisif (isset($emailaddress)) and it didn't work I changed it to $emailaddress != ""and it workedbut then I don't understnad thiswhen I build a newsletter[/quote]That becuase isset doest not check the value of the variable, but it checks for the existance of the variable. If you want to check whether variable is empty use th empty function like so:[code=php:0]if(empty($var)){ echo 'var is empty!';}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59328 Share on other sites More sharing options...
trq Posted July 17, 2006 Share Posted July 17, 2006 isset tests to see if a variable has been set, not weather or not it contains a value. I think your looking for [url=http://php.net/empty]empty[/url]. Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59329 Share on other sites More sharing options...
Ninjakreborn Posted July 17, 2006 Author Share Posted July 17, 2006 So what is the use of isset.This is the same situation, for instance, when I do a newsletter<form name="newslettertest" action="newsletterpage.php" method="post"><label for="emailaddress">Email Address:</label><input name="emailaddress" id="emailaddress" type="text" maxlength="80" /><label for="verifyemail">Verify Email Address:</label><input name="verifyemail" id="verifyemail" type="text" maxlength="80" /><input name="subscribe" id="subscribe" type="submit" value="SubScribe" /><input name="unsubscribe" id="unsubscribe" type="submit" value="UnSubscribe" /></form>Processor down here[code]<?phpif (isset($subscribe)) {// work here}if (isset($unsubscribe)) {// work here}?>[/code]This is the exact same thing I am doing on this.[code]<form name="logemail" action="logpage" method="post"><label for="emailaddress">Email Address:</label><input name="emailaddress" id="emailaddress" type="text" maxlength="80" /><input name="submit" id="submit" type="submit" value="Gain Access!" /></form>[/code]Then over on the page I have it sort of like password protected, just limited access<?phpif (isset($emailaddress)) {?>//show entire page here<?php} else {echo "You suck put in your email";}?>It's the exact same idea, when I do the newsletter this works perfectly, when I do it here it doesn't. Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59338 Share on other sites More sharing options...
trq Posted July 17, 2006 Share Posted July 17, 2006 It is to make sure the variable your trying to use exists before you actually try to use it. Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59339 Share on other sites More sharing options...
wildteen88 Posted July 17, 2006 Share Posted July 17, 2006 I told you isset checks whether the variable acually exists.EDIT: Thorpe beat me.. :( Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59340 Share on other sites More sharing options...
ChaosXero Posted July 17, 2006 Share Posted July 17, 2006 I believe this is because when you have a post variable like that, it isn't initialized even if it has no value (i.e. user inputs nothing, no post variable initialized) which would make isset false.Just my guess. I use a similar thing on my site. Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59341 Share on other sites More sharing options...
Ninjakreborn Posted July 17, 2006 Author Share Posted July 17, 2006 I think I need to rethink how I am processing my newsletters just in case, this is somewhat disturbing. Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59348 Share on other sites More sharing options...
ShogunWarrior Posted July 17, 2006 Share Posted July 17, 2006 The variables should be sent regardless, except for checkboxes which seem to not send anything if they are not true. Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59351 Share on other sites More sharing options...
redarrow Posted July 17, 2006 Share Posted July 17, 2006 if (empty($emailaddress)) {?>//show entire page here<?php} else {echo "You suck put in your email";}?>isset only lets the code know theres a varable set to it.for example$name="redarrow";if isset($name) {echo " hello";}In this example the $name is set becouse the varable $name is redarrow.but if name has not been set like below and has no setting to the varable the echoed message comes up ok.$name=" ";if isset($name) {echo " hello";}else {echo "sorry the varable $\name is not set":} Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59354 Share on other sites More sharing options...
Ninjakreborn Posted July 17, 2006 Author Share Posted July 17, 2006 ah I see what you mean, so it would be useful then in this situation. for like submit buttons. Because if there clicked they are set, if they are not theya re empty. Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59356 Share on other sites More sharing options...
trq Posted July 17, 2006 Share Posted July 17, 2006 This...[code=php:0]$name=" ";if isset($name) {echo " hello";}else {echo "sorry the varable $\name is not set":}[/code]Will echo "hello", because $name IS set. Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59358 Share on other sites More sharing options...
redarrow Posted July 17, 2006 Share Posted July 17, 2006 Was name set above becouse the double quotes had a gap meaning set to a space.$name="";if isset($name) {echo " hello";}else {echo "sorry the varable $\name is not set":} Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59361 Share on other sites More sharing options...
trq Posted July 17, 2006 Share Posted July 17, 2006 [quote]ah I see what you mean, so it would be useful then in this situation. for like submit buttons. Because if there clicked they are set, if they are not theya re empty.[/quote]I would never rely on a submit button being sent. Different browsers hadnle them differently. As for your comment, your still off track. If the variable is not set it wont exist. Not existing and being empty are different things. Something has to exist to be empty. Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59362 Share on other sites More sharing options...
wildteen88 Posted July 17, 2006 Share Posted July 17, 2006 [b]Redarrow[/b]The following will make $name set:$name;$name='';$name=null;$name=" ";As you are creating that variable with a value. if you didnt make the variable and just had:[code=php:0]if(!isset($name)){ echo "name is not set";}[/code]Then you'll get 'name isset' Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59363 Share on other sites More sharing options...
trq Posted July 17, 2006 Share Posted July 17, 2006 [quote]Was name set above becouse the double quotes had a gap meaning set to a space.[/quote]No... even setting it to an empty string, eg; $name = "" , still instantiates the variable. Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59365 Share on other sites More sharing options...
Ninjakreborn Posted July 17, 2006 Author Share Posted July 17, 2006 Then does anyone have any small example code, or a test example, of any possible situation where isset can be effectively used in programming without taking any risks? Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59366 Share on other sites More sharing options...
redarrow Posted July 17, 2006 Share Posted July 17, 2006 $name=" ";unset($name);if isset($name) {echo " hello";}else {echo "sorry the varable $\name is not set":}so do you not have $name there then or use unset like above.thank you intreasting not in books lol............ Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59367 Share on other sites More sharing options...
trq Posted July 17, 2006 Share Posted July 17, 2006 [code=php:0]if (isset($var)) { echo "now I can safely use $var without fear of error because it exists";} else { echo 'the variable $var does not exist, therefore trying to use it will produce a warning';}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59370 Share on other sites More sharing options...
wildteen88 Posted July 17, 2006 Share Posted July 17, 2006 For you two submit buttons this will work:[code=php:0]<?phpif(isset($_POST['button1'])){ echo "You have clicked button1";}else if(isset($_POST['button2'])){ echo "You have clicked button2";}?><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="submit" name="button1" value="Button 1" /> <input type="submit" name="button2" value="Button 2" /></form>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59372 Share on other sites More sharing options...
redarrow Posted July 17, 2006 Share Posted July 17, 2006 So in esence the isset let's php know that there's a varable in a code and should be set. Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59377 Share on other sites More sharing options...
wildteen88 Posted July 17, 2006 Share Posted July 17, 2006 Yes isset checks whether the variable your are refering to exists. Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59380 Share on other sites More sharing options...
redarrow Posted July 17, 2006 Share Posted July 17, 2006 thank you wildteen88i want also to know if you use the unset($name);will this unset a isset cheers. Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59388 Share on other sites More sharing options...
wildteen88 Posted July 17, 2006 Share Posted July 17, 2006 If you use unset then isset will return false, meaning the variable is non-existant. Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59391 Share on other sites More sharing options...
redarrow Posted July 17, 2006 Share Posted July 17, 2006 Thank you wildteen88 and others for your examples and explination's cheers mate's.sorry businessman to but in, but cheers. Quote Link to comment https://forums.phpfreaks.com/topic/14841-isset-vrs/#findComment-59395 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.