简体   繁体   English

使用$ _GET [page_id]

[英]Working with $_GET[page_id]

Okay, this might be a basic question. 好的,这可能是一个基本问题。 Here is my code: 这是我的代码:

<?php $pageid = $_GET[page_id]; ?>

And then: 接着:

<a href="" <?php if($pageid == '2' OR $pageid == '9') { echo...

So this makes it so that if they are on page ID 2 or 9, then it will echo a message. 所以这使它如果它们在页面ID 2或9上,那么它将回显一条消息。 Now what I want to do is that I want to add index.php as one of those pages. 现在我想要做的是我想将index.php添加为其中一个页面。 But index.php does not have a page id. 但是index.php没有页面ID。 So I want <?php if($pageid == '2' OR $pageid == '9' OR index.php) { echo... How the heck do I do that? 所以我想<?php if($pageid == '2' OR $pageid == '9' OR index.php) { echo...我该怎么做? Just placing the filename wont work obviously. 只是放置文件名不会明显工作。

if($pageid == '2' || $pageid == '9' || __FILE__ == 'index.php')

如果index.php没有pageid ,那么只需将你的if()放到......

<?php if($pageid == '2' || $pageid == '9' || !isset($_GET['page_id'])) { echo...

I would start your script with 我会用你的脚本开始

 $pageid = false;

Then in your if statement you ca do 然后在你的if语句中你可以做

 <a href="" <?php if($pageid == '2' OR $pageid == '9' OR !$pageid) { echo...

That way if you never set pageid (aka index.php) then you are set in your if statement! 这样,如果您从未设置pageid(也就是index.php),那么您将在if语句中设置!

<?php $pageid = (isset($_GET[page_id]) ? $_GET[page_id] : 'index'); ?>

然后$ pageid将包含page_id或'index'(如果未提供)。

I would say: 我会说:

if (!isset($_GET['page_id']) {
    $pageid = 0;
}

so you're always working with page ids, even when one isn't supplied. 所以你总是使用页面ID,即使没有提供。

You can check if they are on the index by using the base URI. 您可以使用基URI检查它们是否在索引上。 So do this: 这样做:

if($pageid == '2' || $pageid == '9' || $_SERVER['REQUEST_URI']=='/') if($ pageid =='2'|| $ pageid =='9'|| $ _SERVER ['REQUEST_URI'] =='/')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM