Jump to content

Password Protect page


kipper1960

Recommended Posts

Hoping someone can shed some light as I am new to php

 

I have set up a login for members on my site and all this works well, once logged in it sends me to a members page where I have used the following code to protect the page but for the life of me I cannot get it to work,  could some one help me out

 

<?

session_start();
if(!isset($_SESSION['username']) || $_SESSION['username']=="")
{
echo "Please login to see this page.....";
}
else
{
content();
}
 
function content()
{
   My members page information I thought goes in here
 
}

?>

Link to comment
Share on other sites

What exactly doesn't work?  The first thing to note is that the function you declare needs to go before the call of the function in your else{}.  Remember that php works top-to-bottom, so if you try to use a var or function before it's actually declared it won't work.  Also you would have know this if you have error_reporting(E_ALL) turned on.

Link to comment
Share on other sites

Fatsol thanks for your reply but I dont understand sorry, this is the error I get after I have logged in and re-directed to the protected page

 

 

Parse error: syntax error, unexpected '}' in /home3/profitst/public_html/integration.php on line 17
 

Link to comment
Share on other sites

This is the correct way to use the code you have.

session_start();
// Notice that the function declaration is now above where you call the function.
function content()
{
  echo 'My members page information I thought goes in here';
}

if(!isset($_SESSION['username']) || $_SESSION['username']=="")
{
	echo "Please login to see this page.....";
}
else
{
        // This is considered a function call below.
	content();
}

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.