Προς το περιεχόμενο

mipws kaneis mporei na mou pei pws mporw na ftiaksw enan aplo aplo counter gia websid


ktziavos

Προτεινόμενες αναρτήσεις

Δημοσ.

σε php θα χρησιμοποιοησεις 3 αρχεια:

 

counter.inc - ο κωδιακας που χρειαζεσαι

count.dat - ενα απλο txt για να μπαινουν να νουμερα

index.php - μεσα στην σελιδα θα βαλεις τον κωδικα που θα φορτωνεις το counter.inc

 

counter.inc

 

><?php

// the path of the counter log file
$logpath = 'count.dat';

// amount of digits to use in the counter when displayed
$pad = 5;

// open the log file (if it exists) and read in the current count
if (file_exists($logpath)) {
$count = file_get_contents($logpath);
}else{ // else if it does not exist, the initial count will be 0
$count = 0;
}

// increment the count by 1
$count++;

// open the log file for writing, ensuring that it has been locked for
// writing before doing so.
// note that if the file does not already exist, an attempt will be made to create it!
$file = fopen($logpath, 'w'); // the 'w' indicates writing mode
if (flock($file, LOCK_EX)) { // do an exclusive lock
fwrite($file, $count); // write out the updated count
flock($file, LOCK_UN); // release the lock
}
fclose($file);

// set the zero padding for the count to the value defined previously, then
// display the count onscreen.
$count = str_pad($count, 5, '0', STR_PAD_LEFT);
echo $count;

?>

 

και στο index θα βαλεις αυτο:

 

><html>
<head>
<title>Μετρητης</title>

<style type="text/css">
p {font-family:"Century Gothic", "Sans Serif"; font-size:12pt; color:black;}
</style>
</head>

<body>
<br>
<br>
<br>
<p>εισαι το νουμερο <?php include 'counter.inc'; ?> </p>
</body>
</html>

Αρχειοθετημένο

Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.

  • Δημιουργία νέου...