Skip to main content
replaced http://security.stackexchange.com/ with https://security.stackexchange.com/
Source Link

Let's see the code:

  1. Your Session class does too many things:

    • Session management
    • Login
    • Data validation
    • Logout
    • Authentication
    • Inclusion management
  2. Your class has no clean way to destroy a session.

  3. You don't verify if a session is active.

  4. Your constructor seems a little off. Sessions are a singleton. Use a single static final class.

  5. You don't need to repeat public on every method;

  6. You are storing a class on a $_SESSION. I would avoid that like plague. You should start and end the session. And you should have a method to save the session (that runs session_write_close() on shutdown or at any given time).

  7. There's no way to check if a session was opened before or not, or if it was saved already or not.

Fixing these points and splitting your code into classes that do each thing in separate will make your code better in every conceivable way.
A while ago I've used JSON to store the session data. It generates files a bit longer, but it is faster to save. Consider making your own session management system, based out on PHP's way.
Since HDD is cheaper than CPU cycles, I would consider using such way to load/save your sessions.
Completely outside the scope of this review, you could use a RAMdisk with the /tmp partition to squeeze every tiny piece of performance you get. Use only 10% of your RAM for such purpose.


Before doing anything to store your password, I recommend a good read:
How to securely hash passwords?How to securely hash passwords?

One of the points is that you shouldn't use SHA1, but instead use bcrypt or password_verify (PHP5.6 and up) in the future.

Also, you should be extremely careful with SQL injection and other possible attacks, especially evolving different encodings.
I sound paranoid, and I know that. But I just want a safe code.

Let's see the code:

  1. Your Session class does too many things:

    • Session management
    • Login
    • Data validation
    • Logout
    • Authentication
    • Inclusion management
  2. Your class has no clean way to destroy a session.

  3. You don't verify if a session is active.

  4. Your constructor seems a little off. Sessions are a singleton. Use a single static final class.

  5. You don't need to repeat public on every method;

  6. You are storing a class on a $_SESSION. I would avoid that like plague. You should start and end the session. And you should have a method to save the session (that runs session_write_close() on shutdown or at any given time).

  7. There's no way to check if a session was opened before or not, or if it was saved already or not.

Fixing these points and splitting your code into classes that do each thing in separate will make your code better in every conceivable way.
A while ago I've used JSON to store the session data. It generates files a bit longer, but it is faster to save. Consider making your own session management system, based out on PHP's way.
Since HDD is cheaper than CPU cycles, I would consider using such way to load/save your sessions.
Completely outside the scope of this review, you could use a RAMdisk with the /tmp partition to squeeze every tiny piece of performance you get. Use only 10% of your RAM for such purpose.


Before doing anything to store your password, I recommend a good read:
How to securely hash passwords?

One of the points is that you shouldn't use SHA1, but instead use bcrypt or password_verify (PHP5.6 and up) in the future.

Also, you should be extremely careful with SQL injection and other possible attacks, especially evolving different encodings.
I sound paranoid, and I know that. But I just want a safe code.

Let's see the code:

  1. Your Session class does too many things:

    • Session management
    • Login
    • Data validation
    • Logout
    • Authentication
    • Inclusion management
  2. Your class has no clean way to destroy a session.

  3. You don't verify if a session is active.

  4. Your constructor seems a little off. Sessions are a singleton. Use a single static final class.

  5. You don't need to repeat public on every method;

  6. You are storing a class on a $_SESSION. I would avoid that like plague. You should start and end the session. And you should have a method to save the session (that runs session_write_close() on shutdown or at any given time).

  7. There's no way to check if a session was opened before or not, or if it was saved already or not.

Fixing these points and splitting your code into classes that do each thing in separate will make your code better in every conceivable way.
A while ago I've used JSON to store the session data. It generates files a bit longer, but it is faster to save. Consider making your own session management system, based out on PHP's way.
Since HDD is cheaper than CPU cycles, I would consider using such way to load/save your sessions.
Completely outside the scope of this review, you could use a RAMdisk with the /tmp partition to squeeze every tiny piece of performance you get. Use only 10% of your RAM for such purpose.


Before doing anything to store your password, I recommend a good read:
How to securely hash passwords?

One of the points is that you shouldn't use SHA1, but instead use bcrypt or password_verify (PHP5.6 and up) in the future.

Also, you should be extremely careful with SQL injection and other possible attacks, especially evolving different encodings.
I sound paranoid, and I know that. But I just want a safe code.

Fixed some bugs on my brain -.-
Source Link
Ismael Miguel
  • 6.1k
  • 2
  • 23
  • 62

Let's see the code:

  1. Your Session class does too many things:

    • Session management
    • Login
    • Data validation
    • Logout
    • Authentication
    • Inclusion management
  2. Your class has no clean way to destroy a session.

  3. You don't verify if a session is active.

  4. Your constructor seems a little off. Sessions are a singleton. Use a single static final class.

  5. You don't need to repeat public on every method;

  6. You are storing a class on a $_SESSION. I would avoid that like plague. You should start and end the session. And you should have a method to save the session (that runs session_write_close() on shutdown or at any given time).

  7. There's no way to check if a session was opened before or not, or if it was saved already or not.

Fixing these points and splitting your code into classes that do each thing in separate will make your code better in every conceivable way.
A while ago I've used JSON to store the passwordsession data. It generates files a bit longer, but it is faster to save. Consider making your own session management system, based out on PHP's way.
Since HDD is cheaper than CPU cycles, I would consider using such way to load/save your sessions.
Completely outside the scope of this review, you could use a RAMdisk with the /tmp partition to squeeze every tiny piece of performance you get. Use only 10% of your RAM for such purpose.


Before doing anything to store your password, I recommend a good read:
How to securely hash passwords?

One of the points is that you shouldn't use SHA1, but instead use bcrypt or password_verify (PHP5.6 and up) in the future.

Also, you should be extremely careful with SQL injection and other possible attacks, especially evolving different encodings.
I sound paranoid, and I know that. But I just want a safe code.

Let's see the code:

  1. Your Session class does too many things:

    • Session management
    • Login
    • Data validation
    • Logout
    • Authentication
    • Inclusion management
  2. Your class has no clean way to destroy a session.

  3. You don't verify if a session is active.

  4. Your constructor seems a little off. Sessions are a singleton. Use a single static final class.

  5. You don't need to repeat public on every method;

  6. You are storing a class on a $_SESSION. I would avoid that like plague. You should start and end the session. And you should have a method to save the session (that runs session_write_close() on shutdown or at any given time).

  7. There's no way to check if a session was opened before or not, or if it was saved already or not.

Fixing these points and splitting your code into classes that do each thing in separate will make your code better in every conceivable way.
A while ago I've used JSON to store the password. It generates files a bit longer, but it is faster to save. Consider your own session management system, based out on PHP's way.
Since HDD is cheaper than CPU cycles, I would consider using such way to load/save your sessions.
Completely outside the scope of this review, you could use a RAMdisk with the /tmp partition to squeeze every tiny piece of performance you get. Use only 10% of your RAM for such purpose.


Before doing anything to store your password, I recommend a good read:
How to securely hash passwords?

One of the points is that you shouldn't use SHA1, but instead use bcrypt or password_verify (PHP5.6 and up) in the future.

Also, you should be extremely careful with SQL injection and other possible attacks, especially evolving different encodings.
I sound paranoid, and I know that. But I just want a safe code.

Let's see the code:

  1. Your Session class does too many things:

    • Session management
    • Login
    • Data validation
    • Logout
    • Authentication
    • Inclusion management
  2. Your class has no clean way to destroy a session.

  3. You don't verify if a session is active.

  4. Your constructor seems a little off. Sessions are a singleton. Use a single static final class.

  5. You don't need to repeat public on every method;

  6. You are storing a class on a $_SESSION. I would avoid that like plague. You should start and end the session. And you should have a method to save the session (that runs session_write_close() on shutdown or at any given time).

  7. There's no way to check if a session was opened before or not, or if it was saved already or not.

Fixing these points and splitting your code into classes that do each thing in separate will make your code better in every conceivable way.
A while ago I've used JSON to store the session data. It generates files a bit longer, but it is faster to save. Consider making your own session management system, based out on PHP's way.
Since HDD is cheaper than CPU cycles, I would consider using such way to load/save your sessions.
Completely outside the scope of this review, you could use a RAMdisk with the /tmp partition to squeeze every tiny piece of performance you get. Use only 10% of your RAM for such purpose.


Before doing anything to store your password, I recommend a good read:
How to securely hash passwords?

One of the points is that you shouldn't use SHA1, but instead use bcrypt or password_verify (PHP5.6 and up) in the future.

Also, you should be extremely careful with SQL injection and other possible attacks, especially evolving different encodings.
I sound paranoid, and I know that. But I just want a safe code.

Very minor tweaks.
Source Link
user34073
user34073

LetsLet's see the code:

  1. Your Session class does too many things:

    • Session management
    • Login
    • Data validation
    • Logout
    • Authentication
    • Inclusion management
  2. Your class has no clean way to destroy a session;session.

  3. You don't verify if a session is active;active.

  4. Your constructor seems a little off. Sessions are a singleton. Use a single static final class;class.

  5. You don't need to repeat public on every method;

  6. You are storing a class on a $_SESSION. I would avoid that like plague. You should start and end the session. And you should have a method to save the session (that runs session_write_close() on shutdown or at any given time);.

  7. There's no way to check if a session was opened before or not, or if it was saved already or not.

Fixing these points and splitting your code into classes that do each thing in separate will make your code better in every conceivable way.
A while ago I've used JSON to store the password. It generates files a bit longer, but it is faster to save. Consider your own session management system, based out on PHP's way.
Since HDD is cheaper than CPU cycles, I would consider using such way to load/save your sessions.
Completely outside the scope of this review, you could use a RAMdisk with the /tmp partition to squeeze every tiny piece of performance you get. Use only 10% of your RAM for such purpose.


Before doing anything to store your password, I recommend a good read:
How to securely hash passwords?

One of the points is that you shouldn't use SHA1, but instead use bcrypt or password_verify (PHP5.6 and up) in the future.

Also, you should be extremely careful with SQL injection and other possible attacks, speciallyespecially evolving different encodings.
I sound paranoid, and I know that. But I just want a safe code.

Lets see the code:

  1. Your Session class does too many things:

    • Session management
    • Login
    • Data validation
    • Logout
    • Authentication
    • Inclusion management
  2. Your class has no clean way to destroy a session;

  3. You don't verify if a session is active;

  4. Your constructor seems a little off. Sessions are a singleton. Use a single static final class;

  5. You don't need to repeat public on every method;

  6. You are storing a class on a $_SESSION. I would avoid that like plague. You should start and end the session. And you should have a method to save the session (that runs session_write_close() on shutdown or at any given time);

  7. There's no way to check if a session was opened before or not, or if it was saved already or not.

Fixing these points and splitting your code into classes that do each thing in separate will make your code better in every conceivable way.
A while ago I've used JSON to store the password. It generates files a bit longer, but it is faster to save. Consider your own session management system, based out on PHP's way.
Since HDD is cheaper than CPU cycles, I would consider using such way to load/save your sessions.
Completely outside the scope of this review, you could use a RAMdisk with the /tmp partition to squeeze every tiny piece of performance you get. Use only 10% of your RAM for such purpose.


Before doing anything to store your password, I recommend a good read:
How to securely hash passwords?

One of the points is that you shouldn't use SHA1, but instead use bcrypt or password_verify (PHP5.6 and up) in the future.

Also, you should be extremely careful with SQL injection and other possible attacks, specially evolving different encodings.
I sound paranoid, and I know that. But I just want a safe code.

Let's see the code:

  1. Your Session class does too many things:

    • Session management
    • Login
    • Data validation
    • Logout
    • Authentication
    • Inclusion management
  2. Your class has no clean way to destroy a session.

  3. You don't verify if a session is active.

  4. Your constructor seems a little off. Sessions are a singleton. Use a single static final class.

  5. You don't need to repeat public on every method;

  6. You are storing a class on a $_SESSION. I would avoid that like plague. You should start and end the session. And you should have a method to save the session (that runs session_write_close() on shutdown or at any given time).

  7. There's no way to check if a session was opened before or not, or if it was saved already or not.

Fixing these points and splitting your code into classes that do each thing in separate will make your code better in every conceivable way.
A while ago I've used JSON to store the password. It generates files a bit longer, but it is faster to save. Consider your own session management system, based out on PHP's way.
Since HDD is cheaper than CPU cycles, I would consider using such way to load/save your sessions.
Completely outside the scope of this review, you could use a RAMdisk with the /tmp partition to squeeze every tiny piece of performance you get. Use only 10% of your RAM for such purpose.


Before doing anything to store your password, I recommend a good read:
How to securely hash passwords?

One of the points is that you shouldn't use SHA1, but instead use bcrypt or password_verify (PHP5.6 and up) in the future.

Also, you should be extremely careful with SQL injection and other possible attacks, especially evolving different encodings.
I sound paranoid, and I know that. But I just want a safe code.

Removed security stuff, as adviced on chat, improved and more advices.
Source Link
Ismael Miguel
  • 6.1k
  • 2
  • 23
  • 62
Loading
Source Link
Ismael Miguel
  • 6.1k
  • 2
  • 23
  • 62
Loading