files and folders must be accessible by logged in users .How to secure files from unauthorized access
<p>i am building a basic filemanager just for learning purpose.</p>

<p>how this sytem works:
1.user registration. while user fill registration form a directory created with a unique name. this name also store in database.
2.User login and access files and folders created by user.</p>

<p>but i faced a problem here. if anyone know the name of folder name and file paths (Can get from URL).</p>

<p>I want to make it secure. only loggedin user can access these files and folders (Who create the folders and files).
Register.php file :</p>

<pre><code>&lt;?php
 if(mysql_query("INSERT INTO user (UserId,FirstName,LastName,UserDirectory,Email,Password,Gender,dob,ipaddress,dateTime) VALUES('$userid','$fname','$lname','$dir','$email','$upass','$gender','$dob','$ipaddress','$datetime')"))
   {    mkdir("file/$dir");
   mkdir  ("file/$dir/");

    header("location:dir.php");
   } ?&gt;
</code></pre>

<p>dir.php file</p>

<pre><code>&lt;?php
session_start();
include_once 'dbconnect.php';

if(!isset($_SESSION['user']))
{
    header("Location: index.php");
}
$id = $_SESSION['user'];
//echo $id;
$res=mysql_query("SELECT * FROM user where UserId = '$id' ");
if(mysql_num_rows($res) &gt; 0){ // if one or more rows are returned do following

            while($result = mysql_fetch_array($res)){

            ?&gt;
&lt;?php { { ?&gt;


            &lt;?php //path to directory to scan
$directory = "file/$mydir";

//get all files in specified directory
$files = glob($directory . "*");

//print each file name
foreach($files as $file)
{
 //check to see if the file is a folder/directory
 if(is_dir($file))
 { ?&gt;
  &lt;a href="&lt;?php echo $file; ?&gt;"&gt; &lt;br&gt;&lt;?php echo $mydir; ?&gt; &lt;/a&gt; &lt;?php
 }
}?&gt;
</code></pre>

<p>so if a user loggedin can easily access other users file by just type the file path.
Means personalised folders and files on lye creator of a file or folder can edit/ view files . 
Request : this system is just for only learning purpose and i just want to learn this task. so if you dont have solution related this please dont comment about mysqli and PDO Comments. 
Thanks in Advance :) </p>