Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

359
Visualizações
How to create a PHP script that will generate new text daily?

I've researched this a lot but can't find a satisfactory answer; how do I create a PHP script that will generate a new number each day? Obviously I'm using this for a reason other than to generate a random number daily, but I won't go into that reason, it'll just make this question more complicated. So I'm asking this: How do I generate a random number which will change each day in PHP? Using MySQL will be no problem, but it must be automatic so I won't have to manually change it daily. (Here's my 'script' to generate a random number)

<?php
echo rand(1,100)
?>

Any answers are appreciated, Thanks - Hugh

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Use time() function to generate seed, then use regular rand. This way you should't to store it anywhere and you always can regenerate it when needed.

function randomEveryDay()
{
    $now = time();
    $today = $now - ($now % 86400); //86400 = 1 day in seconds
    srand($today);
    return rand();
}

Or more interesting example without random at all.

function randomEveryDay() {
    $now = time();
    $today = $now - ($now % 86400);
    $hash = sha1('salt string'.$today);
    return intval('0x' . substr($hash, 6, 8));
}

Every day you will get the same number in $today, then use any cryptographic\non cryptographic hash function to generate "random".

over 4 years ago · Santiago Trujillo Relatório

0

This is fairly a simple task as long as you understand the basics of crontabs.

Step One: Create the script. This is basically going to be what creates the "text" then inputs it into the database via mysqli. For example, if we are generating a random number, what you have so far is good, you will just need to insert it into a database table. I recommend using a time stamp to give what day it was generated on

Step Two: Create a cronjob. Use the servers crontab to run a task every day, this can be done by adding this to the cron file: This will run a cron each new day.

00 01 * * * php path/to/your/generate.php

Step Three Fetch result from database by using the current date. If you are needing to display that text, pull it from the database using whatever the current day is from date() or DateTime

over 4 years ago · Santiago Trujillo Relatório

0

It's impossible to give a good answer without knowing exactly what you want to do, so this will generate a new number every day:

echo date('Ymd');
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda