Project Explaination

Embed Size (px)

DESCRIPTION

Social Share Php application

Citation preview

  • Project Explanation

    The connection string has been implemented in class call DBA.php

    public function __construct() {

    $con = mysql_connect($this->host, $this->user, $this->pass) or die(mysql_error());

    mysql_select_db($this->dbname) or die(mysql_error());

    }

    Once the object is created in any other php file, the connection will be initiated. So the programmer doesnt have to initiate the connection each time we create a new file.

    Login structure

    Once the user login, the system will check the username and password from the users table which we have created. Once the user is matched the session will be generated for the user so that they can access the user area.

    The table structure

  • Register

    In this module is just like as it says Registration of a user, the table structure is same as the above. Once the user press register button the submitted data will be added to the table, and can be used for checking whether the user name and password is valid or not.

  • Dash Board

    Is a place where user can see after login page, it contains group creation, status update and browsing the file of a groups or a folder created.

  • The right hand side menu bar for user. The user can choose 2 others module such as chat and private messaging

    File Upload (code)

  • $new_file_name = strtolower($_FILES['file']['tmp_name']);

    //rename file to lower string

    if ($_FILES['file']['size'] > 10485760) {

    //The above line will check whether the file is greater than 10 mb or not if its too large then it will show error

    $valid_file = false;

    echo 'Oops! Your file\'s size is to large.';

    echo 'Go back';

    }

    //if the file has passed the test

    if ($valid_file) {

    //move it to where we want it to be

    move_uploaded_file($_FILES['file']['tmp_name'], '../APP-BOX/' . $gname . '/' . basename($_FILES['file']['name']));

    echo 'Congratulations! Your file was uploaded sucessfully.';

    echo 'Go back';

    }

    }

    //if there is an error...

    else {

    //set that to be the returned message

    echo 'Ooops! Your upload triggered the following error: ' . $_FILES['file']['error'];

    }

    }

    ?>

    Why we have to move file after upload?

  • Php will usually take upload file to the temporary folder then erase it once the session is over thats why we need to use move_upload_file() function to specify where to store. So it wont get deleted once the session is over

    SESSION

    How session is generated in php?

    public function log_in($username, $password) {

    $sql = "select * from users where username='".$username."' AND password='".$password."'";

    $query = parent::query($sql);

    $num = mysql_num_rows($query);

    if($num == 1)

    {

    $row = mysql_fetch_assoc($query);

    $_SESSION['uid'] = $row['uid'];

    $_SESSION['uname'] = $row['username'];

    $_SESSION['name'] = $row['name'];

    $_SESSION['email'] = $row['email'];

    return 1;

    }

    }

    As we can see in the code above once the sql query is executed, Then it will check whether the username and password Is valid or not.

    If its valid then we will use $_SESSION[] function to generate the session we can specify session value by using data from database also

    EX

    $_SESSION['uid'] = $row['uid'];

    In this case we fetch data user id which is UID make it equal to $_SESSION[uid]

    So that we can use further in any other web pages