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

Datum bzw. Zeitraum in PHP abfragen und dementsprechend eine HTML-Seite aufrufen

Chrisburg

Neues Mitglied
Hallo zusammen,

ich habe ein Javascript in Benutzung, das je nach Datum eine andere Startseite aufruft (mit entprechendem Hintergrund für Weihnachten, Ostern, Fasching etc..)

Leider gibt es damit Probleme bei Smartphones und mit dem Firefox. Die Seiten werden nicht angezeigt. Mit dem IE funktioniert es einwandfrei.

Deshalb wollte ich mal fragen, ob man so etwas mit PHP realisieren könnte und wie dies dann programmiert werden müsste.

Danke für jede Hilfe

Liebe Grüße

Chrisburg




Hier ist der Code mit Javascript:

HTML:
<html>
<head>
<title>START.HTML je nach Jahreszeit</title>
<Script Language="JavaScript">
<!--
// Written by T.J. Buttrick  www.sleestack.com
// Modified by me for special link on different days!
function date() {
        var today = new Date();
        var dayofweek = today.getDay();
                if (dayofweek == 0) {dayofweek = "Sonntag"};
                else if (dayofweek == 1) {dayofweek = "Montag"};
                else if (dayofweek == 2) {dayofweek = "Dienstag"};
                else if (dayofweek == 3) {dayofweek = "Mittwoch"};
                else if (dayofweek == 4) {dayofweek = "Donnerstag"};
                else if (dayofweek == 5) {dayofweek = "Freitag"};
                else {dayofweek = "Samstag"};
        var month = today.getMonth();
                if (month == 0) {month = "Januar"};
                else if (month == 1) {month = "Februar"};
                else if (month == 2) {month = "März"};
                else if (month == 3) {month = "April"};
                else if (month == 4) {month = "Mai"};
                else if (month == 5) {month = "Juni"};
                else if (month == 6) {month = "Juli"};
                else if (month == 7) {month = "August"};
                else if (month == 8) {month = "September"};
                else if (month == 9) {month = "Oktober"};
                else if (month == 10) {month = "November"};
                else {month = "Dezember"};
        var dayofmonth = today.getDate();
        var year = today.getFullYear();
//        document.write("<font size=\"4\">" + dayofweek + ", " + dayofmonth + ". " + month + " " + year + "</font>");
/* FEIERTAGSLISTE */
/* Feiertage, die jedes Jahr das selbe Datum haben */
          if ((month == "Dezember")  && (dayofmonth >= 1) && (dayofmonth <= 23)) {document.location.href="startfiles/start_advent.html"};
          else if ((month == "Dezember")  && (dayofmonth >= 24) && (dayofmonth <= 26)) {document.location.href="startfiles/start_weihnacht.html"};
          else if ((month == "Dezember")  && (dayofmonth >= 27) && (dayofmonth <= 31))  {document.location.href="startfiles/start_silvester.html"};
          else if ((month == "Januar") && (dayofmonth >= 1) && (dayofmonth <= 5))  {document.location.href="startfiles/start_neujahr.html"};
          else if ((month == "Oktober") && (dayofmonth >= 1) && (dayofmonth <= 31))  {document.location.href="startfiles/start_halloween.html"};
//        else if ((month == "Februar") && (dayofmonth == 14)) {document.location.href="start_valentin.html"};
//        else if ((month == "Mai") && (dayofmonth == 1))  {document.location.href="start_mai.html"};
//        else if ((month == "Oktober") && (dayofmonth == 3))  {document.location.href="start_national.html"};
//        else if ((month == "Oktober") && (dayofmonth == 31)) {document.location.href="start_halloween.html"};
/* Feiertage, die manuell eingegeben werden müssen */
          else if  ((year == 2011) && (month == "April") && (dayofmonth >= 21) && (dayofmonth <= 30)) {document.location.href="startfiles/start_ostern.html"};
          else if  ((year == 2012) && (month == "April") && (dayofmonth >= 7) && (dayofmonth <= 16)) {document.location.href="startfiles/start_ostern.html"};
          else if  ((year == 2013) && (month == "März") && (dayofmonth >= 28) && (dayofmonth <= 31)) {document.location.href="startfiles/start_ostern.html"};
          else if  ((year == 2013) && (month == "April") && (dayofmonth >= 1) && (dayofmonth <= 5)) {document.location.href="startfiles/start_ostern.html"};
          else if  ((year == 2014) && (month == "April") && (dayofmonth >= 17) && (dayofmonth <= 26)) {document.location.href="startfiles/start_ostern.html"};
          else {document.location.href="startfiles/start_normal.html"};
}
//  -->
</Script>
</head>
<BODY>
<script language="javascript">date()</script>
</body>
</html>
 
Vielen Dank für den Link.

Ich habe mal probiert das umzusetzen, bekomme aber immer einen Syntaxerror.
Bin leider Anfänger und weiss nicht wo mein Fehler liegt.

Kann mir da jemand weiterhelfen oder liege ich total falsch?

Nochmals danke

Chrisburg

Bin selber drauf gekommen: Ich habe jetzt "include" anstelle von "ZEIGE" benutzt, das war der Fehler....

Hier mein Versuch:

HTML:
<?php
date_default_timezone_set('UTC');
$tag = date('j');
$monat = date('F');
$jahr = date('Y');
if ($monat == "december" && $tag >= 1 && $tag <= 23) {ZEIGE "startfiles/start_advent.html";} 
else {ZEIGE "startfiles/start_normal.html";}
// Code von Javascript:
// if ((month == "Dezember")  && (dayofmonth >= 1) && (dayofmonth <= 23)) {document.location.href="startfiles/start_advent.html"};   
// else {document.location.href="startfiles/start_normal.html"};
?>
 
Zuletzt bearbeitet:
Zurück
Oben