下面这段代码中switch($_GET['ref'])是什么意思?$_GET['ref']又是什么意思?if($_POST['submit']){//当用户点击了本页面的提交按钮
$sql="select * from users where username = '" . $_POST['username'] . "' and password = '" . $_POST['password'] . "';";
mysql_query("set names utf8;");
$result=mysql_query($sql);
$numrows=mysql_num_rows($result);
mysql_query("set names utf8;");
$result=mysql_query($sql);
$numrows=mysql_num_rows($result);
if($numrows ==1){
$row = mysql_fetch_assoc($result);
session_register("USERNAME");
session_register("USERID");
$_SESSION['USERNAME'] = $row['username'];
$_SESSION['USERID']= $row['id'];//现在进行任何必要的重定向 ,需要用户登录的页面会重定向到登录页面,登录之后应该再重定向回原来的页面
//用户试图发表新帖,登录之后应当跳到newtopic.php ; 用户试图回复帖子,登录之后跳转到reply.php
switch($_GET['ref']){
case "newpost":
if(isset($_GET['id'])==false){
header("Location: " .$config_basedir . "/newtopic.php");
}
else {
header("Location: " . $config_basedir . "/newtopic.php?id=" . $_GET['id']);
}
break;
case "reply":
if(isset($_GET['id'])==false){
header("Location: " . $config_basedir . "/newtopic.php");
}
else{
header("Location: " . $config_basedir . "/newtopic.php?id=" . $_GET['id']);
}
break;
default;
header("Location: " . $config_basedir . "/forum_index.php");
break;
}
}//if($numrow==1)else{
header("Location: " . $config_basedir . "/forum_login.php?error=1");
}
}
$sql="select * from users where username = '" . $_POST['username'] . "' and password = '" . $_POST['password'] . "';";
mysql_query("set names utf8;");
$result=mysql_query($sql);
$numrows=mysql_num_rows($result);
mysql_query("set names utf8;");
$result=mysql_query($sql);
$numrows=mysql_num_rows($result);
if($numrows ==1){
$row = mysql_fetch_assoc($result);
session_register("USERNAME");
session_register("USERID");
$_SESSION['USERNAME'] = $row['username'];
$_SESSION['USERID']= $row['id'];//现在进行任何必要的重定向 ,需要用户登录的页面会重定向到登录页面,登录之后应该再重定向回原来的页面
//用户试图发表新帖,登录之后应当跳到newtopic.php ; 用户试图回复帖子,登录之后跳转到reply.php
switch($_GET['ref']){
case "newpost":
if(isset($_GET['id'])==false){
header("Location: " .$config_basedir . "/newtopic.php");
}
else {
header("Location: " . $config_basedir . "/newtopic.php?id=" . $_GET['id']);
}
break;
case "reply":
if(isset($_GET['id'])==false){
header("Location: " . $config_basedir . "/newtopic.php");
}
else{
header("Location: " . $config_basedir . "/newtopic.php?id=" . $_GET['id']);
}
break;
default;
header("Location: " . $config_basedir . "/forum_index.php");
break;
}
}//if($numrow==1)else{
header("Location: " . $config_basedir . "/forum_login.php?error=1");
}
}
if(isset($_GET['id'])==false){
header("Location: " .$config_basedir . "/newtopic.php");
}如果 $_GET['ref'] 值是 newpost,就执行下面的语句
if(isset($_GET['id'])==false){
header("Location: " .$config_basedir . "/newtopic.php");
作用跟if elseif一样
GET, POST这两个是提交表单的两种方法。
$_GET['ref'] , $_POST['submit']这两个里面是传来的值
case "newpost":
if(isset($_GET['id'])==false){
header("Location: " .$config_basedir . "/newtopic.php");
}
else {
header("Location: " . $config_basedir . "/newtopic.php?id=" . $_GET['id']);
}
break;这一段代码表示当$_GET['ref'] 的值为"newpost"时,执行break前的那段代码;
$_GET['ref']表示获取表单传递过来的值,这个表单的method属性的值为get,如果method属性的值为post,则可以通过$_POST['name']来获取