newbie help
Results 1 to 3 of 3

Thread: newbie help

  1. #1
    Member
    Join Date
    Apr 2012
    Posts
    38

    newbie help

    Hello,

    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
    include'./startpage.php';
    }else{
    include'./home.php';
    }

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

    thanks

  2. #2
    Beware: Crazy Scientist leatherback's Avatar
    Join Date
    Mar 2002
    Location
    Small border town between Netherlands and Germany
    Posts
    5,395
    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:

    <?php
    echo "aaaa";
    ?>


    Then b.php:
    PHP Code:
    <?php

    echo "page b. Referring to a:";
    include(
    'a.php');

    ?>
    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 07:22 AM.
    Php 4.* to 5.*. A small step for programmers. But a leap for me!

  3. #3
    Member
    Join Date
    Apr 2012
    Posts
    38
    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:
    <?php
    //allow sessions to be passed so we can see if the user is logged in
    ob_start();
    session_start();
     

     
    //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
            
    if($_POST['submit']){
                
    //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>";
                }else{
                    
    //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>";
                    }else{
                        
    //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>";
                        }else{
                            
    //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>";
                            }else{
                                
    //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 11: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
  •