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 8678017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:36:22+00:00 2026-06-12T20:36:22+00:00

Does anyone know how to generate a long (e.g. 280 characters) random string in

  • 0

Does anyone know how to generate a long (e.g. 280 characters) random string in PHP without having to use a for loop that will loop through characters 280 times? I need it in order to create a custom session ID.

The PHPSESSID is not secure enough in my opinion being too short and not too random. I know Facebook and Twitter, use long session IDs (150, 550 chars respectively).

There could be an option to use MD5 strings or Bcrypt encryption of different string such as PHPSESSID, host, User-Agent etc. but I’m not sure this is the right way of doing it.

  • 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-12T20:36:23+00:00Added an answer on June 12, 2026 at 8:36 pm

    If you’re asking a question like that, it probably means you don’t know anything about cryptography or security. Trying to generate a “long random string” because, as you say, “The PHPSESSID is not secure enough” will probably lead you to a custom and insecure implementation.

    Generating a random string is IMPOSSIBLE, at least not with your current hardware: you may approximate a fair pseudorandom generator but that is only useful for educational purposes.

    PHP’s Session ID generation algorithm is fairly efficient; if you think it is not secure enough, then you’ll likely waste time making it better. You may probably want to use a different authentication mechanism if you are looking at maximum security (using a client certificate for example).

    If websites such as Twitter, Facebook, or another site with similar traffic use longer session IDs, it may be not because it is more secure (well in a way), but rather because it avoids conflicts.

    Finally, if you want a longer session ID without trying to write your own algorithm, you should use the following PHP configuration directive:

    session.hash_function which can take any hash algorithm known by PHP.

    You may also want to use session.bits_per_characters to shorten or lengthen the string. Note that if you do this, the string may be longer or shorter, but the data remains the same — only represented differently (base 16, base 32, etc.)

    Additional info:

    You may also increase the entropy by using a custom source (file) and setting the length of the seed:

    ini_set("session.hash_function", "sha512");
    ini_set("session.bits_per_charater", 4); // 4 means hex
    ini_set("session.entropy_file", "/dev/urandom");
    ini_set("session.entropy_length", "512");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how facebook connect buttons generate the pop-up window that you use
Does anyone know a C# framework that can generate public/private keys, X.509 certificates and
Does anyone know why the following random distributions of matrices generate different plots? (This
Does anyone know of any websites, or (preferably) downloadable packages that you can use
Does anyone know of a tool that can inspect a specified schema and generate
does anyone know a simple way to generate a random 64 bit number using
Does anyone know an easy way to generate a checksum for a String on
Does anyone know of an app that would generate an xml file filled out
Does anyone know an API or other method that I could generate a short
Does anyone know of a rake task or RSpec call that will generate a

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.