Jump to content

Help with protected pages and session register


simonjk

Recommended Posts

Hi,

 

I have built a registration and login system for a website, part of which I wish to protect certain pages.

 

The registration systems works well, as does the login BUT I am having difficulty with the next stage.

 

How do I then 'capture' the username and password that were entered by the user and get the PHP page I want to protect to check that these are valid? I guess it is a piece of code I need to put in the top of the protected page?

 

Here is the final piece of code (which then includes a link to the page I want to protect) from the login page which includes session_register, but then how can I use this information in the page I wish to protect?

 

//Now if everything is correct let's finish his/her/its login

session_register("username", $username);

session_register("password", $password);

 

echo "Welcome, ".$username." please continue onto our ".$sub." membership area...<a href=".$index.">click here</a>";

}

 

 

Thanks,

Simon

Link to comment
Share on other sites

Thanks for the pointer thorpe.

 

But I wonder if you can tell me what code I should use at the top of the page I want to protect, i.e index.php?

 

Sorry to ask what must be obvious questions...I've stared at this far to long and have now confused even myself! ;)

 

Thanks,

Simon

Link to comment
Share on other sites

Arrgghhhhh, just when I thought it had gone so well.

 

The piece of code seems to not recognise when a user is logged in or not, it does not seem to protect the page. Am I missing something? Here it is as entered at the top of index.php

 

<?php

session_start();

if (!isset($_SESSION['username'])) {

  // user is not logged in

} else {

  // user is logged in

}

?>

 

Sorry to trouble you again,

Simon

 

Link to comment
Share on other sites

Again, I'm sorry to ask the obvious on a Friday afternoon, but I would like the user to just be able to see the page index.php if they are logged on, and to be taken back to login.php if they are not logged on?

 

Tried this but not working ;(

 

<?php

session_start();

if (!isset($_SESSION['username'])) {

header("location:login.php");  // user is not logged in

}

else {  // user is logged in}

?>

 

Simon

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.