php biorhythms (βιορυθμοι)

Σε αυτή την περιοχή μπορείτε να βρείτε ή να αναζητήσετε πληροφορίες σχετικές με την PHP

Συντονιστές: WebDev Moderators, Super-Moderators, PHP Moderators

Απάντηση
H_TSOPELAS
Δημοσιεύσεις: 16
Εγγραφή: 31 Αύγ 2010 21:33

php biorhythms (βιορυθμοι)

Δημοσίευση από H_TSOPELAS » 25 Σεπ 2010 18:49

καλησπερα σε ολους, ειμαι νεο μελος στην κοινοτητα σας και ηθελα να κανω μια ερωτηση.
θελει ενας φιλος ενα script βιορυθμους(εχει σχεση με αστρολογια), βρηκα λοιπον αυτο που θα δειτε παρακατω αλλα δεν ξερω τι να κανω για να λειτουργησει!μπορει καποιος που εχει γνωση να με βοηθησει σας παρακαλω?δεν ξερω τι κανω λαθος!ο κωδικας ειναι:

Κώδικας: Επιλογή όλων

<?php 
// 
// page header 
// 
function pageHeader() 
{ 

    print("<html><head>"); 
    print("<title>Biorhythm with PHP3</title>"); 
    print("</head><body>"); 

} 

// 
// page footer 
// 
function pageFooter() 
{ 

    print("</body></html>"); 

}  

// 
// function that transforms date from the Julian calendar to the Gregorian calendar 
// 
function gregorianToJD($month, $day, $year) 
{ 
    

    if($month < 3) 
    { 
        $month = $month + 12; 
        $year = $year - 1; 
    } 

    $jd = $day + floor((153 * $month - 457) / 5) + 365 * $year 
          + floor($year / 4) - floor($year / 100) 
          + floor($year / 400) + 1721118.5; 

    return($jd); 

} 

// 
// Function of biorhythm graph drawing 
// Parameters: day, biorhythm period, color 
// 
function drawRhythm($daysAlive, $period, $color) 
{ 
    global $daysToShow, $image, $diagramWidth, $diagramHeight; 

    // Define day in the center of the graph 
    $centerDay = $daysAlive - ($daysToShow / 2); 

    // Graph&#65533;s parameters 
    $plotScale = ($diagramHeight - 25) / 2; 
    $plotCenter = ($diagramHeight - 25) / 2; 

    // Draw the graph 
    for($x = 0; $x <= $daysToShow; $x++) 
    { 
 
        $phase = (($centerDay + $x) % $period) / $period * 2 * pi(); 
        
        $y = 1 - sin($phase) * (float)$plotScale + (float)$plotCenter; 

            if($x > 0) 
            imageLine($image, $oldX, $oldY, $x * $diagramWidth / $daysToShow, 
            $y, $color); 
  
        // Save the current coordinates 
        $oldX = $x * $diagramWidth / $daysToShow; 
        $oldY = $y; 
    } 

} 

// 
// ---- MAIN PROGRAM START ---- 


// Check whether date of birth has been set
// If not show the form for date entering
if(!isset($birthdate)) 
{ 
    pageHeader(); 

    ?> 
     <form method="post" action="<?php print(basename($PHP_SELF)); ?>"> 
     Please enter your birthday:<br> 
     <input type="text" name="birthdate" 
            value="MM/DD/YYYY"><input type="submit" value="OK!"> 
     </form> 
    <?php 

    pageFooter(); 

    exit(); 
} 
    
// Select day, month and year 
$birthMonth = substr($birthdate, 0, 2); 
$birthDay = substr($birthdate, 3, 2); 
$birthYear = substr($birthdate, 6, 4); 

if(!checkDate($birthMonth, $birthDay, $birthYear)) 
{ 
    pageHeader(); 

    print("The date "$birthMonth/$birthDay/$birthYear" is invalid."); 

    pageFooter(); 

    exit(); 
} 
    
// Graph&#65533;s parameters (global variables) 
$diagramWidth = 710; 
$diagramHeight = 400;     
$daysToShow = 30;        

$daysGone = abs(gregorianToJD($birthMonth, $birthDay, $birthYear) 
                - gregorianToJD(date( "m"), date( "d"), date( "Y"))); 

// Create the image 
$image = imageCreate($diagramWidth, $diagramHeight); 

// Register the used colors 
$colorBackgr       = imageColorAllocate($image, 192, 192, 192); 
$colorForegr       = imageColorAllocate($image, 255, 255, 255); 
$colorGrid         = imageColorAllocate($image, 0, 0, 0); 
$colorCross        = imageColorAllocate($image, 0, 0, 0); 
$colorPhysical     = imageColorAllocate($image, 0, 0, 255); 
$colorEmotional    = imageColorAllocate($image, 255, 0, 0); 
$colorIntellectual = imageColorAllocate($image, 0, 255, 0); 

// Filling with the background color 
imageFilledRectangle($image, 0, 0, $diagramWidth - 1, $diagramHeight - 1, $colorBackgr);  

// Calculate the start date of the graph 
$nrSecondsPerDay = 60 * 60 * 24; 
$diagramDate = time() - ($daysToShow / 2 * $nrSecondsPerDay) + $nrSecondsPerDay; 

for ($i = 1; $i < $daysToShow; $i++) 
{ 
    $thisDate = getDate($diagramDate); 
    $xCoord = ($diagramWidth / $daysToShow) * $i; 
    imageLine($image, $xCoord, $diagramHeight - 25, $xCoord, 
              $diagramHeight - 20, $colorGrid); 
    imageString($image, 3, $xCoord - 5, $diagramHeight - 16, 
                $thisDate[ "mday"], $colorGrid); 

    $diagramDate += $nrSecondsPerDay; 
} 

// Draw the frame 
imageRectangle($image, 0, 0, $diagramWidth - 1, $diagramHeight - 20, 
               $colorGrid); 

// Draw the axes 
imageLine($image, 0, ($diagramHeight - 20) / 2, $diagramWidth, 
          ($diagramHeight - 20) / 2, $colorCross); 
imageLine($image, $diagramWidth / 2, 0, $diagramWidth / 2, $diagramHeight - 20, 
          $colorCross); 

// Print the text 
imageString($image, 3, 10, 10,  "Birthday: $birthDay.$birthMonth.$birthYear", 
            $colorCross); 
imageString($image, 3, 10, 26,  "Today:    ".  date(  "d.m.Y"),  $colorCross); 
imageString($image, 3, 10, $diagramHeight - 42,  "Physical", $colorPhysical); 
imageString($image, 3, 10, $diagramHeight - 58,  "Emotional", $colorEmotional); 
imageString($image, 3, 10, $diagramHeight - 74,  "Intellectual", 
            $colorIntellectual); 

// Draw three graphs with corresponding parameters 
drawRhythm($daysGone, 23, $colorPhysical); 
drawRhythm($daysGone, 28, $colorEmotional); 
drawRhythm($daysGone, 33, $colorIntellectual); 

// Send the header Content-type 
//header("Content-type:  image/gif"); 
header("Content-type:  image/png"); 

// Set the interlaced mode 
imageInterlace($image, 1); 

// Make the background color transparent 
imageColorTransparent($image, $colorBackgr); 

// print the image 
//imageGIF($image); 
imagePNG($image); 

?>&#91;code&#93;
και η σελιδα απο οπου το βρηκα ειναι:
http://www.phpwest.com/articles/54/Basics/Creating_the_images_by_means_of_PHP.html

ελπιζω καποιος να γνωριζει!σας ευχαριστω πολυ ολους!&#91;/code&#93;

WSPNH
Δημοσιεύσεις: 97
Εγγραφή: 10 Μαρ 2006 12:52
Επικοινωνία:

php biorhythms (βιορυθμοι)

Δημοσίευση από WSPNH » 30 Σεπ 2010 17:29

Φίλε σε έφτιαξα σπέσιαλ.

Διόρθωσα τα προβλήματα (απλά μερικοί ανεβάζουν tutorial χωρίς αυτά να δουλεύουν βλέπε php west).

Το έφτιαξα να ειναι ποιο ασφαλές, πλέον δεν έχει text field όπου μπορεί ο καθένας να βάζει ότι γουστάρει αλλά select boxes με τις στάνταρ ημερες , μήνες και χρόνους.

Δεν πείραξα καθόλου την function όπου δημιουργεί την εικόνα. Προσπάθησα όσο γινόταν να μικρύνω (shorten) τον κώδικα.

Δες και τα σχόλια που εχω γράψει μέσα, αν έχεις να ρωτήσεις κάτι, ευχαρίστως αν μπορώ να απαντήσω...

Κώδικας: Επιλογή όλων

<?php
$currentday=date&#40;"j"&#41;;
$currentmonth=date&#40;"m"&#41;;
$currentyear=date&#40;"Y"&#41;;
if&#40;!isset&#40;$_POST&#91;'month'&#93;&#41; || !isset&#40;$_POST&#91;'day'&#93;&#41; || !isset&#40;$_POST&#91;'year'&#93;&#41; &#41;&#123;
 ?>
<html><head><title>Biorhythm with PHP3</title></head><body>
<form method="post" action="<?php print&#40;basename&#40;$PHP_SELF&#41;&#41;; ?>"> 
Please select your birthday&#58;
<select name='day'>
<?php
for&#40;$i=1;$i<=31;$i++&#41;&#123; //if&#40;$i<10&#41; for adding leading zeros // if&#40;$i==$currentday&#41; check to automaticly select curent day
if&#40;$i<10&#41; if&#40;$i==$currentday&#41; echo "<option value='0$i' selected=\"selected\">0$i</option>"; else echo "<option value='0$i'>0$i</option>";
else if&#40;$i==$currentday&#41; echo "<option value='$i' selected=\"selected\">$i</option>"; else echo "<option value='$i'>$i</option>";
&#125;
?>
</select>
<select name='month'>
<?php
for&#40;$i=1;$i<=12;$i++&#41;&#123;//if&#40;$i<10&#41; for adding leading zeros // if&#40;$i==$currentmonth&#41; check to automaticly select curent month
if&#40;$i<10&#41; if&#40;$i==$currentmonth&#41; echo "<option value='0$i' selected=\"selected\">0$i</option>"; else echo "<option value='0$i'>0$i</option>";
else if&#40;$i==$currentmonth&#41; echo "<option value='$i' selected=\"selected\">$i</option>"; else echo "<option value='$i'>$i</option>";
&#125;
?>
</select>
<select name='year'>
<?php
for&#40;$i=1800;$i<=3000;$i++&#41;&#123; // if&#40;$i==$currentyear&#41; check to automaticly select curent year
if&#40;$i==$currentyear&#41; echo "<option value='$i' selected=\"selected\">$i</option>"; else echo "<option value='$i'>$i</option>";
&#125;
?>
</select> <input type="submit" value="OK!">
</form></body></html>
<?php
exit&#40;&#41;; 
&#125;else&#123; //An exome tis metavlhtes, an einai oles setarismenes

//kalo tha htan edw na exetazame an an oi post ontws einai arithmoi kai swstoi, POTE DE XEREIS
// p.x. tha mporousame na eixame ena array me tis acceptable times kai na exetazame an h POST timh yparxei ston pinaka
// an theleis na to kanw pes to mou 
$birthMonth =$_POST&#91;'month'&#93;; 
$birthDay = $_POST&#91;'day'&#93;; 
$birthYear = $_POST&#91;'year'&#93;;

//$birthdate= $_POST&#91;'month'&#93;."/".$_POST&#91;'day'&#93;."/".$_POST&#91;'year'&#93;;
//$birthMonth = substr&#40;$birthdate, 0, 2&#41;; 
//$birthDay = substr&#40;$birthdate, 3, 2&#41;; 
//$birthYear = substr&#40;$birthdate, 6, 4&#41;; 
&#125;

// Graph&#65533;s parameters &#40;global variables&#41; 
$diagramWidth = 710; 
$diagramHeight = 400;     
$daysToShow = 30;        

$daysGone = abs&#40;gregorianToJDA&#40;$birthMonth, $birthDay, $birthYear&#41; - gregorianToJDA&#40;date&#40; "m"&#41;, date&#40; "d"&#41;, date&#40; "Y"&#41;&#41;&#41;; 

// Create the image 
$image = imageCreate&#40;$diagramWidth, $diagramHeight&#41;; 

// Register the used colors 
$colorBackgr       = imageColorAllocate&#40;$image, 192, 192, 192&#41;; 
$colorForegr       = imageColorAllocate&#40;$image, 255, 255, 255&#41;; 
$colorGrid         = imageColorAllocate&#40;$image, 0, 0, 0&#41;; 
$colorCross        = imageColorAllocate&#40;$image, 0, 0, 0&#41;; 
$colorPhysical     = imageColorAllocate&#40;$image, 0, 0, 255&#41;; 
$colorEmotional    = imageColorAllocate&#40;$image, 255, 0, 0&#41;; 
$colorIntellectual = imageColorAllocate&#40;$image, 0, 255, 0&#41;; 

// Filling with the background color 
imageFilledRectangle&#40;$image, 0, 0, $diagramWidth - 1, $diagramHeight - 1, $colorBackgr&#41;;  

// Calculate the start date of the graph 
$nrSecondsPerDay = 60 * 60 * 24; 
$diagramDate = time&#40;&#41; - &#40;$daysToShow / 2 * $nrSecondsPerDay&#41; + $nrSecondsPerDay; 

for &#40;$i = 1; $i < $daysToShow; $i++&#41; 
&#123; 
    $thisDate = getDate&#40;$diagramDate&#41;; 
    $xCoord = &#40;$diagramWidth / $daysToShow&#41; * $i; 
    imageLine&#40;$image, $xCoord, $diagramHeight - 25, $xCoord, $diagramHeight - 20, $colorGrid&#41;; 
    imageString&#40;$image, 3, $xCoord - 5, $diagramHeight - 16, $thisDate&#91; "mday"&#93;, $colorGrid&#41;; 

    $diagramDate += $nrSecondsPerDay; 
&#125; 

// Draw the frame 
imageRectangle&#40;$image, 0, 0, $diagramWidth - 1, $diagramHeight - 20, $colorGrid&#41;; 

// Draw the axes 
imageLine&#40;$image, 0, &#40;$diagramHeight - 20&#41; / 2, $diagramWidth, &#40;$diagramHeight - 20&#41; / 2, $colorCross&#41;; 
imageLine&#40;$image, $diagramWidth / 2, 0, $diagramWidth / 2, $diagramHeight - 20, $colorCross&#41;; 

// Print the text 
imageString&#40;$image, 3, 10, 10,  "Birthday&#58; $birthDay.$birthMonth.$birthYear", $colorCross&#41;; 
imageString&#40;$image, 3, 10, 26,  "Today&#58;    ".  date&#40;  "d.m.Y"&#41;,  $colorCross&#41;; 
imageString&#40;$image, 3, 10, $diagramHeight - 42,  "Physical", $colorPhysical&#41;; 
imageString&#40;$image, 3, 10, $diagramHeight - 58,  "Emotional", $colorEmotional&#41;; 
imageString&#40;$image, 3, 10, $diagramHeight - 74,  "Intellectual", $colorIntellectual&#41;; 

// Draw three graphs with corresponding parameters 
drawRhythm&#40;$daysGone, 23, $colorPhysical&#41;; 
drawRhythm&#40;$daysGone, 28, $colorEmotional&#41;; 
drawRhythm&#40;$daysGone, 33, $colorIntellectual&#41;; 

// Send the header Content-type 
//header&#40;"Content-type&#58;  image/gif"&#41;; 
header&#40;"Content-type&#58;  image/png"&#41;; 

// Set the interlaced mode 
imageInterlace&#40;$image, 1&#41;; 

// Make the background color transparent 
imageColorTransparent&#40;$image, $colorBackgr&#41;; 

// print the image 
//imageGIF&#40;$image&#41;; 
imagePNG&#40;$image&#41;; 


//FUNCTIONS

/* 
Function that transforms date from the Julian calendar to the Gregorian calendar 
*/ 
function gregorianToJDA&#40;$month, $day, $year&#41;&#123; 
    
    if&#40;$month < 3&#41;&#123; $month = $month + 12; $year = $year - 1; &#125;
    $jd = $day + floor&#40;&#40;153 * $month - 457&#41; / 5&#41; + 365 * $year 
          + floor&#40;$year / 4&#41; - floor&#40;$year / 100&#41; 
          + floor&#40;$year / 400&#41; + 1721118.5; 

    return&#40;$jd&#41;;
&#125; 

/* 
Function of biorhythm graph drawing 
Parameters&#58; day, biorhythm period, color 
*/ 
function drawRhythm&#40;$daysAlive, $period, $color&#41; 
&#123; 
    global $daysToShow, $image, $diagramWidth, $diagramHeight; 
    $centerDay = $daysAlive - &#40;$daysToShow / 2&#41;;  // Define day in the center of the graph 

    // Graph&#65533;s parameters 
    $plotScale = &#40;$diagramHeight - 25&#41; / 2; 
    $plotCenter = &#40;$diagramHeight - 25&#41; / 2; 

    // Draw the graph 
    for&#40;$x = 0; $x <= $daysToShow; $x++&#41; &#123; 
        $phase = &#40;&#40;$centerDay + $x&#41; % $period&#41; / $period * 2 * pi&#40;&#41;; 
        $y = 1 - sin&#40;$phase&#41; * &#40;float&#41;$plotScale + &#40;float&#41;$plotCenter; 
        if&#40;$x > 0&#41; imageLine&#40;$image, $oldX, $oldY, $x * $diagramWidth / $daysToShow, $y, $color&#41;; 
        // Save the current coordinates 
        $oldX = $x * $diagramWidth / $daysToShow; 
        $oldY = $y; 
    &#125; 

&#125;
?> 
http://xesemesa.gr ή http://arxwn.eu όπως και να έχει http://jbaron.gr

Απάντηση

Επιστροφή στο “PHP Προγραμματισμός”

Μέλη σε σύνδεση

Μέλη σε αυτήν τη Δ. Συζήτηση: Δεν υπάρχουν εγγεγραμμένα μέλη και 1 επισκέπτης