From your question it would seem that your main problem is that the _spPageContextInfo variable is not defined. I don't know if this is your case, but in the past I found myself in a similar situation when working with a custom master page that someone else developed.
After some fun searching for a cause, a number of curses to the master page creation and some prayers to the Google Goddess, I found an article that explains the inner working behind the above variable and it's availability on SharePoint pages. The link is here.
Short story: the SPWebPartManager control is responsible of defining the _spPageContextInfo variable. Since whoever created my master page forgot to add it, the problem was resolved by simply enough adding the missing control.. and presto! the variable appeared.
As said, I don't know if you are in the same situation, but I prefer to post this anyway in the hope it may help you.