gpt4 book ai didi

php - 记住用户从一页到下一页的选择

转载 作者:行者123 更新时间:2023-12-01 22:58:18 28 4
gpt4 key购买 nike

在我的网站上,用户有多种选项,例如语言、日期和区域。当用户单击其中任何一个都很好时,网站会适应特定的选择,但是当他们转到另一个页面时,他们会失去所有选择,如果我找到一种方法在整个访问过程中保留它们,那就太好了24小时。

示例:鲍勃进入我的网站,在区域设置下,他单击“英国”,结果网站进行了调整,并向他显示了英国国旗。然而,当他进入下一页时,他失去了标志和他的区域设置,并且必须重新选择他的区域设置。

这就是我想要解决的问题。我将发布整个代码以防万一这可能有所帮助:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Loughborough University | Students Union</title>


<script type="text/javascript" src="scripts/changesheets.js"></script>
<?php include("scripts/lang_change.php"); ?>
<?php include("scripts/factoid_randomise.php"); ?>
<?php include("scripts/greeting.php"); ?>
<?php include("scripts/menu_change.php"); ?>
<?php include("scripts/lang_select.php"); ?>
<?php include("scripts/geo_loc_change.php"); ?>

<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/grey_white.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/orange_black.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/offwhite_blue.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />

<script type="text/javascript">
//Specify affected tags. Add or remove from list:
var tgs = new Array( 'div','td','tr','li','p');

//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 2;

function ts( trgt,inc ) {
if (!document.getElementById) return
var d = document,cEl = null,sz = startSz,i,j,cTags;

sz += inc;
if ( sz < 0 ) sz = 0;
if ( sz > 6 ) sz = 6;
startSz = sz;

if (!( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

cEl.style.fontSize = szs[ sz ];

for ( i = 0 ; i < tgs.length ; i++ ) {
cTags = cEl.getElementsByTagName( tgs[ i ] );
for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
}
}
</script>
</head>

<body>


<div id="wrapper">


<div id="header">



<?php


if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}

foreach ($_POST['languages'] as $language) {
switch ($language) {
case 'Japanese' :
echo "<div id='logo_japanese'></div>";
break;
case 'Chinese' :
echo "<div id='logo_chinese'></div>";
break;
default:
echo "<div id='logo'></div>";
break;
}
}
?>

<ruby style='float:right; margin-top:-80px;'>
<rb><a href="javascript:ts('body',2)"><button style='background-image:url(/misc/FYP/images/textchange.png); width:31px; height:29px; border:none; '></button></a> </rb>

<rb><a href="javascript:ts('body',-1)" ><button style='background-image:url(/misc/FYP/images/textchangeb.png); width:23px; height:29px; border:none;'></button></a></rb>
<rb><button onclick='JavaScript:changeSheets(1)' style='background-image:url(/misc/FYP/images/theme1.png); width:29px; height:29px; border:none; '></button></rb>
<rb><button onclick='JavaScript:changeSheets(2)' style='background-image:url(/misc/FYP/images/theme2.png);width:29px; height:29px;border:none;' ></button></rb>
<rb><button onclick='JavaScript:changeSheets(3)' style='background-image:url(/misc/FYP/images/theme3.png);width:29px; height:29px;border:none;' ></button></rb>
<rb><button style='background-image:url(/misc/FYP/images/Britishflag.png);width:48px; height:20px;border:none;' ></button></rb>
</ruby>

<div class='greeting'>
<?php


if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}

foreach ($_POST['languages'] as $language) {
switch ($language) {
case 'German' :
echo welcome($tz_ger,$greetings_ger);
break;case 'Korean' :
echo welcome($tz_kor,$greetings_kor);
break;case 'Russian' :
echo welcome($tz_rus,$greetings_rus);
break;
case 'Japanese' :
echo welcome($tz_jap,$greetings_jap);
break;
case 'Chinese' :
echo welcome($tz_chi,$greetings_chi);
break;
default:
echo welcome($tz_eng,$greetings_eng);
break;
}
}
?></div>
</div>


<div id="line"></div>

<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}

foreach ($_POST['languages'] as $language) {
switch ($language) {
case 'German' :
echo makeMenu($links,$tabs_ger,$title);
break;
case 'Korean' :
echo makeMenu($links,$tabs_kor,$title);
break;
case 'Russian' :
echo makeMenu($links,$tabs_rus,$title);
break;
case 'Japanese' :
echo makeMenu($links,$tabs_jap,$title);
break;
case 'Chinese' :
echo makeMenu($links,$tabs_chi,$title);
break;
default:
echo makeMenu($links,$tabs_eng,$title);
break;
}
}

?>


<div id="line"></div>
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}

foreach ($_POST['languages'] as $language) {
switch ($language) {
case 'German' :
echo changeGeoLoc($GeoLoc,$details_ger,$geoplugin);

break;case 'Korean' :
echo changeGeoLoc($GeoLoc,$details_kor,$geoplugin);

break;case 'Russian' :
echo changeGeoLoc($GeoLoc,$details_rus,$geoplugin);

break;case 'Japanese' :
echo changeGeoLoc($GeoLoc,$details_jap,$geoplugin);

break;
case 'Chinese' :
echo changeGeoLoc($GeoLoc,$details_chi,$geoplugin);

break;
default:
echo changeGeoLoc($GeoLoc,$details_eng,$geoplugin);
break;
}
}

?>
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}

foreach ($_POST['languages'] as $language) {
switch ($language) {
case 'Russian' :
echo "<div id='welcome_pic_russian'>";
break;
case 'Japanese' :
echo "<div id='welcome_pic_japanese'>";
break;
case 'Chinese' :
echo "<div id='welcome_pic_chinese'>";
break;
default:
echo "<div id='welcome_pic'>
";
break;
}
}

?>





<div id="play_feature">
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}

foreach ($_POST['languages'] as $language) {
switch ($language) {
case 'German' :
echo selectLang($h_ger,$lang_ger,$values,$h2_ger,$lang_ger2,$countries,$day,$month,$year);
break;case 'Korean' :
echo selectLang($h_kor,$lang_kor,$values,$h2_kor,$lang_kor2,$countries,$day,$month,$year);
break;
case 'Russian' :
echo selectLang($h_rus,$lang_rus,$values,$h2_rus,$lang_rus2,$countries,$day,$month,$year);
break;
case 'Japanese' :
echo selectLang($h_jap,$lang_jap,$values,$h2_jap,$lang_jap2,$countries,$day,$month,$year);
break;
case 'Chinese' :
echo selectLang($h_chi,$lang_chi,$values,$h2_chi,$lang_chi2,$countries,$day,$month,$year);
break;
default:
echo selectLang($h_eng,$lang_eng1,$values,$h2_eng,$lang_eng2,$countries,$day,$month,$year);
break;
}
}

?>




<?php
/*
@author geoPlugin (gp_support@geoplugin.com)
@copyright Copyright geoPlugin (gp_support@geoplugin.com)
*/

require_once('scripts/geoplugin.class.php');

$geoplugin = new geoPlugin();

$geoplugin->locate();

?>

<div id='menu2' style='width:250px; margin-left:-40px;'>
</div>
<div style="color:#616161; margin-left:-20px;">
<blockquote>&#8216<?php


if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}

foreach ($_POST['languages'] as $language) {
switch ($language) {
case 'German' :
echo randomFactoid($factoidsg);
break;case 'Korean' :
echo randomFactoid($factoidsk);
break;case 'Russian' :
echo randomFactoid($factoidsr);
break;case 'Japanese' :
echo randomFactoid($factoidsj);
break;
case 'Chinese' :
echo randomFactoid($factoidsc);
break;
default:
echo randomFactoid($factoids);
break;
}
}


?>&#8217</blockquote>
</div>

</font>
</div></div>

<div id="homepage_text">
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}

foreach ($_POST['languages'] as $language) {
switch ($language) {
case 'German' :
echo "<p>text</p>";
break;
case 'Korean' :
echo "<p>text.</p> ";
break;
case 'Russian' :
echo "<p>text </p>";
break;

case 'Japanese' :
echo "<p>text</p>";
break;
case 'Chinese' :
echo "<p>text</p>";
break;
default:
echo "<p>text</p>";
break;
}
}

?>



</div></div>
</div>
</body>
</html>

这在 cookie/ session 或类似的东西中可能是可行的,但我不知道如何用我编码的方式将 cookie/ session 合并到其中。

欢迎除 cookie 或 session 之外的任何其他建议。

非常感谢任何帮助。

非常重要的更新*在遵循以下建议后,我尝试了此代码:*

<?php
session_start(); //put this at the top of your script on all pages that need to remember
if(isset($_POST['languages']))
{
$_SESSION['languages'] = $_POST['languages'];
}?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Loughborough University | Students Union</title>



<script type="text/javascript" src="scripts/changesheets.js"></script>
<?php include("scripts/lang_change.php"); ?>
<?php include("scripts/factoid_randomise.php"); ?>
<?php include("scripts/greeting.php"); ?>
<?php include("scripts/menu_change.php"); ?>
<?php include("scripts/lang_select.php"); ?>
<?php include("scripts/geo_loc_change.php"); ?>

<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/grey_white.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/orange_black.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/offwhite_blue.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />

<script type="text/javascript">
//Specify affected tags. Add or remove from list:
var tgs = new Array( 'div','td','tr','li','p');

//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 2;

function ts( trgt,inc ) {
if (!document.getElementById) return
var d = document,cEl = null,sz = startSz,i,j,cTags;

sz += inc;
if ( sz < 0 ) sz = 0;
if ( sz > 6 ) sz = 6;
startSz = sz;

if (!( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

cEl.style.fontSize = szs[ sz ];

for ( i = 0 ; i < tgs.length ; i++ ) {
cTags = cEl.getElementsByTagName( tgs[ i ] );
for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
}
}
</script>
</head>

<body>

<div id="wrapper">


<div id="header">



<?php

if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}

foreach ($_SESSION['languages'] as $language) {
switch ($language) {
case 'Japanese' :
echo "<div id='logo_japanese'></div>";
break;
case 'Chinese' :
echo "<div id='logo_chinese'></div>";
break;
default:
echo "<div id='logo'></div>";
break;
}
}
?>

<ruby style='float:right; margin-top:-80px;'>
<rb><a href="javascript:ts('body',2)"><button style='background-image:url(/misc/FYP/images/textchange.png); width:31px; height:29px; border:none; '></button></a> </rb>

<rb><a href="javascript:ts('body',-1)" ><button style='background-image:url(/misc/FYP/images/textchangeb.png); width:23px; height:29px; border:none;'></button></a></rb>
<rb><button onclick='JavaScript:changeSheets(1)' style='background-image:url(/misc/FYP/images/theme1.png); width:29px; height:29px; border:none; '></button></rb>
<rb><button onclick='JavaScript:changeSheets(2)' style='background-image:url(/misc/FYP/images/theme2.png);width:29px; height:29px;border:none;' ></button></rb>
<rb><button onclick='JavaScript:changeSheets(3)' style='background-image:url(/misc/FYP/images/theme3.png);width:29px; height:29px;border:none;' ></button></rb>
<rb><button style='background-image:url(/misc/FYP/images/Britishflag.png);width:48px; height:20px;border:none;' ></button></rb>
</ruby>

<div class='greeting'>
<?php


if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}

foreach ($_SESSION['languages'] as $language) {
switch ($language) {
case 'German' :
echo welcome($tz_ger,$greetings_ger);
break;case 'Korean' :
echo welcome($tz_kor,$greetings_kor);
break;case 'Russian' :
echo welcome($tz_rus,$greetings_rus);
break;
case 'Japanese' :
echo welcome($tz_jap,$greetings_jap);
break;
case 'Chinese' :
echo welcome($tz_chi,$greetings_chi);
break;
default:
echo welcome($tz_eng,$greetings_eng);
break;
}
}
?></div>
</div>


<div id="line"></div>

<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}

foreach ($_SESSION['languages'] as $language) {
switch ($language) {
case 'German' :
echo makeMenu($links,$tabs_ger,$title);
break;
case 'Korean' :
echo makeMenu($links,$tabs_kor,$title);
break;
case 'Russian' :
echo makeMenu($links,$tabs_rus,$title);
break;
case 'Japanese' :
echo makeMenu($links,$tabs_jap,$title);
break;
case 'Chinese' :
echo makeMenu($links,$tabs_chi,$title);
break;
default:
echo makeMenu($links,$tabs_eng,$title);
break;
}
}

?>


<div id="line"></div>
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}

foreach ($_SESSION['languages'] as $language) {
switch ($language) {
case 'German' :
echo changeGeoLoc($GeoLoc,$details_ger,$geoplugin);

break;case 'Korean' :
echo changeGeoLoc($GeoLoc,$details_kor,$geoplugin);

break;case 'Russian' :
echo changeGeoLoc($GeoLoc,$details_rus,$geoplugin);

break;case 'Japanese' :
echo changeGeoLoc($GeoLoc,$details_jap,$geoplugin);

break;
case 'Chinese' :
echo changeGeoLoc($GeoLoc,$details_chi,$geoplugin);

break;
default:
echo changeGeoLoc($GeoLoc,$details_eng,$geoplugin);
break;
}
}

?>
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}

foreach ($_SESSION['languages'] as $language) {
switch ($language) {
case 'Russian' :
echo "<div id='welcome_pic_russian'>";
break;
case 'Japanese' :
echo "<div id='welcome_pic_japanese'>";
break;
case 'Chinese' :
echo "<div id='welcome_pic_chinese'>";
break;
default:
echo "<div id='welcome_pic'>
";
break;
}
}

?>





<div id="play_feature">
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}

foreach ($_SESSION['languages'] as $language) {
switch ($language) {
case 'German' :
echo selectLang($h_ger,$lang_ger,$values,$h2_ger,$lang_ger2,$countries,$day,$month,$year);
break;case 'Korean' :
echo selectLang($h_kor,$lang_kor,$values,$h2_kor,$lang_kor2,$countries,$day,$month,$year);
break;
case 'Russian' :
echo selectLang($h_rus,$lang_rus,$values,$h2_rus,$lang_rus2,$countries,$day,$month,$year);
break;
case 'Japanese' :
echo selectLang($h_jap,$lang_jap,$values,$h2_jap,$lang_jap2,$countries,$day,$month,$year);
break;
case 'Chinese' :
echo selectLang($h_chi,$lang_chi,$values,$h2_chi,$lang_chi2,$countries,$day,$month,$year);
break;
default:
echo selectLang($h_eng,$lang_eng1,$values,$h2_eng,$lang_eng2,$countries,$day,$month,$year);
break;
}
}

?>




<?php
/*
@author geoPlugin (gp_support@geoplugin.com)
@copyright Copyright geoPlugin (gp_support@geoplugin.com)
*/

require_once('scripts/geoplugin.class.php');

$geoplugin = new geoPlugin();

$geoplugin->locate();

?>

<div id='menu2' style='width:250px; margin-left:-40px;'>
</div>
<div style="color:#616161; margin-left:-20px;">
<blockquote>&#8216<?php


if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}

foreach ($_SESSION['languages'] as $language) {
switch ($language) {
case 'German' :
echo randomFactoid($factoidsg);
break;case 'Korean' :
echo randomFactoid($factoidsk);
break;case 'Russian' :
echo randomFactoid($factoidsr);
break;case 'Japanese' :
echo randomFactoid($factoidsj);
break;
case 'Chinese' :
echo randomFactoid($factoidsc);
break;
default:
echo randomFactoid($factoids);
break;
}
}


?>&#8217</blockquote>
</div>

</font>
<a href="http://s06.flagcounter.com/more/7ydE" ><img src="http://s06.flagcounter.com/count/7ydE/bg=FFFFFF/txt=000000/border=CCCCCC/columns=3/maxflags=25/viewers=Visitors/labels=0/pageviews=1/" alt="free counters" style="border:none; margin-left:15px;"/></a></div></div>

<div id="homepage_text">
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}

foreach ($_SESSION['languages'] as $language) {
switch ($language) {
case 'German' :
echo "<p> </p>";
break;
case 'Korean' :
echo "<p></p> ";
break;
case 'Russian' :
echo "<p> </p>";
break;

case 'Japanese' :
echo "<p>。</p>";
break;
case 'Chinese' :
echo "<p></p>";
break;
default:
echo "<p></p>";
break;
}
}

?>



</div></div>
</div>
</body>
</html>

这不起作用。有什么原因吗,似乎已经做了人们告诉我的一切?**

最佳答案

在这种情况下可以使用 session 。您可以在 session 变量中分配这些值,并可以在应用程序的所有页面上访问。

$_SESSION['somevar']='someval';

关于php - 记住用户从一页到下一页的选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5379798/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com