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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    Scotland
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts

    preventing access to sub-pages

    i want to set my site up in such a way so that the only way someone can view it is by the "front door" i.e. by loading the index.php page.
    When they type in (say) 'main.php' i want main.php to reject it and divert them to the index.php page.

    index.php uses a session and loads all sub-pages by include statements. Is there a command that can detect if a session is present and allow the user to pass, but throw them out if not?
    My body's a temple... and like those ancient Greek ones it's a ruin
    sweenster.co.uk

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Something like this?

    PHP Code:
    <?php
    session_start
    ();
    if(!isset(
    $_SESSION['session_name'])){
         
    header("Location: index.php");
    }
    ?>

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    Scotland
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sort of... -ish.

    index.php has following code:

    Code:
    <?php session_start();
    if ($statnum == "0") {
    	include('../index.php');
    	die;
    }
    	include('../header.php');
    	include('../pageheader.php');
    	include('sqlconnect.php');
    	include(''.$load.'.php');
    ?>
    
    </body>
    </html>
    i only want this site to be accessed through (for example) "index.php?load=main"

    needing a line of code i can put on main.php that will detect if a session is not present (i.e. page hasn't been loaded by the index)and run index.php.

    would above code work??
    My body's a temple... and like those ancient Greek ones it's a ruin
    sweenster.co.uk


  •  

    Posting Permissions

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