【问题标题】:Can we have a totally new page with php when click on the new button?单击新按钮时,我们可以使用 php 获得一个全新的页面吗?
【发布时间】:2011-09-18 04:49:41
【问题描述】:

我有一个站点,我们将其命名为http://mysite.com/index.php,这是我的主要站点,包含所有信息,我想要另一个页面,类似于http://mysite.com/index.php?=premium,在这个premium 页面中,将是全新的整个页面。这意味着不同的标题或与 index.php 页面没有任何关系。

原因是我不希望我的访问者直接访问premium page,所以他们必须先访问index.php 页面,然后从那里点击。

这样可以吗?

@knittl 不确定我的问题是否已解决

但是现在实际发生了什么,上面的代码可以让我毫无问题地进入高级页面

但在高级页面中包含许多 div 类,我在高级页面中有这个

<?php
if(!isset($_GET['ch'])){ 
    $ch = 1; 
} else { 
    $ch = $_GET['ch']; 
}

if ($ch == 1) {
echo "<div class='player_live_server_info'> 

现在我有了这个会发生什么

<li><a href="tv.php?page=premium?ch=1"><img src="live_img/ch_5.jpg"></a></li>

我不知道我这样做是对还是错,但它只是重定向回正常页面。

【问题讨论】:

  • 该按钮在 index.php 中,我希望人们在转到下一页时单击以转到像 Wordpress 这样的新页面,但如果可能的话,我只希望它是全新的页面
  • 可以只为您的高级页面添加书签并在那里而不访问您的“正常”页面
  • 是的,他们可以按照我的想法这样做,但很多人不会真正想到这一点,因为我的网站是移动网站 (iPhone)
  • @knittl not if you check referer then redirect if not from http://mysite.com/index.php index.php?=premium is missing the GET parameter
  • @lawrence:引荐来源标头可能会被防火墙剥离……

标签: php web


【解决方案1】:
<?php if(isset($_GET['page']) && $_GET['page'] == 'premium') {
// this is the premium version, only visible when called as index.php?page=premium
?>

<html>
<head><title>you are on the fancy premium page</title></head>
<body>
  <h1>your premium page</h1>
</body>
</html>

<?php } else {
// this is the normal page with a link to the premium version
?>

<html>
<head><title>you are on the lame normal page</title></head>
<body>
  <h1>your normal page</h1>
  <p>
    <a href="?page=premium">click here to go to our premium page</a>
  </p>
</body>
</html>

<?php } ?>

【讨论】:

  • 还有if($_GET['page'] == 'premium' &amp;&amp; $_SERVER['HTTP_REFERER']=='http://mysite.com/index.php')
  • 我已经放置了这段代码并放置了我所有的html,但它并没有改变整体还是我误解了什么?
  • @ali:只需使用我在答案中发布的代码模板。顶部是高级页面,下部(else)是普通页面。当页面被称为index.php?page=premium 时,只有顶部(如果)将被执行。如果以任何其他方式调用,您只会看到底部(else)
  • @ali:对于多个获取参数,您必须使用&amp; 链接它们。为 html 输出转义一个锚标记将如下所示:&lt;a href="tv.php?page=premium&amp;amp;ch=1"&gt;click me&lt;/a&gt;,否则只有一个参数会传递给您的 php 脚本(取决于浏览器和 Web 服务器(配置))
【解决方案2】:

$_GET['something'] 是您的最佳选择。您也可以使用 $_SESSION,但这会很复杂,而且会使您的应用程序变慢。

【讨论】:

    猜你喜欢
    • 2014-04-10
    • 1970-01-01
    • 2015-07-05
    • 2015-01-04
    • 2015-11-19
    • 2013-10-10
    • 1970-01-01
    • 2015-03-16
    • 2016-09-26
    相关资源
    最近更新 更多