Simple PHP question

Discussion in 'Web Design and Development (archive)' started by pepeleuepe, Jan 26, 2004.

  1. macrumors 6502

    Joined:
    Oct 27, 2002
    Location:
    Los Angeles, California
    #1
    First off, the problem I am trying to solve:

    1. I have a page on my site that I want to be loosely secure, basically a user can't just click through to get to the page. I don't want it to be bulletproof by any means and I don't even care if it is linkable or bookmarkable, just some kind of quasi-security to stop prying, computer illiterate eyes from seeing the page.

    2. I also have a phpbb database of users already registered.

    Solution:

    Make a script to access the phpbb database logins and passwords and determine if the user will be passed on to the page, or rejected.

    Well, I have everything working fine except for the very very last and seemingly simple part. Once the script determines that the user is authorized, how do I redirect the user to the next page? I'm new to PHP, but not to programming, and have found everything else I need in books or on php.net, but I can't seem to stumble across a means of implementing this. I'm sure its one simple line of code, but I can't seem to find it, so if you can help, please do.
     
  2. macrumors 6502

    Joined:
    Jan 17, 2002
    Location:
    Santiago, Chile
    #2
    The simplest way, and what I do most of the time, is to just close php and redirecto throgh javascript; it will address just fine your problem.
    something like:

    if (authorized)
    {
    ?>
    <script>
    location.href="otherpage.php"
    </script>
    <?
    }
    else
    echo("Access denied");
    ?>
     
  3. macrumors newbie

    Joined:
    Jan 27, 2004
    Location:
    Hellsinki
    #3
    And by using PHP

    Also, you can use PHP to send http headers. So, within PHP just:

    PHP:
    <?php

    if($authenticated) {
      
    header("Location: http://www.example.com/secret_dir/");
    } else {
      
    header("Location: http://www.example.com/notloggedin.html");
    }

    ?>
    By using this the client browser doesn't need to have javascript support.
     

Share This Page