在注销时重命名文件

I'm trying to rename a file with PHP but for some reason it doesnt work, do I have to activate some special permissions under PHP?

heres my code for the php file

<?php
  if(!rename('file.php','filer.php'))
  {
    echo "Couldn't rename file!";
  }
  else 
  {
    echo "file renamed succesfully!";
  }
?>

I'm trying to rename a file on my /var/www directory when they sign out of a login area, so that way they cant access back hitting back button. Do I have an error on my code? Or is there another way to prevent this?

The Default permissions on this folder /var/www/ are: chmod 755 /var/www/

"read, write, and execute by owner" and "read and execute by the group and everyone else" (-rwxr-xr-x)

and the files inside the folder /var/www/file are: chmod 644 /var/www/file

I don't know if you have changed the Permissions or simply execute this command and it we'll work.

chmod 777 /var/www/file.php

"read, write, and execute by owner, group and everyone else"

Try this, then...it will make a copy of the file under a new name and them delete the original:

copy('file.php','filer.php');
unlink('file.php');

You aren't trying to move the file the code is being called from, are you?

PHP must have write access to the file. (I assume that you have a UNIX system). First find out which user PHP runs as, by running this command:

echo `whoami`;

in the PHP interpreter. (On my system that's www-data). Then run:

sudo chown www-data file.php

in the shell, in the same directory as the file you want. Of course, change www-data to the PHP user on your system. Make sure that the owner has write permissions. Then you're done; PHP can rename this file.