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

258
Visualizações
Script working to pass POST var to PHP until filename change

any thoughts would be greatly appreciated. This is my first post. I've always been able to find answers from previous posts. I'm absolutely baffled now, so here it goes.

I have a simple script inside a html doc that sends a value to a php file that adds a few strings of text to a text file. The script sends the name of the page so I can count page hits. I haven't done any error catching, etc., I'm just trying to see how the basics work (I've programmed plenty, but I'm completely new to html, javascript, and php). Everything was working.

Then, I copied the php file, renamed it, and updated the script link with the new file name. No problem, right?--I just wanted a different file name than my test file name. sigh. With the new filename, the process isn't working.

I have the html file in a folder (like the Desktop). The php file is in a folder in XAMPP (I'm using Apache to simulate server). I've changed a few things, like adding COR allow to .htaccess file, and some other allowances. Again, all I did is try to copy the php file and rename it. You can see the filename is "numofhitscopy.php" When I copied the file and renamed it to "hitcounter.php and updated that in the link below, it stopped working. Here is the code...(the script is inside an html doc with the appropriate heading info. The php code is the exact same in both php files.)

<script type="text/javascript">
var xhr = new XMLHttpRequest();
var param = 'value='+"home";
xhr.open('POST', 'http://localhost:80/Appeljacks/numofhitscopy.php', true);
//Send the proper header information along with the request
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.send(param);
</script>

<?php
//Had to change php.ini file; below didn't work.
//date_default_timezone_set('America/Chicago');
$temp=$_POST['value'];
$dandt=date("Y-m-d h:i:s A");
$user_ip=$_SERVER['REMOTE_ADDR'];

$fp = fopen("page_counter.txt", "a");
fwrite($fp,$user_ip.",".$temp.",".$dandt."\r\n");
fclose($fp);
?>

Typical output in page_counter file:

127.0.0.1,home,2021-12-16 12:18:16 PM
127.0.0.1,home,2021-12-16 12:22:49 PM
127.0.0.1,home,2021-12-16 12:22:51 PM

about 4 years ago · Juan Pablo Isaza
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