Welcome to Geeklog, Anonymous Sunday, December 22 2024 @ 09:29 am EST

Geeklog Forums

Welcome committee PHP code


Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Hi!

Let's say I use a PHP code in header.thtml or index.php, but I only want the code to run if the visitor has just entered the site (i.e. he's in the root folder and not in a specific PHP file).

How do I get those files to recognize which page they are "loaded inside of"? Do they see it as a referrer or something?

What I want is basically

if ("run inside root") {
code goes here...
}
?>
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
You could always use $PHP_SELF to see what the current file is. There's also some ugly code to be found in lib-common.php that determines whether we're currently on the front page or not (for the "frontpage only" blocks).

bye, Dirk
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Well, Dirk sure threw me in the jungle, but I made it!
You see, "$PHP_SELF" doesn't work. The var "$HTTP_SERVER_VARS['SCRIPT_NAME']", which lib-common.php used, doesn't work either.

But instead I used a var called $_SERVER['REQUEST_URI'] .

[quote - somewhere inside header.thtml]
<?php
preg_match( "/\/\/[^\/]*(.*)/", $_CONF['site_url'], $pathonly );
if ($_SERVER['REQUEST_URI'] == $pathonly[1] . "/&quotWink
{
code goes here...
}
?>
[/quote]
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Well, I've changed my mind. Instead of testing if the location is root every time someone loads ANY page (because header.thtml is ALWAYS loaded) AND dealing with individual themes, I've decided to include it inside the global index.php instead.

Just be sure to put it after COM_siteHeader() so it won't push the entire page down and just show up above the first article. I've put it just above the line "$maxstories = 0".
[quote - inside index.php]
COM_siteHeader();
.
.
.
The aforementioned code goes here...
.
.
.
$maxstories = 0
[/quote]
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Hmm, turns out that if one uses the Static Pages plugin and chooses "Homepage Only", then it does the check itself. In other words, whatever code you write there will ONLY show up on index.php.
Not even in index.php?page=x, but just in index.php itself!

Sure, my version didn't even show up in index.php, but only in "/" (which is more appropriate for a welcome message), but I guess it's more compatible this way for future geeklog upgrades.

Just remember you must enable php code in Static Pages first.
 Quote

All times are EST. The time is now 09:29 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content