Reputation: 2679
I would like to transform this url :
http://example.com/users_images/image.jpg
into :
http://example.com/users_images/user_123/image.jpg
(123 is user id stored in session)
Is this possible to do this with url rewriting ? If not, how are you dealing with this kind of problem ? I don't want my users to access another users's documents.
Thanks
Upvotes: 0
Views: 170
Reputation: 667
It is not possible to read out values from the php $_SESSION array in .htaccess for url rewriting. What you can do is to read out %{HTTP_COOKIE}
, so you can store it there but i would avoid this practive.
I would make a a folder where you store the images and put there a .htaccess file with the following content to prevent every user to access it:
Deny from all
Then I would make a php script that is responsible for reading out the session vars and with the php function fpassthrough()
you can pass the picture to the user. The php script can be called, when image is requestet for example:
RewriteRule users_images/(.*) /getpicture.php?image=$1 [L]
Upvotes: 2