[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

showing where users are

im trying to show where users are on my forum.. just like this

*   PHP Freaks Forums > * PHP Coding >  * PHP Help >  * Start new topic

and i want it to be in just 1 file... so far i have this

<a href="http://www.runningprofiles.com/members/index.php?page=mainforums">runningprofiles forums</a> > <?php echo $forum; ?> > topic

with the topic i only want the link to show if they are on certain pages in my website.. so here are a few following examples

index.php?page=message
index.php?page=post
index.php?page=reply

could i make an if statement to somehow check if the user is viewing that page
0
runnerjp
Asked:
runnerjp
  • 3
  • 2
1 Solution
 
Roger BaklundCommented:
I'm not sure if I understand, but something like this:

$page = $_REQUEST['page'];
$forumpages = array('message','post','reply');
if(in_array($page,$forumpages))
  $forum = '<a href="/members/index.php?page='.$page.'">'.$page.'</a>';
else $forum = '';

...and then use the $forum variable like in your example above.
0
 
runnerjpAuthor Commented:
ok i did something like this..

<?php
$show = array('message','post','reply');
if(in_array($_GET['page'],$show)) {
    echo 'foo';
}
?>

but cant i do something like

if($_GET['page']= post) {
    echo 'foo';
}
elseif($_GET['page']= message) {
    echo 'bar';
}
0
 
Roger BaklundCommented:
Yes... but you must use quotes and double ==:

if($_GET['page'] == 'post')

What about this:
$show = array(
  'message' => 'bar',
  'post' => 'foo',
  'reply' => 'foobar'
);
if(in_array($_GET['page'],array_keys($show))) {
  echo $show[ $_GET['page'] ];
}

Open in new window

0
 
runnerjpAuthor Commented:
that works great... could i add something like  'message' => '$messageid'

so that the message title would come up?


0
 
Roger BaklundCommented:
Yes, but then you would NOT use the single quotes, because $messageid is a variable: 'message' => $messageid

This only works if the $messageid variable contains the title... :)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now