• 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

    • Stardock Start11 v2.5.3.1 by Razvan Serea Stardock Start11 is a Windows 11 customization tool designed to bring back the classic Start menu and enhance users' desktop experience. It offers a range of features and options that allow users to personalize their Start menu and taskbar to suit their preferences. Make Your Desktop Yours Take complete control of your desktop with Start11. With Windows 11, Microsoft chose form over functionality and removed many different features that were available in Windows 10. With Start11, you can customize the experience to fit your personality. Features You Expect Windows 11 removed many features that were present in Windows 10, Start11 brings them back. From the basics like returning the right-click menu on the taskbar to ungrouping of windows on the taskbar. You can also choose to have your icons centered on the taskbar with your Start menu left aligned. One Desktop to Rule Them All When working with multiple devices across various versions of Windows, Start11 can help you create a common desktop experience. Make Windows 10 look like Windows 11, or 11 look like Windows 10. Or how about making both Windows 10 and 11 look like Windows 7? The choice is yours. Remove Unwanted Content Windows 11 brings with it a new design language but also more advertisements and content that you can’t remove. Take back complete control with Start11 and remove unwanted outside content and sections of the Start menu that you don’t want to see. Start11 v2.5.3.1 changelog: All the changes from 2.52 that were went to beta but never was not released Resolves issue with not always releasing reserved space when closing an app which reserved space on the side such as Multiplicity KVM switch bar. Resolved issue with enhanced taskbar not showing status indicators correctly for some running apps Tweaks to start button sizing with vertical taskbars on Windows 11 especially when using small icon mode Tweaks to drag & drop in Win10/Win11/App/Pro/Launcher menus to make creating folders easier and less like playing chase the item around :) Resolved issue with dragging out of a group in Win11/App/Pro/Launcher menus where you couldn't always drag out of a folder to a group below Resolved issue with taskbar texture not refreshing when the OS accent colour changes. Resolved issue with on top taskbar not in enhanced mode and clicking on the taskbar search field which would make the search window appear off the top of the screen incorrectly Apps flagged as 'new' in Win10/11/App/Pro/Launcher menus will now not have the flag once run once or right clicked on Improved removal of 'new' indicator on newly installed apps so it goes away in a day or so. The apps will still be considered 'new' for the recently installed apps list Improved sorting of child items in sub folders in all apps list Start10 style search no longer shows control panel results which are duplicates of the results in the Control Panel section. Enabled sort A-Z option for Folders and Fences groups too on Win11/App/Pro/Launcher menus Small tweaks to icon & tile image loading for Universal apps on Windows 10/11/App/Pro/Launcher menus Fixes setting pins to only show on a secondary not working for some apps. Users will need to reset the show only on a secondary setting on the pins which were not working. Start11 is only $7.40 For more information about Start11, please visit Start11 website. Disclaimer: Neowin's relationship to Stardock. Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Brave 1.80.113 by Razvan Serea Brave Browser is a lightning-fast, secure web browser that stands out from the competition with its focus on privacy, security, and speed. With features like HTTPS Everywhere and built-in tracker blocking, Brave keeps your online activities safe from prying eyes. Brave is one of the safest browsers on the market today. It blocks third-party data storage. It protects from browser fingerprinting. And it does all this by default. Speed - Brave is built on Chromium, the same technology that powers Google Chrome, and is optimized for speed, providing a fast and responsive browsing experience. Brave Browser also features Brave Rewards, a system that rewards users with Basic Attention Tokens (BAT) for viewing opt-in ads. This innovative system provides an alternative revenue model for content creators and a way to support the Brave community. Brave 1.80.113 changelog: Web3 Implemented stricter wallet routing and added a 404 page for an invalid route. (#45684) Updated opt-in screen for Meld to fit on small screen sizes. (#44318) Removed the “Edit” gas button for Zcash transactions. (#45748) Fixed crash which occurred when trying to render Brave Wallet image in certain cases. (#46828) Fixed “Search” icon being cut off on the “Explore” page. (#44950) Leo Added support for automatic default model. (#45954) Added loading spinner to display when uploading image attachments. (#45889) Improved image attachment UI. (#45672) Removed Mixtral from the default Leo model list. (#46406) Fixed attachment thumbnail image not being displayed correctly. (#45916) Rewards Updated dark mode color theme for Rewards UI. (#45741) General Added the ability to open Progressive Web Apps (PWAs) in a tabbed window. (#45435) Updated extension import to warn the user to close Chrome if opened during import attempt. (#44945) Updated extension import to import both “IndexedDB” and “Local Extension Storage” when present for an extension. (#44946) Updated buttons on interstitial pages to use Brave theme. (#45666) Removed the password check box from brave://settings/importData dialog when importing from Chrome. (#46206) Fixed crash which occurred when moving a tab across monitors. (#46066) Fixed issue with “:matches-path” being used at the beginning of a filter rule. (#46220) Fixed display of long keyboard shortcuts on brave://settings/system/shortcuts. (#41873) Fixed “Toggle Vertical Tabs Expanded” keyboard shortcut not working when “Expand Vertical Tabs Independently per Window” is enabled. (#41074) Upgraded Chromium to 138.0.7204.49. (#47094) Download: Brave Browser 64-bit | 1.2 MB (Freeware) Download: Brave Browser 32-bit View: Brave Homepage | Offline Installers | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Google releases Gemma 3n, a new AI model built for mobile devices by David Uzondu Google has announced Gemma 3n, the next generation of its open AI models, and it is a significant step up from what we saw before. After a preview last month at Google I/O, the full version is now here and ready to run directly on your hardware. For those of you who are not aware, Gemma is a family of open AI models. It is different from Gemini in that it is designed for developers to download and modify, whereas Gemini is Google's closed, proprietary powerhouse. The model can now natively process inputs like images, audio, and video to generate text, a leap from just being a text-based model. It can also run on hardware with as little as 2GB of memory, and is supposedly better at tasks like coding and reasoning. Here's the full list of improvements as outlined by Google: Multimodal by design: Gemma 3n natively supports image, audio, video, and text inputs and text outputs. Optimized for on-device: Engineered with a focus on efficiency, Gemma 3n models are available in two sizes based on effective parameters: E2B and E4B. While their raw parameter count is 5B and 8B respectively, architectural innovations allow them to run with a memory footprint comparable to traditional 2B and 4B models, operating with as little as 2GB (E2B) and 3GB (E4B) of memory. Groundbreaking architecture: At its core, Gemma 3n features novel components like the MatFormer architecture for compute flexibility, Per Layer Embeddings (PLE) for memory efficiency, and new audio and MobileNet-v5 based vision encoders optimized for on-device use cases. Enhanced quality: Gemma 3n delivers quality improvements across multilinguality (supporting 140 languages for text and multimodal understanding of 35 languages), math, coding, and reasoning. The core of its efficiency is a new architecture Google calls MatFormer. Google uses the analogy of a Russian Matryoshka doll to describe it: a larger model contains a smaller, fully functional version inside. This allows a single model to run at different sizes for different tasks. And as for benchmarks, the larger E4B model is the first model under 10B parameters to break a LMArena score of 1300. The model's audio capabilities now support on-device speech-to-text and translation, using an encoder that can process speech in fine detail. The vision side of things is powered by a new encoder called MobileNet-V5, which is much faster and more efficient than its predecessor. It can process video at up to 60FPS on a Google Pixel device. If you're interested, you can start playing with it immediately as the models are available through familiar platforms like Hugging Face and Kaggle, and you can even experiment with them directly in Google AI Studio. More details can be found in the official announcement post.
    • Bitdefender Antivirus Free 27.0.53.265 by Razvan Serea Bitdefender Antivirus Free is a free antivirus software especially designed to protect your Windows PC. Quick to install and light on computer resources, it is good for gaming, image and video editing, and resource-intensive applications. Once you have installed Bitdefender Antivirus Free, your device is protected against all kinds of threats (such as malware, spyware, ransomware, exploits, botnets and trojans) and internet threats (such as hackers, phishing and spam). The app uses the Photon technology to enhance the speed and performance of the threat scanning process. It works by learning the usage patterns of your system apps to know what and when to scan, thus minimizing the impact on system performance. Many free antivirus solutions are as intrusive and resource-heavy as the viruses they’re supposed to stop. Only Bitdefender Antivirus Free is designed from the ground up to keep you safe without disrupting your workflow and focus. Free antivirus protection that stops even the fastest-evolving attacks Runs silently in the background and stays out of your way Impossibly light on CPU (will not slow down your computer) Live customer support included (unlike other free antivirus software) Bitdefender Antivirus 27.0.53.265 changelog: Updated Safepay version Fixed blank page issue when loading www.chewy.com in Safepay Fixed login errors on www.pcfinancial.ca in Safepay Fixed issue where websites failed to load with Encrypted Web Scan enabled Fixed issue where Search Advisor checkmarks appeared upside down Fixed duplicate notifications from Alert Mode Operating systems: Windows 7 with Service Pack 1, Windows 8.1, Windows 10 and Windows 11 Download: Bitdefender Antivirus Free 27.0.53.265 | 18.0 MB (Freeware) View: Bitdefender Antivirus Free Homepage | Release Notes | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • i built my own, all ya need is a pc with two network cards and i used operwrt as the os
  • Recent Achievements

    • One Month Later
      jfam earned a badge
      One Month Later
    • First Post
      TheRingmaster earned a badge
      First Post
    • Conversation Starter
      Kavin25 earned a badge
      Conversation Starter
    • One Month Later
      Leonard grant earned a badge
      One Month Later
    • Week One Done
      pcdoctorsnet earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      541
    2. 2
      ATLien_0
      200
    3. 3
      +FloatingFatMan
      176
    4. 4
      Michael Scrip
      145
    5. 5
      snowy owl
      113
  • Tell a friend

    Love Neowin? Tell a friend!