newbie help
Results 1 to 3 of 3

Thread: newbie help

  1. #1
    Join Date
    Apr 2012

    newbie help


    Just started creating my first dynamic site for a uni project.

    right now i've just got my registration/ login system sorted.

    when you navigate to my site, the index.php has a query asking whether a user session is active, if not it loads the login page, if there is it loads the homepage.

    at the moment, im using the include''; function. my question is does this just load the file within the current page? because i want to have a way of completely loading the new file/page, but I dont know the syntax for this?

    so currently i have:

    if(strcmp($_SESSION['uid'],"") == 0){
    //no user session, so go to startpage where the login/ register form is

    this works but i think its loading the new files within the index.php which I dont want


  2. #2
    Beware: Crazy Scientist leatherback's Avatar
    Join Date
    Mar 2002
    Small border town between Netherlands and Germany
    Includes will result in all code from the included file to be inserted at the point where you "include" them.

    So is a.php has:

    echo "aaaa";

    Then b.php:
    PHP Code:

    echo "page b. Referring to a:";

    wil result in:

    page b. Referring to a:aaaa

    I think you would want to user the header funtion instead.

    As an afterthought.. Why did you not post this in the newbies forum?
    Last edited by leatherback; 04-09-2012 at 06:22 AM.
    Php 4.* to 5.*. A small step for programmers. But a leap for me!

  3. #3
    Join Date
    Apr 2012
    Thanks! i managed to get part of the system working using the header(); function, as well as the ob_start(); and ob_flush();.

    so so far my index.php redirects to either the start/login page if user not logged in or the home page if they are

    however, when a user logs in sing the form, I cant get my login.php that the form uses to redirect using this method?

    I think its probably an error in my script, could somebody take a look?

    PHP Code:
    //allow sessions to be passed so we can see if the user is logged in

    //connect to the database so we can check, edit, or insert data to our users table
    $con mysql_connect('STUFF HERE THAT YOURE NOT ALLOWED TO SEE :P') or die(mysql_error());
    $db mysql_select_db('MORE CENSORED STUFF'$con) or die(mysql_error());
    //include out functions file giving us access to the protect() function made earlier
    include "./functions.php";
    //If the user has submitted the form
    //protect the posted value then store them to variables
    $username protect($_POST['username']);
    $password protect($_POST['password']);
    //Check if the username or password boxes were not filled in
    if(!$username || !$password){
    //if not display an error message
    echo "<center>You need to fill in a <b>Username</b> and a <b>Password</b>!</center>";
    //if the were continue checking
                    //select all rows from the table where the username matches the one entered by the user
    $res mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."'");
    $num mysql_num_rows($res);
    //check if there was not a match
    if($num == 0){
    //if not display an error message
    echo "<center>The <b>Username</b> you supplied does not exist!</center>";
    //if there was a match continue checking
                        //select all rows where the username and password match the ones submitted by the user
    $res mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."' AND `password` = '".$password."'");
    $num mysql_num_rows($res);
    //check if there was not a match
    if($num == 0){
    //if not display error message
    echo "<center>The <b>Password</b> you supplied does not match the one for that username!</center>";
    //if there was continue checking
                            //split all fields fom the correct row into an associative array
    $row mysql_fetch_assoc($res);
    //check to see if the user has not activated their account yet
    if($row['active'] != 1){
    //if not display error message
    echo "<center>You have not yet <b>Activated</b> your account!</center>";
    //if they have log them in
                                //set the login session storing there id - we use this to see if they are logged in or not
    $_SESSION['uid'] = $row['id'];
    //show message
    header('location: home.php');ob_end_flush();}}}}}?>
    Last edited by bradgrafelman; 04-09-2012 at 10:21 AM. Reason: attached inserted into message

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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