Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2006
    Posts
    282
    Tokens
    0

    Default Need help with cookies

    Ok so for the login to admin panel on my site i put it to create a cookie with the value '1' so you put on the passworded pages that it required a cookie with the value '1' like this;

    if($_COOKIE['in'] == "1"){}
    else{
    die("You are not authrised to view this page.");
    }

    Now i tried to make a moderator login so its basically the same as the admin login but it sets the cookie to "2" and i put this code on the pages that moderators need;

    if($_COOKIE['in'] == "1" && "2"){}
    else{
    die("You are not authrised to view this page.");
    }

    Thats so admin and moderators can access the page, it works fine but when you login through the moderator login, it goes to a moderator page when the login was successful but says Not logged in so it isnt setting the cookie correctly, this is what i use for the admin login;

    PHP Code:
    <?php
    if ($_SERVER['REQUEST_METHOD']=="POST"){

    // Get UserNames and Passwords.
    $Logi file("users/users.txt");
    // Work out how many there are
    $size sizeof($Logi);
    // Break appart passwords and usernames
    foreach($Logi as $Key => $Val)
    $Data[$Key] = explode("||"$Val); }
    // run threw list and see if any match
    for($K 0$K<$size$K++)
    {
    $user $Data[$K][0];
    $pass =  $Data[$K][1];
    // If match set cookie and redirect.
    if ($user == trim(addslashes($_POST["user"])) && $pass == trim(addslashes($_POST["pass"])) )
    {
    setcookie("in"1time()+3600);
    // Start hidden page
    header("Location: adminindex.php");
    }
    }
    echo 
    "Login Failed.";

    // If you didnt log in show login form
    } else { ?>
    <div style="width:250px">
    <div><strong><font face='verdana'><font size=1><b>Admin Login</b></strong></div><br><br>
    <div><form name="Login" method="post" action="<?=$_SERVER['PHP_SELF'];?>">
    Username;<br>
    <input name="user" type="text" >
    <br><br>
    Password;<br>
    <input name="pass" type="password" >
    <br><br>
    <input type="submit" name="Submit" value="Submit">
    </form>
    </div></div>
    <?php

    // Copyright PixelResources 2006 - 2007

    ?>

    <?php
    }
    ?>
    And this is what i use for mod login;

    PHP Code:
    <?php
    if ($_SERVER['REQUEST_METHOD']=="POST"){

    // Get UserNames and Passwords.
    $Logi file("users/mods.txt");
    // Work out how many there are
    $size sizeof($Logi);
    // Break appart passwords and usernames
    foreach($Logi as $Key => $Val)
    $Data[$Key] = explode("||"$Val); }
    // run threw list and see if any match
    for($K 0$K<$size$K++)
    {
    $user $Data[$K][0];
    $pass =  $Data[$K][1];
    // If match set cookie and redirect.
    if ($user == trim(addslashes($_POST["user"])) && $pass == trim(addslashes($_POST["pass"])) )
    {
    setcookie("in"2time()+3600);
    // Start hidden page
    header("Location: modindex.php");
    }
    }
    echo 
    "Login Failed.";

    // If you didnt log in show login form
    } else { ?>
    <div style="width:250px">
    <div><strong><font face='verdana'><font size=1><b>Admin Login</b></strong></div><br><br>
    <div><form name="Login" method="post" action="<?=$_SERVER['PHP_SELF'];?>">
    Username;<br>
    <input name="user" type="text" >
    <br><br>
    Password;<br>
    <input name="pass" type="password" >
    <br><br>
    <input type="submit" name="Submit" value="Submit">
    </form>
    </div></div>
    <?php

    // Copyright PixelResources 2006 - 2007

    ?>

    <?php
    }
    ?>
    But for some reason its not working..

  2. #2
    Join Date
    Mar 2005
    Location
    Leeds
    Posts
    3,423
    Tokens
    0

    Latest Awards:

    Default

    Its much easier when you just use mysql. Also just using cookies is very unsafe, I could get into it in about 5 seconds you need to check the username againts the password aswell....

    www.php.net/mysql

    Good luck,
    Danny

  3. #3
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    Yeah lol, all you need to do is create the cookie in and set it to 1 and I am in lol. Also the modcp wont work in you used and and not or..

Posting Permissions

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