/    Sign up×
Community /Pin to ProfileBookmark

Check if session variable is empty

I was wondering if it is possible to check if a session variable is empty and if it is, to set it to something. For example, I have a checkout form where the buyer has the option to set a separate shipping address from their billing address. I want the shipping address to be set as the billing address if they are the same. Here’s what I’ve tried, but it doesn’t seem to be working:

[code=php]
if ($_SESSION[‘shipping_address’] = ”)
{
$_SESSION[‘shipping_address’] = $_REQUEST[‘billing_address’];
}
[/code]

Is there something completely wrong with what I’m doing? Any help is always appreciated! I’m still learning, so I’m sorry if this is an obvious issue!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@DasherDec 03.2010 — You should put the code before any other code, above <!DOCTYPE

[code=php]
ob_start();
session_start();
if ($_SESSION['shipping_address'] == '')
{
$_SESSION['shipping_address'] = $_REQUEST['billing_address'];
}
ob_end_flush();
[/code]


I don't like using $_REQUEST because it can get data from multiple sources, I would specify $_POST if that is how the form is submitted.

Also the if statement needs == not =.
Copy linkTweet thisAlerts:
@UtopiaTheoryauthorDec 03.2010 — You should put the code before any other code, above <!DOCTYPE

[code=php]
ob_start();
session_start();
if ($_SESSION['shipping_address'] == '')
{
$_SESSION['shipping_address'] = $_REQUEST['billing_address'];
}
ob_end_flush();
[/code]


I don't like using $_REQUEST because it can get data from multiple sources, I would specify $_POST if that is how the form is submitted.

Also the if statement needs == not =.[/QUOTE]


Excellent...thank you so much!
×

Success!

Help @UtopiaTheory spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...