使用URL和变量来影响代码


Using URL With Variables to Effect Code

我想知道你是如何使用的?(问号)在你的网站,使它做不同的东西基于url中的变量。如:http://example.com/php/learn/kinder.php?level=美元水平那叫什么,怎么用?我假设用一个switch语句这是我现在的代码:

<php
$con=mysqli_connect("host","username","pass","db");
  //Check connection
 if (mysqli_connect_errno())
   {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }
$level = mysqli_query($con,"SELECT gradek FROM profiles");
?>
<html>
<head>
<title> Redirecting </title>
<meta http-equiv="refresh" content="1; url=http://teachertechtutor.com/php/learn/kinder.php?level=$level> 
</head>
<body>
</body>
</html>

然后我有一个开关…我知道这毫无意义。我只是想知道,以便将来参考。

我的问题是:如何在HTML中使用PHP变量重定向如何使用?修改代码。

我使用了bolli的代码,这是在网页上显示的内容:

`<meta http-equiv="refresh" content="1; url=http://teachertechtutor.com/php/learn/kinder.php?level2=> </head> <body> </body> </html> 

它仍然不能正确重定向

在幼儿园。php的位置:

$level = $_REQUEST['level'];
echo $level;

并阅读POST和GET请求。http://www.tizag.com/phpT/postget.php

或者你的意思是如何在URL中放置变量?

要么做

 <meta http-equiv="refresh" content="1; url=http://teachertechtutor.com/php/learn/kinder.php?level=<?php echo $level;?>> 

echo "<meta http-equiv="refresh" content="1; url=http://teachertechtutor.com/php/learn/kinder.php?level=".$level;

您是否试图获得变量并基于它切换页面内容?

你可以这样做吗?

<?php
//you could load header here
//include 'header.php';
/*
*Load content based on $_get parameter
*/
    // Get the $variable from the url after the level=
$page = (isset($_GET['level'])) ? $_GET['level'] : 'index';
//Check to see if the file exist
if (!file_exists($page . '.php'))
{
//echo "File does not exist" . $page;
}
switch ($page)
{
case 'test':
include('test.php');
break;
case 'test2':
include('test2.php');
break;
case 'test3':
include('test3.php');
break;
//Defualt start page
default:
include('index.php');
}
// You could load footer here
//include 'footer.php';
?>