简体   繁体   中英

Refresh SESSION after change it by submit form

I have code that get me country flag for user when select country from drop down menu like this

Submit country:

<select name="countryname" onchange="this.form.submit();fla(this);" >
    <option value="AF">Afghanistan</option>
    <option value="US">USA</option>
    <option value="UK">UK</option>
</select>

After change above we do this:

define('WCDP_PATH_INCLUDES', dirname(__FILE__) . '/inc');

if (!class_exists('GeoIP')) {
    include(WCDP_PATH_INCLUDES . "/geoip.inc");
}
$geo_data = geoip_open(WCDP_PATH_INCLUDES . "/GeoIP.dat", GEOIP_STANDARD);

$country_code = geoip_country_code_by_addr($geo_data, $_SERVER['REMOTE_ADDR']);

$countrynameselect =  $_SESSION['countryname'];

if ($countrynameselect) {
    $country_code = $countrynameselect;
} else {
    $country_code = geoip_country_code_by_addr($geo_data, $_SERVER['REMOTE_ADDR']);
}       
// Build HTML for flag icons.
?>

<img src="<? bloginfo('stylesheet_directory')?>/flags/sm/<?php echo strtolower($country_code).'.png'; ?>" border="0" style="margin-top:10px" id="flagc" />

Now when user select country from drop down menu, I save country post in SESSION , But when user change again, it does not update SESSION , and to update it, we must refresh page to show new SESSION value.

What can I do ??

You can try unset the session and set the session again when a user selects something else.

How are you setting the session? does the user click submit and then the session is set? or are you using AJAX?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM