The concept is possible but you would need to store cPanel logins in your script's database otherwise they will not be able to login to webmail without a user and password since cPanel doesn't know anything about who is trying to login to what account.

As for the code, I will let the PHP guru's answer that.

You might want to be more specific however as the original post is a bit terse.