Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    May 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't get rid of errors!

    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

  • #2
    New Coder
    Join Date
    May 2003
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    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.
    cpCommerce - Finally a template based open-source e-commerce solution

  • #3
    New to the CF scene
    Join Date
    May 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't understand, if I don't use case then what replaces that?

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    New to the CF scene
    Join Date
    May 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry maybe i wasn't being clear enough.
    Last edited by cheekuon; 05-20-2004 at 03:48 PM.

  • #6
    New to the CF scene
    Join Date
    May 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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()

  • #7
    New to the CF scene
    Join Date
    May 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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");
    }

    }
    }
    ?>

  • #8
    New Coder
    Join Date
    May 2003
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    cpCommerce - Finally a template based open-source e-commerce solution

  • #9
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    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)


    PHP Code:
    <?
    $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
    PHP Code:
    <?
    $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
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •