SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    May 2003
    Location
    somewhere on the Earth
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    newbie question about protect password on server

    I have a file containing password on the server. I want to protect it from being accessed by vistors, but I need to access in my PHP scripts. What should I do? I tried to change the atrribute of that file to make it not accessible from vistors, but, my scripts can't, either.

  2. #2
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    You could try putting the file above the webroot. Like when you log into your FTP there will probably be a public_html firectory or something that you put your files in. Just put the file with your password in the first directory and when you include the file in your PHP scripts, do something like this:
    PHP Code:
     require_once '../password.php'

  3. #3
    SitePoint Wizard Dangermouse's Avatar
    Join Date
    Oct 2003
    Posts
    1,024
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you have this in password.php

    PHP Code:
    <?php
    $password 
    "password";
    ?>
    Then on your other page have
    PHP Code:
    <?php
    include("password.php");
    echo 
    $password;
    ?>
    If a user goes to password.php they wont be able to see anything, but when you include the script $password should be set.

  4. #4
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    That's very true, but if PHP dies on the server then all will be visible If possible I'd suggest storing the file abive webroot but it's really personal preference, chances of PHP crashing and not taking Apache with it are small.

  5. #5
    SitePoint Wizard Dangermouse's Avatar
    Join Date
    Oct 2003
    Posts
    1,024
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Didnt think about that


Bookmarks

Posting Permissions

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