Single download page for each user

0

I'm trying to create a user area on my site with PHP and MySQL, so far I've been able to make the login system and a private page for clients.

The question is how could I make a single page available to each customer?

My goal is to provide unique download links for each user so that another user can not access, I will do so from Google Drive, but I do not know how to show the links exclusively for each client (even tried to insert the links in the database and show them with echo however this would prevent me from customizing them with CSS and HTML afterwards).

Here is the code I want to implement:

<?php
    include_once ("setting.php");
    @session_start ();

    $nome =  $_SESSION ['nome'];
    $usuario = $_SESSION ['usuario'];

    if (!isset($_SESSION['nome']) && !isset($_SESSION['usuario'])){
        header('location: login.php');
        exit;

    }
?>
    
asked by anonymous 21.08.2017 / 17:56

1 answer

1

I think you should use the database and it would not prevent you from doing anything ( in my view of the problem )

For this to happen you only have to make a simple 1-to-many relationship (because 1 user can have multiple download links (by logic))

Imagine the following table of users :

+----+-----------------+------------------------------------------+
| id |      email      |                 password                 |
+----+-----------------+------------------------------------------+
|  1 | [email protected]  | D6540780F1D484ABF4CF3EE484575822B28EF5FQ |
|  2 | [email protected]  | 88D2C2801C73885F0D0F54374CD51F3288C34F82 |
|  3 | [email protected] | C97C961736D050F24B1FCE96791546790A2BB668 |
+----+-----------------+------------------------------------------+

OBS Each user has a unique id.

Now imagine the following table user_links :

+----+---------+-------------------+
| id | id_user |       links       |
+----+---------+-------------------+
|  1 |       1 | google.com        |
|  2 |       1 | stackoverflow.com |
|  3 |       2 | facebook.com      |
+----+---------+-------------------+

In this table you can see that it contains the foreign key id_user that refers to the ID of the user of the example table.

e In order to get all the links that the user has, just make the following query as an example:

SELECT * FROM utilizador_links WHERE id_user = $_SESSION['id_user_logado']

In this case, you will return all links that the logged-in user has.

This was just an example of how your system can be organized using simple and practical database.

If you were trying to create a folder for each user, I think it would go wrong, how would you guarantee that a certain folder can be accessed by a certain user?     

21.08.2017 / 18:49