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 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2003
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer Sessions or Cookies

    Hi guys

    i want to protect an admin area of a website. how would i do this.

    what do you reccomend...sessions or cookies??

    how would i start a session / cookie??

    could you please reply with some code?

    cheers
    pete

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would do both.

    PHP Code:

    setcookie
    ('username','matt',time()+3600);

    // Sets a cookie called username, with the value matt, that lasts 
    // for 3600 seconds after the current time.

    // To get the value of that cookie, use...

    echo $_COOKIE['username']; // Displays the value matt.


    session_start();
    // Starts a PHP session

    $_SESSION['user'] = 'matt';
    // Sets the session variable user, with the value matt.

    echo $_SESSION['user']; // Displays the value matt.


    // You could check someone being logged in by:

    if(isset($_SESSION['admin']))
    {
          
    // Do admin
    }
    else
    {
          echo 
    "Do you really think im stupid?";

    Hope that helps you.

    Lets hope krycek turns up with his so_secure scripts.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    This little Earth.
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    http://codingforums.com/showthread.p...threadid=17023
    a 3-page thread to hopefully help you
    don't forget this site's got a Search feature
    'If you don't stand for something, you'll fall for anything.'

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    session_start();

    // Starts a PHP session

    $_SESSION['user'] = 'matt';
    echo 
    $_COOKIE['username']; // Displays the value matt. 
    Would have to be that way round, or you'll get an error saying headers already sent or something daft

  • #5
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    They were meant to be separate examples, I should have made that clear. Thanks Nightfire.


  •  

    Posting Permissions

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