3

Im including almost every page in page_protect(); . I have made an variable for the userid, $userid, with the user´s id. So it will be much easier for me to get the id than calling SESSION_id each time on every page.

How can i use a variable inside that function outside the function?

1 Answer 1

12
function page_protect()
{
  global $id;
  $id = 1234;
}

page_protect();
echo $id;
Sign up to request clarification or add additional context in comments.

2 Comments

I know this answer was written almost 4 years ago, but I'd like to add this as a note for future visitors: You shouldn't use globals anymore. They're evil.
@AmalMurali, agreed, it's better to use function parameters and return values. But let people walk before they run.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.