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

80
Visualizações
PHP doesn't see a cookie unless I refresh the page again

I know there are other questions like this on here, but I've read through the answers and I'm still not finding a solution to my issue.

All of these scripts are on the same page, search-results.

It shows results in data-tables, and lets the user select records to save to a list, which they can then print. The IDs of the selected records are stored in a records cookie. I can see that this works.

There's a link at the bottom of the page that fires this JS function:

function resultsPage(){
    window.location = "/search-results/?printqueue=true";
}

As you can see, this is the same page, but with a different parameter. This tells the page to display their saved results.

On the initial load with ?printqueue=true PHP cannot read the cookie, even tho the page has refreshed. I have to refresh (or click the link) AGAIN before PHP picks up the cookie. Why?

I'm getting the cookie data like this:

if( $_GET['printqueue'] == 'true' && $_COOKIE['records'] !== 'undefined' ) {
    $posts_to_show = explode(',',$_COOKIE['records']);
}

If that's just because of the order of operations, that's cool, nothing to do about it then. But any clean ways to "double refresh" the page without adding an extra parameter and refreshing again if it's present? I'd really hate to do that...

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I beleieve its becouse $_COOKIE['records'] is not set yet..

Try:

if( $_GET['printqueue'] == 'true' &&  isset($_COOKIE['records']) ) {
    // your code
}
about 4 years ago · Juan Pablo Isaza 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