• 0

Need to create a way for users to login


Question

I'm a bit way over my head with this, haven't designed or coded webpages since 2002. I need a way for users to login using the website so they can download personal information such as W2 forms or timesheets. I am not sure if I would need to do this in .php or what. If anybody can give me some advice, I would appreciate it.

6 answers to this question

Recommended Posts

  • 0

You can use multiple types of code, php, asp, jsp etc.

 

Here's a simple php tutorial: http://www.phpeasystep.com/phptu/6.html

 

Make sure to secure your passwords with a hash, I recommend PBKDF2, bcrypt or scrypt if you want to be absolutely sure the password cannot be cracked even when your user database is stolen.

  • 0
  On 18/07/2014 at 02:41, HardSide said:

I should have been more clearer, I understand how to create a login, but I am not sure how to tie the login so the login can access certain files.

See step 4 that php code should be added to the pages which should only be available to users who are logged in.
  • 0

You might try something like this:

 

  1. Store the files you want to be only available to specific users in a web-inaccessible location (but one that PHP can read)
  2. Use something like this in a download script:
if ($loggedIn) {
        header("Content-type: application/msword");
        header("Content-disposition: attachment; filename=\"W2.doc\"");
        echo file_get_contents("/home/username/yoursite/JohnDoeW2.doc");
} else {
        echo "You are not authorized";
}

First, a conditional checks one of two possibilities: whether you're logged in or not. Then, it sets two headers. The first tells the browser it's going to receive a MS Word document, and the second tells it that it should download the file rather than show it in the browser. Here, you get to specify a name for the file that is different than the actual file itself (W2.doc). Then, you echo the contents of John Doe's W2 file (JohnDoeW2.doc). So if you go to the site and you're logged in, your browser will prompt you to download JohnDoeW2.doc - but it will be called W2.doc in the client. Hope that helps!

  • Like 2
  • 0
  On 24/07/2014 at 18:33, Moogey said:

You might try something like this:

 

  1. Store the files you want to be only available to specific users in a web-inaccessible location (but one that PHP can read)
  2. Use something like this in a download script:
if ($loggedIn) {
        header("Content-type: application/msword");
        header("Content-disposition: attachment; filename=\"W2.doc\"");
        echo file_get_contents("/home/username/yoursite/JohnDoeW2.doc");
} else {
        echo "You are not authorized";
}

First, a conditional checks one of two possibilities: whether you're logged in or not. Then, it sets two headers. The first tells the browser it's going to receive a MS Word document, and the second tells it that it should download the file rather than show it in the browser. Here, you get to specify a name for the file that is different than the actual file itself (W2.doc). Then, you echo the contents of John Doe's W2 file (JohnDoeW2.doc). So if you go to the site and you're logged in, your browser will prompt you to download JohnDoeW2.doc - but it will be called W2.doc in the client. Hope that helps!

Nice method for actually securing file download links!

  • 0
  On 24/07/2014 at 18:33, Moogey said:

You might try something like this:

 

  1. Store the files you want to be only available to specific users in a web-inaccessible location (but one that PHP can read)
  2. Use something like this in a download script:
if ($loggedIn) {
        header("Content-type: application/msword");
        header("Content-disposition: attachment; filename=\"W2.doc\"");
        echo file_get_contents("/home/username/yoursite/JohnDoeW2.doc");
} else {
        echo "You are not authorized";
}

First, a conditional checks one of two possibilities: whether you're logged in or not. Then, it sets two headers. The first tells the browser it's going to receive a MS Word document, and the second tells it that it should download the file rather than show it in the browser. Here, you get to specify a name for the file that is different than the actual file itself (W2.doc). Then, you echo the contents of John Doe's W2 file (JohnDoeW2.doc). So if you go to the site and you're logged in, your browser will prompt you to download JohnDoeW2.doc - but it will be called W2.doc in the client. Hope that helps!

nice little bit of code, though dont forget about the sessions! (if you need to know that as well) 

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Anno 117: Pax Romana gets a November release date as Ubisoft unveils Governor's Edition by Pulasthi Ariyasinghe Ubisoft's long-running city-building and management franchise, Anno, was first revealed to be receiving another entry back in 2024. While it has taken some time, Anno 117: Pax Romana finally received a firm release date today during the 2025 PC Gaming Show event just as pre-orders open up. Catch the latest cinematic trailer above. Anno 117: Pax Romana lands on November 13, 2025, letting fans loose on the Roman settlement-building venture. The game's first gameplay was revealed just a few weeks ago as well, which you can watch by heading here. As new features, the title is adding a province selection mechanic at the start of each game, a religion system, a research tree, land combat, modular shipbuilding, and, most importantly, diagonal roads and building construction. Those who pre-order the game will also receive a Builder Pack from today. This will carry the Wolf player sigil, a matching battle standard, the Town Crier statue, as well as the Capitoline Wolf statue. At the same time, a Gold Edition is available for pre-order that bundles the Year 1 Pass with the base game. This will carry access to three DLC packs, and judging by the teaser image, it looks like players will be heading to Egypt for new adventures as part of the expanded content. For fans who may want something a little more comprehensive, Ubisoft also unveiled the Anno 117 Governor’s Edition. This special edition comes with these collector's items and digital goodies: Collector's items: Amphitheatre 3D Puzzle (36 x 31 x 13 cm) 84-page Artbook featuring concept art and behind-the-scenes content - cover design elected by community! Forged Anno Symbol (approx. 7 cm) Albion & Latium Coins Steelbook® case - design elected by community! Town Crier's Letter (21 x 30 cm) Tesserae Works Blueprint (42 x 59 cm) 3 Lithographs (30 x 15 cm) Digital Content: Base Game Year 1 Pass, including: 3 upcoming DLCs Additional in-game content The Builder Pack: 3 exclusive ornaments 1 player sigil Anno 117: Pax Romana is slated to hit Steam, Ubisoft Connect, Epic Games Store, Xbox Series X|S, and PlayStation 5 platforms. Pre-orders are now available starting at $59.99 for the standard edition. Ubisoft+ subscribers will also receive the title as a day-one drop. In addition to the base game, members will also receive access to the upcoming DLC packs at launch for no extra cost.
    • Once the first went to a full version number, some just egregiously long numbers with every iteration of compilations/dates/times... what have you, it was a landslide. Long gone are the days of IE version 6, 7... now it's Edge 137.0.3296.16. So, why not iOS 2026.18.8778.322.10.800? Shocked that Edge isn't 2025.137.0.3296.16... seriously. When Samsung went from S10 to S11, to S20... to S21... I thought they were just doing new iterations of the same/similar models, then the next would have logically been S30/S31... but nope. Oh well... better things to think about then version numbers, leave that to the devs.
    • The problem -- as pointed to by the PowerShell output I quoted above -- was that for some reason it couldn't download the NuGet provider. Here's what did work: (1) Download the raw nupkg file (set-inetpubfolderacl.1.0.0.nupkg) from https://www.powershellgallery....s/Set-InetpubFolderAcl/1.0; (2) Extract (e.g., via 7-Zip) the Set-InetpubFolderAcl.ps1 file into C:\Program Files\WindowsPowerShell\Scripts; (3) Run the script via PowerShell as described in the quite thorough instructions given at https://www.windowslatest.com/...t-on-windows-11-windows-10/ . That worked for me, or seemed to. Oh, relief!
    • I like the show's/comic's violence being represented here, as so many others avoid it. Timing is key with this release due to the Marvel Tokon title.
  • Recent Achievements

    • First Post
      George Almeyda earned a badge
      First Post
    • Reacting Well
      BlakeBringer earned a badge
      Reacting Well
    • Reacting Well
      Lazy_Placeholder earned a badge
      Reacting Well
    • Dedicated
      Epaminombas earned a badge
      Dedicated
    • Veteran
      Yonah went up a rank
      Veteran
  • Popular Contributors

    1. 1
      +primortal
      469
    2. 2
      +FloatingFatMan
      265
    3. 3
      ATLien_0
      235
    4. 4
      snowy owl
      219
    5. 5
      Edouard
      171
  • Tell a friend

    Love Neowin? Tell a friend!