I am getting confused by PHP at this point. I am trying to make a membership site but need a way to protect all my pages from unauthenticated access. Can someone steer me how to do this through PHP? I already have the database that does create accounts but once the account is created people can access the page as long as they know the full URL.

Member Avatar for diafol

Have you searched this site or the internet for login scripts? You'll find a few thousand. Just research.

But I notice that all of them just have a single user/pass to protect each page. I am looking for a php script that connects to the database with members before connecting the page to make sure that they are authenticated.

Member Avatar for diafol

On form login - send details to a form handler file. Verification takes place, a session variable is set if user exists with details like username, userlevel. A paage redirect then occurs - usually back to the index page.

The index page shows different data, depending on whether the session variables are set or not or at which level the user is.

Each page should be 'protected' by the userlevel. Access to some, not others maybe or different views depending on level.

commented: useful post +5

As Ardav suggested, Use session to protect your page from unauthorized users.

My problem is that I do not know how to write the code needed for the protection for individual pages. If I knew how to write the code, I would not have had to ask how to do it in this forum.

Member Avatar for diafol

That's why you need to research it first. You can't expect members to write the code for you. Get a script, read the documentation and give it a go.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.