简体   繁体   English

通过提交表单更改后刷新会话

[英]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. 现在,当用户从下拉菜单中选择国家时,我将国家帖子保存在SESSION ,但是当用户再次更改时,它不会更新SESSION ,并且要更新它,我们必须刷新页面以显示新的SESSION值。

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? 或者您正在使用AJAX?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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