开发者

Working with $_GET[page_id]

开发者 https://www.devze.com 2023-02-04 01:13 出处:网络
Okay, this might be a basic question. Here is my code: <?php $pageid = $_GET[page_id]; ?> And then:

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. Now what I want to do is that I want to add index.php as one of those pages. But index.php does not have a page id. So I want <?php if($pa开发者_如何学Cgeid == '2' OR $pageid == '9' OR index.php) { echo... How the heck do I do that? Just placing the filename wont work obviously.


If index.php has no pageid, then simply put your if() to...

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


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


I would start your script with

 $pageid = false;

Then in your if statement you ca do

 <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!


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

Then $pageid would contain either the page_id or 'index' if it wasn't supplied.


I would say:

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

so you're always working with page ids, even when one isn't supplied.


You can check if they are on the index by using the base URI. So do this:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消