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 11 of 11
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Members Only Pages

    Right now with my CMS im working on there is a default menu with only a small selection of options in the menu, once a guest logs in then the menu expands with more options. Now of course one could get around this by just typing in the address with the name of one of the pages, so I want to know how I would go about making sure that ALL the pages/features that are for members only STAY as members only pages?

    Thanks for the help

  • #2
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Are you using database or flat files?

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts
    I am using a MySQL db.

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Any ideas how to do it if I am using a db? Id rather keep using my db if its ok to do it that way.

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Use sessions.

  • #6
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    Yeah uses sessions like Fumigator suggested.
    A simple if statement would work, but it could get tedious.
    PHP Code:
    <?php
    if(@_SESSION['loggedin'] = "yes"){
    ?>
    <a href="link">Link</a>
    <a href="link">Link</a>
    <a href="link">Link</a>
    <a href="link">Link</a>
    <?php
    echo "<a href=\Secret link\">Secret Link</a>";
    }
    ?>
    Last edited by fl00d; 08-03-2007 at 04:54 AM. Reason: [/php]

  • #7
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Well I got the script from a book and I do have something like that, so Im not sure how I would incorporate that into what I have. Here is the code I have right now.
    PHP Code:
    <?php
    //This page begins the header for the site.

    //start output buffering and initialize a session
    ob_start();
    session_start();

    //Check for a $page_title value
    if (!isset($page_title)) {
        
    $page_title 'Twincitieshotspot.com Account Editor v1.0';
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title><?php echo $page_title?></title>
    <link href="style.css" rel="stylesheet" type="text/css">
    </head>

    <body>

    <table width="60%" border="0" cellspacing="10" cellpadding="0" align="center">

    <tr>
        <td colspan="2" bgcolor="#003366"><p class="title">Content Management System</p></td>
    </tr>

    <tr>
        <td valign="top" nowrap="nowrap">
    <b><a href="index.php" class="navlink">Home</a><br />
    <a href="../index.php" class="navlink">Main Site</a><br />
    <?php
    //This page ends the header for the site.

    //Display links based upon the login staus.
    if (isset($_SESSION['user_id']) AND
    (
    substr($_SERVER['PHP_SELF'], -10) !='logout.php')) {
        echo 
    '<b><a href="logout.php" class="navlink">Logout</a><br />
        <a href="change_password.php" class="navlink">Change Password</a><br />
        <a href="add_urls.php" class="navlink">Add URLs</a><br />
        <a href="view_urls.php" class="navlink">View URLs</a><br />
        <a href="add_files.php" class="navlink">Add Files</a><br />
        <a href="view_files.php" class="navlink">View Files</a><br />
        <a href="#" class="navlink">Upload Music</a><br />
        <a href="#" class="navlink">Upload Video</a><br />
        <a href="edit_content.php" class="navlink">Edit Content</a><br />
        <a href="form.php" class="navlink">Manage Images</a><br />'
    ;
    } else {
        echo 
    '<a href="register.php" class="navlink">Register</a><br />
        <a href="login.php" class="navlink">Login</a><br />
        <a href="forgot_password.php" class="navlink">Forgot Password</a><br /></b>'
    ;
    }
    ?>
            <b><a href="#" class="navlink"></a><br />
            <a href="#" class="navlink"></a><br /></b>
        </td>
        
        <td valign="top" class="content">
    <!-- Script 11.1 - header.php -->
    Thanks a lot for your help

  • #8
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts
    any ideas on this one? Thanks for the help again.

  • #9
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    It says right here...just add stuff to it if thats what you're using...
    PHP Code:
    //Display links based upon the login staus.
    if (isset($_SESSION['user_id']) AND
    (
    substr($_SERVER['PHP_SELF'], -10) !='logout.php')) {
        echo 
    '<b><a href="logout.php" class="navlink">Logout</a><br />
        <a href="change_password.php" class="navlink">Change Password</a><br />
        <a href="add_urls.php" class="navlink">Add URLs</a><br />
        <a href="view_urls.php" class="navlink">View URLs</a><br />
        <a href="add_files.php" class="navlink">Add Files</a><br />
        <a href="view_files.php" class="navlink">View Files</a><br />
        <a href="#" class="navlink">Upload Music</a><br />
        <a href="#" class="navlink">Upload Video</a><br />
        <a href="edit_content.php" class="navlink">Edit Content</a><br />
        <a href="form.php" class="navlink">Manage Images</a><br />'
    ;
    } else {
        echo 
    '<a href="register.php" class="navlink">Register</a><br />
        <a href="login.php" class="navlink">Login</a><br />
        <a href="forgot_password.php" class="navlink">Forgot Password</a><br /></b>'
    ;


  • #10
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts
    well maybe im getting the results I am because im running it locally. See the deal is that if I bring up say for instance the index.php for this and dont login but type in a file that SHOULD be secured such as "add_files.php" and ht enter..it will bring the page up without me logging in. Incase this isnt clear...if I have this in my address bar...
    http://localhost/viewable/hsrevised/cms/index.php
    and change it to...
    http://localhost/viewable/hsrevised/cms/add_files.php
    without logging in, the page will be displayed and allow me to add files.

    Would it behave this way because I am running everything locally or is there something else going on?

    Thanks

  • #11
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    Thats because the page isn't protected. Assign a session at login, and check if it exists for that page. To do so you would add something like this to the top of the page:

    addfiles.php
    PHP Code:
    if($_SESSION['member'] != "member"){
      
    header("Location: login.php");
    }
    <
    html>
    blah blah
    </html
    Obviously the session names(member) and value(member) are examples, and can be changed to whatever you would like.


  •  

    Posting Permissions

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