members only page

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
I am new to this site and really no nothing about php but I was told in order to set up a members only page on my website, I needed to created a php member page and I have no idea how to go about doing this.
I've searched the web for help and have found lots of codes you can use but I have no idea where to put these codes.
I don't know where to start or what steps I need to take in order to make some pages on my website only available to people who register and become a member.
I hope someone can help me or give me some directions as to where I can look for help.
Thanks.
 
You will need a Database of some kind to hold member data....

Then you need to create a login page which checks the username and password against the contents of the database.

Then you need to utilize sessions to restrict certain pages to only logged in users.

On a side note... if you need a Members Only Jacket, I might have one for sale.
 
I know how to create a database but from then on I'm not sure what I need to do.
Can I just create an HTML page that uses the information in my database or is this where the php file needs to be created?
 
You can either:

A. Create a HTML form that submits to a PHP page that will check the form variables against the Database.

OR

B. Create a php page that displays a form and submits to itself to check the variables against the database

Either way. On the PHP page once a user is confirmed as legit, you want to create a session and push them to the members only section
 
I think this is way over my head. I may have to can this idea.
 
Its really not as difficult as you would think. Once you understand it, you will be amazed you ever had issues.

Assuming you know how to make a form in HTML that has 2 fields (username, password) and a submit button. You would create a page that the form submits to. That page would roughly look like this....

Code:
<?php
session_start();

//create your database connection here

//check to make sure that username and password variables made it through to this page
//if you used a POST method on your form it would look like this...
if(!empty($_POST['username']) && !empty($_POST['password'])){
      //inside these brackets the user has supplied both a username and password

     //write out your query, be sure to sanitize form inputs
     $query = "SELECT * FROM users WHERE username = '" . mysql_real_escape_string($_POST['username']) . "' AND password = '" . $_POST['password'] . "'";

     if($rs = mysql_query($query)){
            if(mysql_num_rows($rs) == 1){
                    //a single row was returned which means that the user supplied a valid username/password
                    $_SESSION['loggedin'] == true;
                    header("Location: membersOnly.php");
            }else{
                    //user failed to log in
                    echo "GTFO with your bad credentials";
            }
     }else{
            echo "MySQL query failed please try again.";
     }

}


Then all you need to do is start all of your member only pages with the following code:
Code:
<?php
session_start();

if(isset($_SESSION['loggedin']) AND $_SESSION['loggedin'] === true){
        //they are logged in and should be here
}else{
        //wtf are they doing here send them to google for trying to go where they shouldnt
        header("Location: http://www.google.com");
}
 
As an additional note....

PHP is an amazingly versatile language that will allow you to accomplish the same task a multitude of ways. The only real requirement for utilizing the language is a basic knowledge of programming and a willingness to learn.

I can tell you from personal experience that 2 years ago I couldn't write PHP to save my life. Now, through lots of work and lots of reading of sites like PHP.net, I honestly feel that there isn't anything I couldn't accomplish with the knowledge I have gained.

PHP, HTML, JavaScript, CSS and SQL come together in such a beautiful symbiosis that someone who can master all of them can make amazingly powerful and aesthetically pleasing sites.
 
You make it sound so easy but this seems way above me.
I don't know how to create any forms, not even using html.
I've been trying to learn html and css for several years now and have a pretty good understanding on how they both work but I really don't know anything about php. However, I did buy a book, actually 3 years ago on php but never could seem to get the hang of it so I went back to learning html and css.
I may have to can this whole idea of setting up a member's only page unless I can make some sense out of this.
 
I am sorry I couldn't assist you more. As I stated before a basic knowledge of programming languages and HTML is pretty much required to even have a chance at handling most of these topics.

I suggest that you check out w3schools, php.net and other similar resources. They are full of examples and tutorials that will get you on the learning track necessary to accomplish what your are attempting.

If on the other hand you are willing to pay for a developer I would suggest posting in the Jobs board on this forum with a verbose description of your goals and what you are willing to pay.
 
Thanks for trying to help me. I'll look into w3schools.
This just might be something I myself can't figure out and will have to can the idea. My website is a site I created just for fun but I have some information I only wanted certain people to be able to see if they signed up for a membership but since I don't make any money from my site, it's not worth it to pay someone to set something up for me.
 
You might be better served looking into utilizing something like Drupal or Joomla which will allow you to obtain the functionality you wish without having to learn the code. The problem is that you have to redesign you site into Drupal or Joomla templates. The advantage is that you will be able to update and implement web pages on your site with greater ease.

The code I supplied above is more than adequate to accomplish what you need but because I have 0 experience with your site I code in generalities that will satisfy anyone with the knowledge of how to utilize it.

I wish I could assist you more but I wish you the best whatever you end up deciding to do.
 
I had originally asked my host site for some help and they suggested I download Joomla but I got the impression that meant they would design my site and I don't want that so I'll either just forget about this or try and understand php better. I also need to try and understand exactly what takes place when you set up a page where someone needs to become a member.
From what I've been reading, I get the impression I need to have a database to store all the member information.
I've set up databases but those were for some forums. I'm assuming you can use a database to store other information such as a member list.
I was thinking of attempting to create an HTML form since I'm more familiar with html and see if that helps me make some sense out of all this.
I appreciate you trying to help me.
 
I actually created a form using an online form builder but I have no idea where my submissions went.
I think I'm starting to understand things just a little bit. Maybe I'll figure it out.
 
Back
Top