使用用户ID重写网址
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
我想转换这个网址: p>
http: //example.com/users_images/image.jpg
into: p>
这可以通过url重写来实现吗?
如果没有,你好吗? 处理这类问题?
我不希望我的用户访问其他用户的文档。 p>
谢谢 p>
div> http:// example。 com / users_images / user_123 / image.jpg code>(123是会话中存储的用户ID) p>
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]