First of all, learn the basic concepts and the different kinds of the access tokens from here
To get the extended User token (validity: 2months) use the code you have mentioned in the question.
You can get the app secret from the Apps page.
To get a never expiring token for your fan page. Follow the simple steps:
Using the user token you obtained through step 2, get the list of pages/apps-
$facebook->api("/USER_ID/accounts");
Get the never expiring access token for any page-
$facebook->api("/PAGE_ID?fields=access_token");
(You can use Facebook's Debug Tool to check the validity of the token.)