/    Sign up×
Community /Pin to ProfileBookmark

i wish to set up a file called check.php what this doe sit check a set of php pages all which include this file, what this script does to begin wiht is to check the variable $logged and as default it should be out and if it is out and a page they have accessed needs them to be logged in , it auto takes them to the login page, whihc they can then choose to register, to login i need to check usernames and passwords against an sql table , once logged in the logged var turns to in and in the session it needs to store their username id, form the table and their rank could pyro or somebody help me where possible so i can achieve this, maybe step by step guide somehere? thanks, luke ?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@JonaJan 09.2004 — [font=arial]Hello lukezweb,

I've done something very similar to this myself, while working on [url=http://cmm.sonoracabinets.com/accessiforum/]AccessiForum[/url]. What I did was create an inc/ directory and put three files in it:

  • 1. headers.php

  • 2. functs.php

  • 3. footers.php


  • I include functs.php in headers.php, and have most of my basic functions in functs.php. Headers.php is just the beginning HTML, and footers.php is just the ending HTML (or XHTML) for each page.

    What I do is call the loggedin() function, which looks like this:[/font]

    [code=php]
    function loggedin(){
    $currTime = time();
    if(isset($_SESSION["username"]) && isset($_SESSION["time"]) && isset($_SESSION["ip"])){
    if($currTime<$_SESSION["time"] && $_SESSION["ip"] == $_SERVER["REMOTE_ADDR"]){
    $_SESSION["time"] = time()+60*30;
    return true;
    }
    } else {
    $mQuery = "UPDATE players SET status = 'false' WHERE ip = '". $_SERVER["REMOTE_ADDR"] ."'";
    $mResult = mysql_query($mQuery);
    if(!$mResult){dispErrMsg("Database error: ". mysql_error());}
    return false;
    }
    }
    [/code]


    [font=arial]As you can see, I'm using $_SESSION variables in my validation. You'll notice the dispErrMsg() function--it basically displays an error and includs the footers.php file, but doesn't run anymore code other than that (no more validation occurs).

    In my login page, I set the session variables that are validated above. The IP address, username, etc.

    Hope that helped a bit![/font]

    [b][J]ona[/b]
    ×

    Success!

    Help @lukezweb spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...