Jump to content


Photo

Isset vrs != ""


  • Please log in to reply
26 replies to this topic

#1 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 17 July 2006 - 01:12 PM

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 access
It 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 this
if (isset($emailaddress)) and it didn't work I changed it to $emailaddress != ""
and it worked
but then I don't understnad this
when I build a newsletter

if (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

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 />";
}

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 17 July 2006 - 01:30 PM

I tried with my form at first like this
if (isset($emailaddress)) and it didn't work I changed it to $emailaddress != ""
and it worked
but then I don't understnad this
when I build a newsletter

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:
if(empty($var))
{
    echo 'var is empty!';
}


#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 July 2006 - 01:32 PM

isset tests to see if a variable has been set, not weather or not it contains a value. I think your looking for empty.

#4 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 17 July 2006 - 01:46 PM

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
<?php
if (isset($subscribe)) {

// work here

}

if (isset($unsubscribe)) {
// work here
}
?>

This is the exact same thing I am doing on this.

<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>



Then over on the page I have it sort of like password protected, just limited access
<?php
if (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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 July 2006 - 01:47 PM

It is to make sure the variable your trying to use exists before you actually try to use it.

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 17 July 2006 - 01:48 PM

I told you isset checks whether the variable acually exists.

EDIT: Thorpe beat me.. :(

#7 ChaosXero

ChaosXero
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 17 July 2006 - 01:48 PM

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.

#8 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 17 July 2006 - 01:52 PM

I think I need to rethink how I am processing my newsletters just in case, this is somewhat disturbing.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#9 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 17 July 2006 - 01:54 PM

The variables should be sent regardless, except for checkboxes which seem to not send anything if they are not true.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#10 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 July 2006 - 01:56 PM

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":
}

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#11 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 17 July 2006 - 01:58 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#12 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 July 2006 - 01:59 PM

This...

$name=" ";

if isset($name) {

echo " hello";

}else {

echo "sorry the varable $\name is not set":
}

Will echo "hello", because $name IS set.

#13 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 July 2006 - 02:02 PM

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":
}

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#14 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 July 2006 - 02:02 PM

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.


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.

#15 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 17 July 2006 - 02:03 PM

Redarrow
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:
if(!isset($name))
{
  echo "name is not set";
}
Then you'll get 'name isset'

#16 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 July 2006 - 02:03 PM

Was name set above becouse the double quotes had a gap meaning set to a space.

No... even setting it to an empty string, eg; $name = "" , still instantiates the variable.

#17 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 17 July 2006 - 02:05 PM

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?

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#18 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 July 2006 - 02:06 PM

$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............

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#19 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 July 2006 - 02:07 PM

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';
}


#20 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 17 July 2006 - 02:08 PM

For you two submit buttons this will work:
<?php

if(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>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users