...

View Full Version : Can't get rid of errors!



cheekuon
05-20-2004, 03:01 PM
ok, i'll get to the point.
I've made a function called page()
It connects to 2 pages.
I think the script is fine, but theres errors keep coming out.

Errors :
1. Parse error: parse error in /home/cheekuon/public_html/functions/page.php on line 22

2. Fatal error: Call to undefined function: page() in /home/cheekuon/public_html/inc/pages.php on line 85

/inc/pages.php


<?php

// Get's page() function.
include("functions/page.php");
switch ($page) {


:: Type Key ::
memberonly: Member Page
guest: Guest Page
any: Members or Guest page

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

case heroinfo4:
page("pages/incognitosinfo.php", "incognitosinfo", "any");
break;

case heroinfo4:
page("pages/barbariansinfo.php", "barbariansinfo", "any");
break;

case heroinfo4:
page("pages/earthlingsinfo.php", "earthlingsinfo", "any");
break;

default:
include("pages/home.php");
}
?>


and /functions/page


<?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;
}

}
}
?>


I hope the quote thing comes out rite..

Thx

cpradio
05-20-2004, 03:10 PM
case $title:
include("$url");
break;

case and break in the sense you are using them, only apply when using a switch() statement.

You are using an IF statement, take out those lines.

cheekuon
05-20-2004, 03:20 PM
I don't understand, if I don't use case then what replaces that? :confused:

Spookster
05-20-2004, 03:30 PM
If you don't currently understand how conditional blocks such as if/else and switch statements work I would suggest reading through a few beginners tutorials on programming in general or programming in PHP first.

You can find tutorails at www.phpfreaks.com www.zend.com and of course the PHP manual at www.php.net

cheekuon
05-20-2004, 03:43 PM
Sorry maybe i wasn't being clear enough.

cheekuon
05-20-2004, 03:51 PM
See,

<?php

// Get's page() function.
include("functions/page.php");
switch ($page) {


:: Type Key ::
memberonly: Member Page
guest: Guest Page
any: Members or Guest page

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

case heroinfo4:
page("pages/incognitosinfo.php", "incognitosinfo", "any");
break;

case heroinfo4:
page("pages/barbariansinfo.php", "barbariansinfo", "any");
break;

case heroinfo4:
page("pages/earthlingsinfo.php", "earthlingsinfo", "any");
break;

default:
include("pages/home.php");
}
?>

Thats there.
I was wondering how i can connect


case $title:
include("$url");
break;
to the page with the switch()

cheekuon
05-20-2004, 04:09 PM
After alot of changes, i managed to get this:
theres is still errors though



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

if ($page == $title) {
include("$url");

} elseif ($page == $title) {
include("pages/error.php");

}

} elseif($type == "any") {

if ($page == $title) {
include("$url");

} elseif($type == "guest") {
if(!session_is_registered("loggedin") {
if ($page == $title) {
include("$url");

} elseif ($page == $title) {
include("pages/error.php");
}

}
}
?>

cpradio
05-20-2004, 08:54 PM
okay, 1) $page is not defined in the function page() -- also, I know $page is defined in the other file, but its scope does not reach the page() function -- If you do not understand scope, you definitely need to buy a PHP book 2) From a quick glance it seems you are missing two closing }'s for your page function.

firepages
05-21-2004, 12:19 PM
OK I would suggest a change of tack .. whats to stop me typing in ... domain.com/path/protected_page.php ? nothing that I can see , unless you check again in protected_page.php in which case you are authenticaing twice (e.g twice as many chances to forget something ;))

what about .. (since your file structure is logical)




<?
$page = '/pages/'.$page.'.php' ;

if( file_exists( $page )){
include_once( $page ) ;
}else{
die('Invalid request') ;
}
?>


thats it , just that.

then in each /page/$page.php (and you need to do this anyway to be even close to `secure`)

/page/$page.php


<?
$auth_required = 'membersonly' ;
include_once('./auth.php');
?>



$auth.php would simply check your authentication status (cookie or session or whatever) based on $auth_required; then either let you continue or redirect to the appropriate login page.

& thats a fair bit of typing saved if nothing else ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum