0

在我的 php 页面中,出现“未定义索引类型”的错误。但是,如果使用字符串打开相同的 URL,例如 mypage.php?type=abc,则不会显示此错误!

我想重定向没有字符串的用户,即从 mypage.php 到 mypage.php?type=abc

我决定更好地纠正php!php代码如下

<?
if (($_REQUEST["type"] == "mz") || ($_REQUEST["type"] == "ie") || ($_REQUEST["type"] == "iea")) {
?>
    <link rel="SHORTCUT ICON" href="icons/<?= $_REQUEST['id'] ?>_favicon.ico" type="image/x-icon">
<?
}
?>

<?
if ($_REQUEST["type"] == "mza") {
?>
    <link rel="icon" href="icons/<?= $_REQUEST['id'] ?>_extra_animated_favicon.gif" type="image/x-icon">
<? } ?>

2行和最后一行有错误

4

3 回答 3

0

如果我理解正确,你想这样做:

window.location.href = window.location.origin + window.location.pathname + '?type=abc';

更好的是,修复您的 PHP 代码,这样您就不会在通知中收到任何警告!

于 2012-11-21T10:33:43.057 回答
0

要么更正 PHP 文件中的问题,要么添加 .htaccess 条目以直接重定向用户。

我建议在 PHP 文件中添加一些代码,如下所示:

if (!isset($_GET)) { //or you can use more specifically if (!isset($_GET['type'])) { 

//there is no get variables here so we either add a local variable or redirect (which is redundant)

$type = "abc"; //or even $_GET['type'] = "abc";

//redirect header("location: mypage.php?type=abc");

}else{

//execute work

}

更改 .htaccess 需要某些人没有的某些特权。

编辑:这样做的 javascript 方式也是可能的,但也是最滞后且不太推荐的。

针对您的更新:

您可能需要在使用 $_REQUEST['id'] 之前检查它;(您可以按照我上面介绍的方式进行操作)

if (isset($_REQUEST['id'])) {

//do your code

}
else {

//no ID here

}

也可能是您的服务器不支持短标签(<?= ?>),请尝试使用 echo 代替:

echo "<link blah blah blah=\"$_REQUEST[id]_icon.ico\" blah />";
于 2012-11-21T10:35:17.133 回答
0

检查这个

<script type="text/javascript">

function urlRD(){
if (location.href == "http://mypage.php")
window.location = "http://mypage.php?type=abc"
}

</script>

进而:

<body onLoad="urlRD()">
于 2012-11-21T10:39:01.577 回答