Password protecting a website
Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Password protecting a website

  1. #1
    The Prancing Pirate
    Join Date
    Jul 2004
    Posts
    548

    Password protecting a website

    Hi,

    I would like to upload a website to a webhosting company, but as it's still under development I'd like it to have a kind of "member login" on the index, and then from there, if the username and password are correct, they can be directed to the index.html of a subdirectory. I have seen other sites with this kind of pre-release "login required" index, and I'd like to make one. The only problem is that I think I'd need to use something like PHP, of which I know none, or something else. Could someone please point me in the right direction, because I'd like my partners to view the unfinished site to help me with the details. Thanks in advance,

    J_K9
    TAZForum <---- click

  2. #2
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,403
    If it's an Apache webserver you can use a .htaccess file..
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  3. #3
    The Prancing Pirate
    Join Date
    Jul 2004
    Posts
    548
    I don't think it's an Apache webserver....can you please tell me how to find out? Once, I got a 404 Error which turned it up and I'm pretty sure it wasn't Apache, but how can I check? Thanks,

    J_K9
    TAZForum <---- click

  4. #4
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,403
    Ask the hosting company? You can also look at the server headers it returns..

    If you're able to use PHP there's a 10 to 1 chance it's Apache..
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  5. #5
    The Prancing Pirate
    Join Date
    Jul 2004
    Posts
    548
    Oh ok in that case it isn't Apache because I've just found out for a fact that it doesn't support PHP or Perl "yet" (as they all say). Do you know of any good free webhosting services which support PHP? Well, I guess I have to make the script first...How would I do that? Are there any other languages I could make the script in (as long as it isn't too complicated!). I'm just about to find out what scripting languages they [I]do/I] support. Thanks,

    J_K9

    edit: Found a list of free webhosting services which support PHP here
    TAZForum <---- click

  6. #6
    Flash M0nkey
    Join Date
    Sep 2001
    Posts
    3,447
    Code:
    &lt;?php 
    $pw = "yourpassword";
    
    if($_GET['pw'] != $pw)
    {
    die("not authorised");
    }
    
    ?&gt;
    place that code at top of each page you wish to protect
    and then when trying to view a url just add ?pw=yourpass onto the end like :

    http://yoursite.com/index.php?pw=yourpass

    the script basically looks for the password in the URL if it cant find it it stops rest of page from loading and prints an error message. So place the code as the first thing on the page.

    Very very very quick and dirty way of doing it - but it works

  7. #7
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,403
    No need to use PHP if it is an Apache...

    .htaccess is also easy but definitly not a "dirty" trick
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  8. #8
    The Prancing Pirate
    Join Date
    Jul 2004
    Posts
    548
    Lol thanks valhallen and SirDice, but could I just get one final thing clear? I have put the php script supplied by valhallen in between the &lt;head&gt; and &lt;/head&gt; tages: is this ok? The thing is that I tried it by double-clicking on the index.html file after adding the php script in between the head tags but it loaded up anyway! As I am pretty much a newbie at PHP, I am very sorry for my ignorance, but does this script only work when it's placed on a web server? Also, the web hosting service I have chosen (SiteBerg.com) says that:
    Using PHP4
    You can use PHP immediately after registration.
    PHP directives are processed in files with *.php extension. If you want your site to start with index.php, upload it to the server and delete index.html, created during registration.
    Store your PHP scripts in the "WWW" folder. Folders with PHP scripts should have "755" ("drwxr-xr-x") access rights, and PHP scripts -- "644" ("-rw-r--r--").
    Does this apply to what I have done? I don't think it does because I'm pretty sure that only applies to external php files whereas this is embedded within the html, but I just want to check! Sorry I am very confused I'm also sorry for being such an ignorant uneducated ****

    edit: attached is what my index.html currently looks like (if you want to know) - is this right?

    J_K9
    TAZForum <---- click

  9. #9
    Flash M0nkey
    Join Date
    Sep 2001
    Posts
    3,447
    you need to inform your server that the file contains content which needs to be processed as php rather than plain html so you will need to change the extension of the page from .html to .php

    SirDice : yeah I would prefer to use .htaccess for this kind of thing as well - but am not sure if he has access to it.

  10. #10
    The Prancing Pirate
    Join Date
    Jul 2004
    Posts
    548
    So.....if I change the extension of the page (index.html) ot index.php, and put that in the normal folder (because if I delete the server's index.html I can put my index.php there, as shown in the quote of the FAQ). Will I really need to notify the hosting company, or can I just place this file in the place of the index.html? Also, I'm guessing I'll also need to change the extensions of all the linked pages lol. Thanks,

    J_K9
    TAZForum <---- click

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •