Gå til innhold

Litt prob. med en selvlaget php-teller


Anbefalte innlegg

Den er jo ikke ferdig da.

Her er problemet:

 

 

leseinniarray.php

<?php
$lines = file('ulike.txt');
$T = "0";
  foreach ($lines as $line_num => $line) {
  $linje[$T] = "$line";
  $T ++;}
?>

Leser det som er i ulike.txt inn i et array.

 

iarray.php

<?php
include 'leseinniarray.php';
$iarray = sizeof($linje);
?>

Måler størrelsen på arrayet fra leseinniarray.php.

 

index.php

<?php
include 'leseinniarray.php';
$key = array_search($_SERVER[REMOTE_ADDR],$linje);
$dato = date(d);
if ($key == "") {
$filename = 'like.txt';
$someconten = $_SERVER[REMOTE_ADDR];
$somecontent = "$someconten\n";
if (is_writable($filename)) {
  if (!$handle = fopen($filename, 'a')) {
        echo "Cannot open file ($filename)";
        exit;
  }
  if (fwrite($handle, $somecontent) === FALSE) {
      echo "Cannot write to file ($filename)";
      exit;
  }

  echo "Success, wrote ($somecontent) to file ($filename)";

  fclose($handle);

} else {
  echo "The file $filename is not writable";
}

$filename = 'ulike.txt';
$someconten = $_SERVER[REMOTE_ADDR];
$somecontent = "$someconten\n";
if (is_writable($filename)) {
  if (!$handle = fopen($filename, 'a')) {
        echo "Cannot open file ($filename)";
        exit;
  }
  if (fwrite($handle, $somecontent) === FALSE) {
      echo "Cannot write to file ($filename)";
      exit;
  }

  echo "Success, wrote ($somecontent) to file ($filename)";

  fclose($handle);

} else {
  echo "The file $filename is not writable";
}
$filename = 'datol.txt';
$somecontent = "$dato\n";
if (is_writable($filename)) {
  if (!$handle = fopen($filename, 'a')) {
        echo "Cannot open file ($filename)";
        exit;
  }
  if (fwrite($handle, $somecontent) === FALSE) {
      echo "Cannot write to file ($filename)";
      exit;
  }

  echo "Success, wrote ($somecontent) to file ($filename)";

  fclose($handle);

} else {
  echo "The file $filename is not writable";
}

$filename = 'datou.txt';
$somecontent = "$dato\n";
if (is_writable($filename)) {
  if (!$handle = fopen($filename, 'a')) {
        echo "Cannot open file ($filename)";
        exit;
  }
  if (fwrite($handle, $somecontent) === FALSE) {
      echo "Cannot write to file ($filename)";
      exit;
  }

  echo "Success, wrote ($somecontent) to file ($filename)";

  fclose($handle);

} else {
  echo "The file $filename is not writable";
}   }

//------------------------------------------------------------------------------
elseif ($key != "") {
$filename = 'like.txt';
$someconten = $_SERVER[REMOTE_ADDR];
$somecontent = "$someconten\n";
if (is_writable($filename)) {
  if (!$handle = fopen($filename, 'a')) {
        echo "Cannot open file ($filename)";
        exit;
  }
  if (fwrite($handle, $somecontent) === FALSE) {
      echo "Cannot write to file ($filename)";
      exit;
  }

  echo "Success, wrote ($somecontent) to file ($filename)";

  fclose($handle);

} else {
  echo "The file $filename is not writable";
}

$filename = 'datol.txt';
$somecontent = "$dato\n";
if (is_writable($filename)) {
  if (!$handle = fopen($filename, 'a')) {
        echo "Cannot open file ($filename)";
        exit;
  }
  if (fwrite($handle, $somecontent) === FALSE) {
      echo "Cannot write to file ($filename)";
      exit;
  }

  echo "Success, wrote ($somecontent) to file ($filename)";

  fclose($handle);

} else {
  echo "The file $filename is not writable";
} }
echo "|$key|"
?>

Skriver ip-adressen i like.txt og datoen i datol.txt hvis ip-adressen til brukeren allerede er i ulike.txt eller så skriver det ip-adressen i like.txt og ulike.txt

og skriver datoen i datou.txt og datol.txt.

Det som skjer er at if'en alltid slår ut uansett og elseif'en aldri skjer.

 

 

For da å hente hvor mange sidevisninger teller jeg bare linjer i like.txt.

For da å hente hvor mange unike besøkere teller jeg bare linjer i ulike.txt.

For da å hente hvor mange sidevisninger i dag teller jeg linjer med datoen i dag i datol.txt.

For da å hente hvor mange unike besøkere i dag teller jeg linjer med datoen i dag i datou.txt.

 

ulike.txt, like.txt, datol.txt og datou.txt er selfølgelig tomme nå.

 

Noen som har bedre forslag å gjøre det på, noen forslag til noen forbedringer eller noen som ser noen feil?

Endret av Raring
Lenke til kommentar
Videoannonse
Annonse

Har du siden din oppe lenge nok, er det niks problem å få 5K besøkende. Hvorfor ikke bare bruke en fil til lagring av ip og user-agent elns. og ha en fil som bare har et tall for antall besøkende? Hver dag kl. 12:00 kan det kjøres en prosess som teller linjer i den ene filen og skriver det til den andre filen. Dette er altså bare hvis du vil ha en avansert teller, og ikke vil ha en enkel sak som bare teller treff.

 

 

Evt. kunne du bare skaffet deg mySQL, og sluppet disse problemene. :p

Endret av jorgenindahouse
Lenke til kommentar

Hva er feil her?

 

<?php
$conn = mysql_connect("freesql.org", "*******", "*******");
mysql_select_db("database");
$result = mysql_query("select * from Telefonliste");
while ($row = mysql_fetch_array($result)) {
 echo $row["Navn"];
}
mysql_close($conn);
?>

 

jeg får opp:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in d:\inetpub\wwwroot\servertest.php on line 5

Endret av Raring
Lenke til kommentar

Hadde jeg vært deg så hadde jeg skrevet

or die(mysql_error());

etter alle spørringer du tar (mysql_query()or die();), så kommer det fram om det er din mysql_query(); eller mysql_fetch_array(); som driver å tuller.

 

edit: ikke lett å skrive php med smilies aktivert :p

Endret av LoS
Lenke til kommentar

Syns det blir alt for rotete hvis jeg skal bruke code taggen til dette hver gang jeg skal forklare noe.

 

Anyways, back to topic!

 

Prøv denne koden og si hvilken feilmelding som kommer fram:

<?php
$conn = mysql_connect("freesql.org", "*******", "*******");
mysql_select_db("database");
$result = mysql_query("select * from Telefonliste")or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
echo $row["Navn"];
}
mysql_close($conn);
?>

 

PHP tag hadde vært noe ja :dribble:

Endret av LoS
Lenke til kommentar

Warning: Access denied for user: '[email protected]' (Using password: YES) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 2

 

Warning: MySQL Connection Failed: Access denied for user: '[email protected]' (Using password: YES) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 2

 

Warning: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 3

 

Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 3

 

Warning: MySQL: A link to the server could not be established in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 3

 

Warning: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 4

 

Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 4

 

Warning: MySQL: A link to the server could not be established in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 4

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

 

Dette er feilmeldingen jeg får da.

 

 

mySQL(hvordan uttales det??)

may-ess-ku-ell :thumbup:

Takk!

Lenke til kommentar

Nå får jeg:

 

 

Warning: Unknown MySQL Server Host 'http' (1) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 2

 

Warning: MySQL Connection Failed: Unknown MySQL Server Host 'http' (1) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 2

 

Warning: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 3

 

Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 3

 

Warning: MySQL: A link to the server could not be established in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 3

 

Warning: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 4

 

Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 4

 

Warning: MySQL: A link to the server could not be established in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 4

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Lenke til kommentar

Når jeg skriver http://fresql.org får jeg:

 

 

Warning: Unknown MySQL Server Host 'http' (1) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 2

 

Warning: MySQL Connection Failed: Unknown MySQL Server Host 'http' (1) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 2

 

Warning: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 3

 

Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 3

 

Warning: MySQL: A link to the server could not be established in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 3

 

Warning: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 4

 

Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 4

 

Warning: MySQL: A link to the server could not be established in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 4

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Lenke til kommentar

Når jeg skriver http://fresql.org får jeg:

 

 

Warning: Unknown MySQL Server Host 'http' (1) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 2

 

Warning: MySQL Connection Failed: Unknown MySQL Server Host 'http' (1) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 2

 

Warning: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 3

 

Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 3

 

Warning: MySQL: A link to the server could not be established in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 3

 

Warning: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 4

 

Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 4

 

Warning: MySQL: A link to the server could not be established in /mnt/home4/h/hb/hbhb1/public_html/servertest.php on line 4

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
×
×
  • Opprett ny...