login redirect code

login redirect code

by Shail Jai -
Number of replies: 1
Hello,

I create one php page for moodle, but i want to display this only after admin login but i am not able to do this.

i try require_login() but it's not working, this function ask every time for login...

any clue ?

thanks & regards
Average of ratings: -
In reply to Shail Jai

Re: login redirect code

by Aaron Wells -
Are you including Moodle's config.php at the top of your script? If so, then require_login() should work. The way it works is that config.php includes lib/setup.php, which then creates a global $USER variable from data that Moodle stores in your PHP $_SESSION superglobal variable, and then require_login() calls is_logged_in(), which basically just checks to see if that global $USER variable is set up.

If you are including config.php, and require_login() still causes your page to redirect to the login page every time, then it sounds like you've got some session-related issue (either the page you're loading isn't using the same session cookie, or it's somehow clearing data from $_SESSION). Try examining the contents of $_SESSION in a PHP debugger, or if you haven't got that set up just add a var_dump($_SESSION) and a var_dump($USER) to your PHP script.

Cheers,
Aaron