我有一个profile.php
页面,其中包含变量uid?=12
,我的语言栏位于名为lang.inc.php
的单独页面上:
个人资料页面:
<div class="langbar">
<?php include 'inc/lang.inc.php'; ?>
</div>
lang.inc.php
<center>
<a class="flag_USA" title="English" href="<?php echo basename($_SERVER['PHP_SELF']); ?>"><img src="css/images/us.png"></a> <span> </span>
<a class="flag_France" title="French" href="<?php echo basename($_SERVER['PHP_SELF']); ?>?lang=fr"><img src="css/images/fr.png"></a> <span> </span>
<a class="flag_dutch" title="Dutch" href="<?php echo basename($_SERVER['PHP_SELF']); ?>?lang=de"><img src="css/images/de.png"></a> <span> </span>
<a class="flag_Italy" title="Italian" href="<?php echo basename($_SERVER['PHP_SELF']); ?>?lang=it"><img src="css/images/it.png"></a> <span> </span>
<a class="flag_Italy" title="" href="<?php echo basename($_SERVER['PHP_SELF']); ?>?lang=es"><img src="css/images/sp.png"></a> <span> </span>
<?php echo $_SERVER['PHP_SELF']; ?>
</center>
正如您所见,我试图将?lang=fr
附加到profile.php?uid=12
的末尾,所以它看起来像profile.php?uid=12&lang=fr
,但它所做的只是{{} 1}}。
答案 0 :(得分:0)
我很确定$ _SERVER ['PHP_SELF']不包含get变量,只包含文件路径,所以你必须自己将uid添加到href。
答案 1 :(得分:0)
<?php
$basename = basename($_SERVER['PHP_SELF']); // Lets store the basename
$basename_with_uid = $basename . "?uid=" . $_GET['uid']; // and append the uid from the URL. Make sure to do some validation if $_GET['uid'] exists.
?>
<a class="flag_France" title="French" href="<?php echo $basename_with_uid; ?>&lang=fr"><img src="css/images/fr.png"></a>
答案 2 :(得分:0)
REQUEST_URI可能就是您的目标:
<a class="flag_France" title="French" href="<?php echo $_SERVER['REQUEST_URI']; ?>&lang=fr"><img src="css/images/fr.png"></a>
如果您的网页是profile.php?uid = 12,则输出应为:
profile.php?uid=12&lang=fr
编辑您可能仍需要在REQUEST_URI周围添加basename(),具体取决于您正在做什么