Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Post Installation Help
Author Message
Caedus
Hangin' Around


Joined: Jun 21, 2004
Posts: 39
Location: The Netherlands

PostPosted: Mon Oct 02, 2006 5:16 am Reply with quote

I'm trying to get a block to display content, dependant on which module a visitor is checking. I came up with this block code, but it doesn't seem to work:

Code:
<?php


if (eregi("block-Test.php", $_SERVER['PHP_SELF'])) {
    Header("Location: index.php");
    die();
}

global $prefix, $db, $admin, $module_name;

if($module_name == "News"){
$content = "A";
}
else {$content = "B";}
   
?>


I suspect it's the 'module_name' variable, but as I am a noob, I've no clue how to get it to work. The above is simple copy/pasting from other sources of code I studied.

Could someone please help me?

_________________
Arrow Caedus
RavensScripts 
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Caedus
PostPosted: Mon Oct 02, 2006 6:02 am Reply with quote

As with every solution: it's so simple if you know it.

The code I used was correct. It even recognised the module name as a variable. But the thing is: I mistyped the name of the module in my test block (I used a capital letter instead of lower cases --> the directory that gives the module it's proper name only uses lower case).

I rewrote it a bit. If someone wants to use it, feel free:

Code:
<?php


if (eregi("block-Test.php", $_SERVER['PHP_SELF'])) {
    Header("Location: index.php");
    die();
}

global $prefix, $db, $admin, $block, $module_name;

if ($module_name == "Whatever") {
$block = "A";
} else {
   $block = "B";
   }

$content = $block;
   
?>


So, to be clear: you don't have to change anything in the modules themselves.
 
montego
Site Admin


Joined: Aug 29, 2004
Posts: 9453
Location: Arizona

PostPosted: Mon Oct 02, 2006 6:16 am Reply with quote

Quote:

the directory that gives the module it's proper name only uses lower case


Are you certain about that? Are you, by chance, running/testing this only on a windows based server? I would think that a *nix environment would report back a case sensitive modules directory.

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
Caedus
PostPosted: Mon Oct 02, 2006 6:32 am Reply with quote

You misunderstand. The server reports are case sensitive. That's why it went wrong. I typed in 'RandoM' name in stead of 'Random'. I did so because the official title is RandoM.
 
montego
PostPosted: Mon Oct 02, 2006 6:55 am Reply with quote

$module_name is obtained strictly from the exact directory name for the module. It is usually this line of code here in the module index.php script:

$module_name = basename(dirname(__FILE__));

So, however that directory is named, that is what is used by $module_name.

I am elaborating on this for the benefit of others who each this thread as they may not understand what you mean by "official title".
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Post Installation Help

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©