Page 1 of 1

Function Help!

Posted: Wed May 12, 2004 12:20 pm
by William
I made a function called: page(), It's not working. Here is the function script:

Code: Select all

<?php

function page($url, $title, $type)
{
	if($type == "memberonly") {
		if(session_is_registered("loggedin") && $page != "logout") {

			case $title:
			include("$url");
			break;

		} else {

			case $title:
			include("pages/error.php");
			break;

		}

	} elseif($type == "any") {
	
	case $title:
	include("$url");
	break;

	} elseif($type == "guest") {
		if(!session_is_registered("loggedin") {
			case $title:
			include("$url");
			break;
		} else {
			case $title:
			include("pages/error.php");
			break;
		}

	}
}
?>
And here is the use of the function:

Code: Select all

<?php

include("functions/page.php");

switch ($page) {

page("pages/attackresult.php", "attackresult", "memberonly");

page("pages/register.php", "register", "guest");

page("pages/aboutus.php", "aboutus", "any");

page("pages/profile.php", "profile", "memberonly");

page("pages/research.php", "research", "memberonly");

page("pages/topexp.php", "topexp", "any");

page("pages/topgold.php", "topgold", "any");

page("pages/top10002.php", "top10002", "any");

page("pages/mcc.php", "mcc", "memberonly");

page("pages/inbox.php", "inbox", "memberonly");

page("pages/sendmessage.php", "sendmessage", "memberonly");

page("pages/clan.php", "clan", "memberonly");

page("pages/shop1.php", "shop1", "memberonly");

page("pages/shop2.php", "shop2", "memberonly");

page("pages/shop3.php", "shop3", "memberonly");

page("pages/shop4.php", "shop4", "memberonly");

page("pages/minegold.php", "minegold", "memberonly");

page("pages/help.php", "help", "any");

page("pages/top1000.php", "top1000", "any");

page("pages/news.php", "news", "any");

page("pages/login.php", "login", "guest");

page("pages/gold.php", "gold", "memberonly");

page("pages/rank.php", "rank", "any");

page("pages/attack.php", "attack", "memberonly");

page("pages/logout.php", "logout", "memberonly");

page("pages/shop.php", "shop", "memberonly");

page("pages/info.php", "info", "any");

page("pages/heroinfo1.php", "heroinfo1", "any");

page("pages/lightinfo.php", "lightinfo", "any");

page("pages/darkinfo.php", "darkinfo", "any");

page("pages/heroinfo2.php", "heroinfo2", "any");

page("pages/heroinfo3.php", "heroinfo3", "any");

page("pages/heroinfo4.php", "heroinfo4", "any");

page("pages/raidersinfo.php", "raidersinfo", "any");

page("pages/incognitosinfo.php", "incognitosinfo", "any");

page("pages/barbariansinfo.php", "barbariansinfo", "any");

page("pages/earthlingsinfo.php", "earthlingsinfo", "any");

default:
	include("pages/home.php");
}
?>
it keeps saying: Parse error: parse error, expecting `T_CASE' or `T_DEFAULT' or `'}'' in /home/cheekuon/public_html/inc/pages.php on line 16

Any ideas?

Posted: Wed May 12, 2004 12:49 pm
by magicrobotmonkey
Umm I don't think that will do what you think it wil. I can see what you're trying to do, but its not quite right. I think you would have to return the

case $title:
include("$url");
break;

as a string then eval it

Posted: Wed May 12, 2004 2:03 pm
by William
huh?

Posted: Wed May 12, 2004 2:05 pm
by patrikG
[php_man]switch[/php_man]

Posted: Wed May 12, 2004 2:36 pm
by William
I know switch. It worked fine till I add my new function.

Posted: Wed May 12, 2004 2:39 pm
by Weirdan
You need to have your swith inside the function. (or your cases outside of it)

Posted: Wed May 12, 2004 2:59 pm
by launchcode
Apart from the fact your case statements are totally invalid because they're not inside a switch block, as Weirdan has pointed out, why are you even bothering with them? I can't see any reason for them - why not just pass in the file name of the page to include? That is in the first script - in the second script you're missing your case statements totally!

Posted: Mon May 17, 2004 10:40 pm
by William
Ok, Case is ourside. The function should be prining the case thing. The function checks if the user is loggin. if it is set memberonly. Not to check if it is any. And checks if your not loggin if its guest. Now do you understand?

Posted: Tue May 18, 2004 12:27 am
by jason
The Hidden Viper wrote:Ok, Case is ourside. The function should be prining the case thing. The function checks if the user is loggin. if it is set memberonly. Not to check if it is any. And checks if your not loggin if its guest. Now do you understand?
No. That's wrong.

Your switch is wrong. It doesn't have any case. You can't have your case sitting inside a function. It won't work.

Your case statements need to be inside the switch, not inside functions.

Read: http://www.php.net/switch

Then continue/

Posted: Tue May 18, 2004 1:43 pm
by William
o, lol, So I got to add function inside the case. Dang going to make it longer. :-|, k thx