Jump to content

Isset vrs != ""


Ninjakreborn

Recommended Posts

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

[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.
Link to comment
Share on other sites

[quote]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[/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]
Link to comment
Share on other sites

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]<?php
if (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
<?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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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":
}
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

[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'
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

For you two submit buttons this will work:
[code=php:0]<?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>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.