Single download page for each user

Asked

Viewed 67 times

1

I am trying to create a user area on my site with PHP and Mysql, so far I have managed to make the login system and a private page for clients.

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

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

Follow 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;

    }
?>

1 answer

1


I think you should use a database and it wouldn’t stop you from anything (in my view of the problem)

For this to happen you only have to make a simple 1-to-many ratio (because 1 user can have multiple download links (by the 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 concerning ID user’s 1 example table.

and To get all the links that the user contains just do the following query as an example:

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

In this case it will return all the links that the logged in user has.

This was just an example 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, as you would have assurance that a certain folder can be accessed by a certain user ?

  • I think that’s really what I was looking for, I’ll test it here, thanks for the suggestion!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.