Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8161777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:34:15+00:00 2026-06-06T18:34:15+00:00

Regarding PHP security with cookies and sessions, this is what i have done so

  • 0

Regarding PHP security with cookies and sessions, this is what i have done so far for prevention of attacks. What have i done incorrectly/unsafely?

login.php

 if ($username==$dbusername&&$hashed_password==$dbpassword){

setcookie('username[0]',$username,time()+(60*60*24*365));
setcookie('username[1]',$userid,time()+(60*60*24*365));
setcookie('password',$hashed_password,time()+(60*60*24*365));

if($admin=='1') {
setcookie('username[3]',$admin,time()+(60*60*24*365));  
}
$_SESSION['logged-in']=1;

logout.php

    $time = time()-(60*60*24*365);
setcookie('username[0]', '',$time);
setcookie('username[1]', '',$time);
setcookie('username[2]', '',$time);
setcookie('username[3]', '',$time);
setcookie('password', '',$time);
unset($_COOKIE['username']); 
unset($_SESSION['logged-in']);

I call session_regenerate_id() on everypage, is that correct to stop session fixation/hijacking?

<?php session_start(); session_regenerate_id();

Here is my PHP.ini what other ways do i provide security for sessions & cookies

    session.use_trans_sid = 0
session.user_only_cookies = 1

Any examples/impovements welcomed, as i learn better with examples.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:34:16+00:00Added an answer on June 6, 2026 at 6:34 pm

    Often regenerating the session-id is done, when changing access priviledges (e.g. after a login).

    The password should not be stored in a cookie on the client side, not even the hash. It’s not even necessary to store it in the session, you use it only to verify the login, and after writing the state to the session, you should forget about the password.

    If you want a really safe site, you need a HTTPS connection with SSL encryption. Otherwise an attacker can eavesdrop the information sent plaintext, and use the session-id (or whatever you use to authenticate the user) to impersonate the user.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is this is far as you would go regarding Object Oriented PHP or can
I have a question regarding static function in php. let's assume that I have
This question is regarding getopt function in php. I need to pass two parameter
I have a question regarding the proper way to modify a php DateTime object.
I have read the PHP manual , but couldn't find any proper explanation regarding
I have a question regarding database connection in PHP and MySQL. I wonder if
I have a question regarding PHP and it's memory limit. I have an index.php
My question is simple regarding password security.. As a web application developer using PHP
I was reading this tutorial for a simple PHP login system . In the
I have been looking around the current options (and related SO questions) regarding PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.