• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

PHP Besucherzähler in CSS einfügen

_iChris_

Neues Mitglied
Hallo,

Hab ein kleines Problem bei meiner Homepage. Für einen Kenner ist das sicher keine Aufgabe, ich als Anfänger habe jedoch meine liebe Not damit meinen PHP Besucherzähler in das css Script einzufügen. Auf der Homepage wird der nämlich als Text angezeigt, und nicht wie vorgesehen nur die Besucheranzahl. Ich arbeite übrigens mit xampp... Hilft mir bitte jemand?

Danke im Voraus.

Besucherzähler:

<?php
$dateiname = "./zaehler.txt";
//Es wird geprüft, ob die Zählerdatei schon vorhanden ist
if(file_exists($dateiname))
{
//Datei existiert bereits, der Inhalt wird in ein Array geladen
$inhalt = file($dateiname);
//Der Zählwert wird aus der Zeichenkette extrahiert
$alter_wert = 0;
sscanf($inhalt[0],"%u",$alter_wert);
//Der Zählwert wird inkrementiert
$alter_wert += 1;
//Der Zählwert wird wieder als Zeichenkette konvertiert
$inhalt[0] = sprintf("%u",$alter_wert);

//Datei wird geöffnet und der neue Wert geschrieben
$fhandle = fopen($dateiname,"w");
//Es wird geprüft, ob die Datei evtl. nicht geöffnet werden konnte
if(!$fhandle)
exit(1);

//Datei konnte geöffnet werden, der neue Wert wird nun geschrieben
fputs($fhandle,$inhalt[0]);
//Datei wird geschlossen
fclose($fhandle);
$dateiname = "./zaehler.txt"; // Name der Datei
$array = file($dateiname); // Datei in ein Array einlesen
foreach ($array as $element) {
echo $element . "<br>"; // Dateiinhalt ausgeben
}
}
else
{
//Datei wird erstellt und der Wert 1 geschrieben
$fhandle = fopen($dateiname,"a");
//Es wird geprüft, ob die Datei evtl. nicht erstellt werden konnte
if(!$fhandle)
exit(1);

//Datei konnte erstellt werden, der Wert 1 wird nun geschrieben
fputs($fhandle,"1");
//Datei wird geschlossen
fclose($fhandle);
$dateiname = "./zaehler.txt"; // Name der Datei
$array = file($dateiname); // Datei in ein Array einlesen
foreach ($array as $element) {
echo $element . "<br>"; // Dateiinhalt ausgeben
}
}
?>



CSS Script:


margin: 7% auto;
padding:0px;
width:1126px;
background-image:url(img/background.jpg);
background-repeat:no-repeat;
background-attachment:fixed;
}

#main{
background:#e4e4e4;
height:1200px;
width:1126px;
}


.box1{
background-image:url(img/top.jpg);
height:250px;
width:100%;

}

/* CSS für das Menü */
.menu_container {
margin: 0 auto 20px auto;
position: relative;
width: 1126px;
height: 20px;
z-index: 100;

}
.menu, .menu ul {
padding: 0;
margin: 0;
list-style: none;
position: absolute;

}
.menu ul {
left: -9999px;
width: 125px;
padding: 0 20px 20px 20px;

}

.menu ul ul {
padding: 20px 20px 20px 0;

}

.menu a {
display: block;
width: 124px;
padding-left: 0px;
text-align: center;
font: normal bold 14px/40px arial, sans-serif;
color: #fff;
text-decoration: none;
margin: 0 -1px -1px 0;
background-color: #283daf;
color: white;
border-right: 1px solid grey;
border-left: 1px solid grey;

}
.menu li ul a {
font-weight: bold;
height:29px;
padding-top 0px;
border-bottom: 1px solid grey;
border-top: 1px solid grey;
border-right: 1px solid grey;
border-left: 1px solid grey;
background-color: white;
color: grey;
}
.menu li {
float: left;
border-right:1px


}

.menu li a {

}

.menu li:hover {
position: relative;
z-index: 100;


}
.menu li:hover > a {
background-color: #000080;
color: white;



}
.menu li:hover > ul {
top: 40px;
left: -20px;
z-index: -1;


}
.menu li:hover li:hover > a {
background-color:#e4e4e4;
color: #000080;
border: 2px solid grey;



}
.menu li:hover li:hover > ul {
left: 145px;
top: -20px;
z-index: 100;
}
.menu li.right:hover li:hover > ul {
left: -165px;
top: -20px;
z-index: 100;
padding: 20px 0 20px 20px;
}


.box3{
background-image:url(img/transition.jpg);
float:left;
padding:0px;
width:19%;
height:900px;
margin:5px;
}

.flashclass{ /*sample CSS class added to image slideshow container*/
width: 200px; /*a width should be defined for transition to work*/
margin: 50px auto;
}

.flashclass img{
border-width: 0;
}

.animclass{ /*sample CSS class added to image slideshow container*/
width: 200px; /*a width should be defined for transition to work*/
margin: 5px auto;
}

.animclass img{
border-width: 0;
}

.box4{
background:darkgray;
float:left;
margin:5px;
padding:0px;
}

.box5{
background:gray;
float:left;
width:1126px;
position:absolute;
top:1339px;
}
 
Html

HTML Text:

<!DOCTYPE HTML>
<html>
<head>
<meta charset=utf-8>
<title>TSV Hartberg
</title>
<link rel="stylesheet" href="standard.css" type="text/css" media="screen">
<link rel="stylesheet" href="standard_mobile.css" media="handheld">
<meta name="author" content="Christian">
</head>
<body>
<div id="main" >
<div class="box1">
</div>
<div class="menu_container">
<ul class="menu">
<li>
<a href="#nogo">Home</a>
<ul>
<li>
<a href="#">Vorwort</a>
</li>
<li>
<a href="#">Aktuelles</a>
</li>
</ul>
</li>
<li>
<a href="#nogo">Mannschaften</a>
<ul>
<li>
<a href="#">Herren</a>
</li>
<li>
<a href="#">Jugend</a>
</li>
<li>
<a href="#">Senioren</a>
</li>
</ul>
</li>
<li>
<a href="#nogo">Events</a>
<ul>
<li>
<a href="#">Turniere</a>
</li>
<li>
<a href="#">Meisterschaft</a>
</li>
<li>
<a href="#">Sonstiges</a>
</li>
</ul>
</li>
<li>
<a href="#nogo">Trainer</a>
<ul>
</ul>
</li>
<li>
<a href="#nogo">Verein</a>
<ul>
<li>
<a href="#">Vorstand</a>
</li>
<li>
<a href="#">Tennishalle</a>
</li>
<li>
<a href="#">Tennisplätze</a>
</li>
<li>
<a href="#">Buffet</a>
</li>
<li>
<a href="#">Chronik</a>
</li>
</ul>
</li>
<li>
<a href="#nogo">Galerie</a>
<ul>
</ul>
</li>
<li>
<a href="#nogo">Presse</a>
<ul>
</ul>
</li>
<li>
<a href="#nogo">Beitritt</a>
<ul>
<li>
<a href="#">Preise</a>
</li>
<li>
<a href="#">Kontakt</a>
</li>
</ul>
</li>
<li>
<a href="#nogo">Impressum</a>
<ul>
</ul>
</li>
</ul>
</div>
<div class="box3">


<!--Hier soll der Besucherzähler stehen -->


<script type="text/javascript">

var global_transitions=["progid:DXImageTransform.Microsoft.Fade()"]

function flashyslideshow(setting){
this.wrapperid=setting.wrapperid
this.imagearray=setting.imagearray
this.pause=setting.pause
this.transduration=setting.transduration/1000 //convert from miliseconds to seconds unit to pass into el.filters.play()
this.currentimg=0
var preloadimages=[] //temp array to preload images
for (var i=0; i<this.imagearray.length; i++){
preloadimages=new Image()
preloadimages.src=this.imagearray[0]
}
document.write('<div id="'+this.wrapperid+'" class="'+setting.wrapperclass+'"><div id="'+this.wrapperid+'_inner" style="width:100%">'+this.getSlideHTML(this.currentimg)+'</div></div>')
var effectindex=Math.floor(Math.random()*global_transitions.length) //randomly pick a transition to utilize
var contentdiv=document.getElementById(this.wrapperid+"_inner")
if (contentdiv.filters){ //if the filters[] collection is defined on element (only in IE)
contentdiv.style.filter=global_transitions[effectindex] //define transition on element
this.pause+=setting.transduration //add transition time to pause
}
this.filtersupport=(contentdiv.filters && contentdiv.filters.length>0)? true : false //test if element supports transitions and has one defined
var slideshow=this
flashyslideshow.addEvent(contentdiv, function(){slideshow.isMouseover=1}, "mouseover")
flashyslideshow.addEvent(contentdiv, function(){slideshow.isMouseover=0}, "mouseout")
setInterval(function(){slideshow.rotate()}, this.pause)
}

flashyslideshow.addEvent=function(target, functionref, tasktype){
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false);
else if (target.attachEvent)
target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)});
},

flashyslideshow.setopacity=function(el, degree){ //sets opacity of an element (FF and non IE browsers only)
if (typeof el.style.opacity!="undefined")
el.style.opacity=degree
else
el.style.MozOpacity=degree
el.currentopacity=degree
},

flashyslideshow.prototype.getSlideHTML=function(index){
var slideHTML=(this.imagearray[index][1])? '<a href="'+this.imagearray[index][1]+'" target="'+this.imagearray[index][2]+'">\n' : '' //hyperlink slide?
slideHTML+='<img src="'+this.imagearray[index][0]+'" />'
slideHTML+=(this.imagearray[index][1])? '</a><br />' : '<br />'
slideHTML+=(this.imagearray[index][3])? this.imagearray[index][3] : '' //text description?
return slideHTML //return HTML for the slide at the specified index
}

flashyslideshow.prototype.rotate=function(){
var contentdiv=document.getElementById(this.wrapperid+"_inner")
if (this.isMouseover){ //if mouse is over slideshow
return
}
this.currentimg=(this.currentimg<this.imagearray.length-1)? this.currentimg+1 : 0
if (this.filtersupport){
contentdiv.filters[0].apply()
}
else{
flashyslideshow.setopacity(contentdiv, 0)
}
contentdiv.innerHTML=this.getSlideHTML(this.currentimg)
if (this.filtersupport){
contentdiv.filters[0].play(this.transduration)
}
else{
contentdiv.fadetimer=setInterval(function(){
if (contentdiv.currentopacity<1)
flashyslideshow.setopacity(contentdiv, contentdiv.currentopacity+0.1)
else
clearInterval(contentdiv.fadetimer)
}, 50) //end setInterval
}
}
 
var flashyshow=new flashyslideshow({ //create instance of slideshow
wrapperid: "myslideshow", //unique ID for this slideshow
wrapperclass: "flashclass", //desired CSS class for this slideshow
imagearray: [
["slide_small_1/pic01.jpg", "http://www.raiffeisen.at/eBusiness/rai_template1/1006637000974-NA-NA-NA-1-NA.html", "", ""],
["slide_small_1/pic02.jpg", "http://www.schirnhofer-gmbh.at/cms/index.php", "", ""],
["slide_small_1/pic03.jpg", "http://sterlinger.gemeindeausstellung.at/", "", ""],
["slide_small_1/pic04.jpg", "http://www.wilson.com/en-us/tennis/", "", ""]
],
pause: 3000, //pause between content change (millisec)
transduration: 1200 //duration of transition (affects only IE users)
})

</script>

<script type="text/javascript">

var global_transitions=["progid:DXImageTransform.Microsoft.Fade()"]

function flashyslideshow(setting){
this.wrapperid=setting.wrapperid
this.imagearray=setting.imagearray
this.pause=setting.pause
this.transduration=setting.transduration/1000 //convert from miliseconds to seconds unit to pass into el.filters.play()
this.currentimg=0
var preloadimages=[] //temp array to preload images
for (var i=0; i<this.imagearray.length; i++){
preloadimages=new Image()
preloadimages.src=this.imagearray[0]
}
document.write('<div id="'+this.wrapperid+'" class="'+setting.wrapperclass+'"><div id="'+this.wrapperid+'_inner" style="width:100%">'+this.getSlideHTML(this.currentimg)+'</div></div>')
var effectindex=Math.floor(Math.random()*global_transitions.length) //randomly pick a transition to utilize
var contentdiv=document.getElementById(this.wrapperid+"_inner")
if (contentdiv.filters){ //if the filters[] collection is defined on element (only in IE)
contentdiv.style.filter=global_transitions[effectindex] //define transition on element
this.pause+=setting.transduration //add transition time to pause
}
this.filtersupport=(contentdiv.filters && contentdiv.filters.length>0)? true : false //test if element supports transitions and has one defined
var slideshow=this
flashyslideshow.addEvent(contentdiv, function(){slideshow.isMouseover=1}, "mouseover")
flashyslideshow.addEvent(contentdiv, function(){slideshow.isMouseover=0}, "mouseout")
setInterval(function(){slideshow.rotate()}, this.pause)
}

flashyslideshow.addEvent=function(target, functionref, tasktype){
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false);
else if (target.attachEvent)
target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)});
},

flashyslideshow.setopacity=function(el, degree){ //sets opacity of an element (FF and non IE browsers only)
if (typeof el.style.opacity!="undefined")
el.style.opacity=degree
else
el.style.MozOpacity=degree
el.currentopacity=degree
},

flashyslideshow.prototype.getSlideHTML=function(index){
var slideHTML=(this.imagearray[index][1])? '<a href="'+this.imagearray[index][1]+'" target="'+this.imagearray[index][2]+'">\n' : '' //hyperlink slide?
slideHTML+='<img src="'+this.imagearray[index][0]+'" />'
slideHTML+=(this.imagearray[index][1])? '</a><br />' : '<br />'
slideHTML+=(this.imagearray[index][3])? this.imagearray[index][3] : '' //text description?
return slideHTML //return HTML for the slide at the specified index
}

flashyslideshow.prototype.rotate=function(){
var contentdiv=document.getElementById(this.wrapperid+"_inner")
if (this.isMouseover){ //if mouse is over slideshow
return
}
this.currentimg=(this.currentimg<this.imagearray.length-1)? this.currentimg+1 : 0
if (this.filtersupport){
contentdiv.filters[0].apply()
}
else{
flashyslideshow.setopacity(contentdiv, 0)
}
contentdiv.innerHTML=this.getSlideHTML(this.currentimg)
if (this.filtersupport){
contentdiv.filters[0].play(this.transduration)
}
else{
contentdiv.fadetimer=setInterval(function(){
if (contentdiv.currentopacity<1)
flashyslideshow.setopacity(contentdiv, contentdiv.currentopacity+0.1)
else
clearInterval(contentdiv.fadetimer)
}, 50) //end setInterval
}
}


///Sample call on your page

var flashyshow=new flashyslideshow({ //create instance of slideshow
wrapperid: "slideshow", //unique ID for this slideshow
wrapperclass: "animclass", //desired CSS class for this slideshow
imagearray: [
["slide_small_2/pic01.jpg", "http://www.lagerhaus.at/", "", ""],
["slide_small_2/pic02.jpg", "http://www.leithaeusl.at/", "", ""],
["slide_small_2/pic03.jpg", "http://www.sparkasse.at/sgruppe/", "", ""]

],
pause: 3500, //pause between content change (millisec)
transduration: 1700 //duration of transition (affects only IE users)
})
</script>

</div>
<div class="box4">box4
</div>
</div>
<div class="box5">box5
</div>
</body>
</html>
 
Ja, aber das Problem ist, dass der Besucherzähler immer einen Teil des Codes auf der Homepage anzeigt und nicht die Zahl. Wenn ich nur den php code in xampp öffne funktoniert es aber problemlos...
 
Also das ganze sind 3 Datein und dein Problem ist, dass wenn du dein HTML-File öffnest Teile vom Code angezeigt werden aber wenn du das PHP-File öffnest nicht?
 
Tschuldigung, bin grade erst draufgekommen, dass ich mich verschrieben habe!! Er soll natürlich in den HTML code eingefügt werden....
 
Genau! Wenn ich das PHP-File mit Xampp simuliere funzt alles aber sobald ich den Code aus dem PHP-File in den HTML-Code einbinde werden nur mehr teile des PHP-Codes angezeigt ...
 
Du meinst an der Stelle wo

Code:
<!--Hier soll der Besucherzähler stehen -->

steht?

Dann hast Du 2 Möglichkeiten:

a) Du benennst die HTML-Datei von .html in .php um und lädst in dieser den Besucherzähler per

PHP:
<?php include("besucherzaehler.php"); ?>

b) Du bindest den Besucherzähler als Bild ein

HTML:
<img src="besucherzaehler.php" alt="">

musst dazu jedoch den PHP-Code des Besucherzählers dahingehend anpassen, dass er ein Bild ausgibt. Siehe:
Grafiken erstellen - PHP-Kurs.com - PHP programmieren lernen
 
Dann würd ich mit dem PHP Befehl include("deineHTMLDatei.html"); die HTML Datei in die PHP Datei einbinden. Dann kannst du in der HTML-Datei deinen Counterwert ausgeben.
 
Zuletzt bearbeitet von einem Moderator:
Bitte nimm für Code die Code-Tags die im Editor unten rechts angeboten werden um Code auch anzuzeigen. Du findest sie wenn du auf erweitert klickst neben Antworten, falls sie nicht eingeblendet werden.
 
Super, danke für die schnelle Antwort! :-D
Ich probier das jez mal aus, und sollte ich auch damit Probleme haben melde ich mich wieder
 
Zurück
Oben