You would be best using Joomla's User Object.
To do this, you can use the following:
$user = JFactory::getUser();
echo $user->id;
echo $user->name;
For more information about the possibilities of Joomla's User Object, have a read of the following:
http://docs.joomla.org/Accessing_the_current_user_object
Update:
To import the Joomla framework, add teh following to your custom PHP files at the top:
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', realpath(dirname(__FILE__)) );
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
$mainframe = JFactory::getApplication('site');
I believe line 3 is correct seeing as your PHP script is in the root folder, however if you move it to another directory, you will have to update the line 3 of the code above.
Hope this helps