• 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

    • New Outlook for Windows landing in Microsoft 365 Education accounts next January by Paul Hill Microsoft has announced that from January 2026, Microsoft 365 Education users will be able to switch to a “modern, AI-powered” Outlook for Windows. The Redmond giant said that a new toggle will show up for eligible users that will let them decide whether to run classic Outlook or the new Outlook for Windows. The new version, Microsoft said, brings numerous improvements including more streamlined communication, features to boost your productivity, and more ways to personalize your experience. As this update is coming to Microsoft 365 Education accounts, it means it’ll affect both students and teachers. The refreshed interface more deeply integrates with Microsoft 365 Copilot to deliver: smarter email and calendar management with features such as Pinning and Snoozing; personalized themes that match your style and preferences; and Copilot-powered assistance to help you draft, summarize, and organize your emails and appointments. Microsoft is obviously keen for users to switch over to the new interface when it's available to foist AI on you. However, if you are reticent about using these AI tools, you can always revert back to the classic Outlook for Windows, at least for a while after the new version is released. The new toggle will begin rolling out globally next January. Before then, Microsoft 365 Education users will get in-app notifications ahead of the change to prepare them, and educational organizations will have the power to opt out or manage the experience through administrator settings. While most Microsoft 365 Education users will get the toggle, there are some exceptions. These include: organizations that have opted out of automatic migration; users with perpetual licenses; on-premises account holders; and devices where the toggle is hidden via policy. The upcoming changes will not require any administrative action during the rollout. Microsoft says administrators, if they want to, can notify users about the upcoming change; update their internal documentation; and review the documentation for Admin control over migration. The firm said that after the rollout, policy controls will become available through Group Policy Objects (GPO), Cloud Policy, and Intune. In terms of compatibility with other platforms, the new Outlook for Windows will be compatible, including with Mac. Users will still be able to access their accounts normally through the Outlook app available for macOS or via the Outlook web app.
    • Might be a joke to a shortsighted person, but that's the minimum for ANY EV to be as reliable and hassle-free as my '12 Highlander Hybrid. Sure my Hybrid gets even less at 372mi (in the winter) - 455mi (in the summer) on a tank, but at least I can refill it for another 372mi-455mi in merely 10 minutes or less without ANY of the following worries: Without all of that peace of mind, an EV will require 800mi/charge to give similar peace of mind for me. I ain't buying and worrying about separate vehicles just for city commuting and long road trips. That's a total waste of cash IMO. My Highlander Hybrid perfectly suits both use cases, and for any EV to be worth my consideration, they'll have to suit them too. Maybe for you that solely resides in 1 city and never travel by road it makes no sense, but for anyone with experience of traveling across cities here in Canada, it makes total sense given the long distances. I ain't suddenly adding another 1hr to my road trip just for EVs, mere coffee and snacks suffice for my trips (~800km), and those certainly don't take me 1hr.
    • Microsoft will reportedly hit Xbox division with a massive wave of layoffs soon by Pulasthi Ariyasinghe It was only a few days ago that a report came out regarding a mass layoff wave at Microsoft. While that report only mentioned sales staff that were to be affected, now, another report has landed that mentions the company's Xbox gaming division being another layoff target. According to Bloomberg's Jason Schreier, Microsoft has another major round of layoffs planned for the Xbox division as it reorganizes the company ahead of the new fiscal year. This unfortunate news for many staff will be announced as soon as next week, per the report Bloomberg has gained the information from sources that had asked not to be named, who had said that managers inside Xbox are already expecting the job cuts to take effect soon. While no specific developers, divisions, or numbers were mentioned, "substantial cuts" are reportedly incoming as a part of this change. The gaming division of Microsoft has gone through multiple layoff waves in recent years. Late 2024 saw 650 jobs being cut from Xbox corporate and supporting teams. Earlier in the same year, over 1,900 staff from Activision Blizzard, ZeniMax, and Xbox development teams were let go from Microsoft. Microsoft has released a number of high-profile first games as of late, including Doom: The Dark Ages, Avowed, and Indiana Jones and the Great Circle, and is also pursuing a multi-platform strategy that has Xbox games releasing on PlayStation platforms. It has also confirmed next-gen Xbox hardware is now in development and recently unveiled a first-ever official Xbox handheld initiative. If the latest report turns out to be accurate, we should have an official announcement sometime next week. Microsoft's current fiscal year is slated to end on June 30.
    • LibreOffice is fine for individual use, but its collaboration tools are far behind Office 365.
    • First thing I wondered as well. I miss the old color. I always thought it was nice how each app had its own color. Then they go and take 2 of the most commonly used apps and give them the same color.
  • Recent Achievements

    • Week One Done
      Sharon dixon earned a badge
      Week One Done
    • Dedicated
      Parallax Abstraction earned a badge
      Dedicated
    • First Post
      956400 earned a badge
      First Post
    • Week One Done
      davidfegan earned a badge
      Week One Done
    • First Post
      Ainajohn earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      593
    2. 2
      ATLien_0
      223
    3. 3
      Michael Scrip
      170
    4. 4
      +FloatingFatMan
      152
    5. 5
      Som
      135
  • Tell a friend

    Love Neowin? Tell a friend!