How to login programmatically as user 1 in Drupal 6

| | 1 min read

If you have a Drupal 6 site where you have access to the ftp account but not to the user 1 credentials here is how you can login programmatially to the site as user 1 without resetting the user 1 password. Now that you know that this is possible, remember to not give ftp access to users who do not have access to user 1 credentials as well.

In Drupal 6 you can do this by copying over index.php as test.php (or whatever name you wish to call it) and replace everything after the following line excluding the following line



global $user;
$user = user_load(1);

If you are looking to find out how to login to a Drupal 7 site read our article on how to login programmatically to a Drupal 7 site.

Remember to delete this file immediately after logging in as it would be a gargantuan security vulnerability to leave this file in the website as anybody who accesses this file will be able to gain access to your site as user 1.