How to compute the sun's (upper) transit
Here is the page code for my BASIC-to-php implementation of the algorithms to calculate the  (geocentric) RA &amp; Dec of the Sun for a given date from Jean Meeus' book Astronomical Algorithms as well as calculating the angular distance between two celestial objects.  I can't remember the accuracy of the calculations and I didn't make the corrections for observer lat &amp; long.

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1" /&gt;
 &lt;base href="sionnagh.com" /&gt;
&lt;title&gt;Mick Todd Distance Calculator&lt;/title&gt;
&lt;STYLE TYPE="text/css"&gt;
&lt;!--
BODY
   {
   font-family:sans-serif;
   }
A:link{color:white}
A:visited{color:yellow}
--&gt;
&lt;/STYLE&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php include("mtheader.php"); ?&gt;
&lt;h1&gt;Mick Todd Distance Calculator&lt;/h1&gt;
&lt;?php 
$earthincl=23.44; //Earth's axial tilt
$sollat=0;

$fdate = $_POST["fdate"];
if ($fdate=="") {
 $fdate=getdate(date("U")-date("Z"));
 $fday=$fdate[mday];
 if (strlen($fday)==1) {$fday="0".$fday;}
 $fmonth=$fdate[mon];
 if (strlen($fmonth)==1) {$fmonth="0".$fmonth;}
 $fyear=$fdate[year];
 //$fdate=$fdate[mday]."/".$fdate[mon]."/".$fdate[year];
 $fdate=$fday."/".$fmonth."/".$fyear;
}
else {
 $fday=substr($fdate,0,2);
 $fmonth=substr($fdate,3,2);
 $fyear=substr($fdate,6,4);
}
$fra1 = $_POST["fra1"];
$fra1 = strtolower($fra1);
if ($fra1&lt;&gt;"") {
  if (strpos($fra1,"h")==0) {
  $frad1=$fra1;
  $fra1=converttohms($fra1);
  }
  else {
    $frad1=converthtod($fra1);
  }
}
$fdec1 = $_POST["fdec1"];
$fdec1 = strtolower($fdec1);
if ($fdec1&lt;&gt;"") {
  if (strpos($fdec1,"d")==0) {
    $fdecd1=$fdec1;
    $fdec1=converttodms($fdec1);
  }
  else {
    $fdecd1=convertdtod($fdec1);
  }
}
$fra2 = $_POST["fra2"];
$fra2 = strtolower($fra2);
if ($fra2&lt;&gt;"") {
  if (strpos($fra2,"h")==0) {
    $frad2=$fra2;
    $fra2=converttohms($fra2);
  }
  else {
    $frad2=converthtod($fra2);
  }
}
$fdec2 = $_POST["fdec2"];
$fdec2 = strtolower($fdec2);
if ($fdec2&lt;&gt;"") {
  if (strpos($fdec2,"d")==0) {
    $fdecd2=$fdec2;
    $fdec2=converttodms($fdec2);
  }
  else {
    $fdecd2=convertdtod($fdec2);
  }
}

function JulianDay ($fday, $fmonth, $fyear, $fUT) {
    $JDpartsign=(100*$fyear+$fmonth-190002.5)/abs(100*$fyear+$fmonth-190002.5);
 $JD = 367*$fyear - floor((7*($fyear+floor(($fmonth+9)/12)))/4) + floor((275*$fmonth)/9) + $fday + 1721013.5 + $fUT/24 - 0.5*$JDpartsign + 0.5;
 return $JD;
}
function converttodms($inval) {
 if ($inval==0) {
   $fdsign=1;
 }
 else {
   $fdsign=$inval/abs($inval);
 }
 $inval=abs($inval);
 $fddeg=floor($inval);
 $remain=($inval-$fddeg)*60;
 $fdmin=floor($remain);
 if (strlen($fdmin)==1) { $fdmin="0".$fdmin; }
 $remain=($remain-$fdmin)*60;
 $fdsec=round($remain*100)/100;
 if (strpos($fdsec,".")==1) { $fdsec="0".$fdsec; }
 $fddeg=$fdsign*$fddeg;
 $fdms=$fddeg."d".$fdmin."m".$fdsec."s";

    return $fdms;
}
function converttohms($inval) {
    $inval=$inval/15;
    $fddeg=floor($inval);
    $remain=($inval-$fddeg)*60;
 $fdmin=floor($remain);
 if (strlen($fdmin)==1) { $fdmin="0".$fdmin; }
    $remain=($remain-$fdmin)*60;
 $fdsec=round($remain*100)/100;
 if (strpos($fdsec,".")==1) { $fdsec="0".$fdsec; }
    $fdms=$fddeg."h".$fdmin."m".$fdsec."s";

    return $fdms;
}
function converthtod($inval) {
  $posh=strpos($inval,"h");
  $posm=strpos($inval,"m");
  $poss=strpos($inval,"s");
  $temph=substr($inval,0,$posh);
  if ($posm) {
    $tempm=substr($inval,$posh+1,$posm-($posh+1));
  }
  if ($poss) {
    $temps=substr($inval,$posm+1,$poss-($posm+1));
  }

  $fdms=($temph+$tempm/60+$temps/3600)*15;

  return $fdms;
}
function convertdtod($inval) {
  $posd=strpos($inval,"d");
  $posm=strpos($inval,"m");
  $poss=strpos($inval,"s");
  $tempd=substr($inval,0,$posd);
  if ($posm) {
    $tempm=substr($inval,$posd+1,$posm-($posd+1));
  }
  if ($poss) {
    $temps=substr($inval,$posm+1,$poss-($posm+1));
  }
  $fdms=$tempd+$tempm/60+$temps/3600;

  return $fdms;
}

function SolarCoords($fday, $fmonth, $fyear, $fUT) {
//Julian Day of 1991/ 5/19 at 13 UT         JD = 2448396.04167
//Julian day of 2000/01/01 at 12 UT         JD = 2451545.0
//number of Julian days since 2000/01/01 at 12 UT               -3148.95833
//number of Julian centuries since 2000/01/01 at 12 UT  T = - 3148.95833/36525
//used by the algorithm for L                                                           = 0.086213780

    $k = 2*pi()/360;
  $T = (JulianDay($fday, $fmonth, $fyear, $fUT)-2451545.0)/36525;
    //echo "\$T: ".$T."&lt;br /&gt;";
 //mean anomaly, degree
 $M = 357.52910 + 35999.05030*$T - 0.0001559*$T*$T - 0.00000048*$T*$T*$T;
    //echo "\$M: ".$M."&lt;br /&gt;";

    // mean longitude, degree
    $L0 = 280.46645 + 36000.76983*$T + 0.0003032*$T*$T;
    //echo "\$L0: ".$L0."&lt;br /&gt;";

    $DL = (1.914600 - 0.004817*$T - 0.000014*$T*$T)*sin($k*$M) + (0.019993 - 0.000101*$T)*sin($k*2*$M) + 0.000290*sin($k*3*$M);
 //echo "\$DL: ".$DL."&lt;br /&gt;";

    // true longitude, degree
    $L = $L0 + $DL;
 if (abs($L)&gt;360) {
        $divsign=($L/360)/abs($L/360);
  $div=floor(abs($L/360));
  $L=$L-$divsign*$div*360;
  if ($L&lt;0) { $L=$L+360; }
    }
    $L=round($L*10000)/10000;

    return $L;

}

?&gt;
&lt;script type="text/javascript"&gt;
    &lt;!--
    function settoday() {
        var d=new Date();
        dday=d.getDate();
        if (dday&lt;10) { dday="0" + dday; }
        dmonth=d.getMonth()+1;
        if (dmonth&lt;10) { dmonth="0" + dmonth; }
        dyear=d.getFullYear();

        ddate= dday + "/" + dmonth + "/" + dyear;

        return ddate;

    }

    //--&gt;
&lt;/script&gt;
&lt;form METHOD="POST" ACTION="mtdistcalc.php" name="mtdistcalc"&gt;


&lt;p&gt;Date &lt;input type="text" name="fdate" id="fdate" size=10 value="&lt;?php echo $fdate; ?&gt;"&gt; &lt;input type="button" value="Now" onclick="fdate.value=settoday();"&gt;&lt;/p&gt;
&lt;p&gt;Object coordinates (#1) RA &lt;input type="text" name="fra1" id="fra1" size=15 value="&lt;?php echo $fra1; ?&gt;"&gt;  Decl &lt;input type="text" name="fdec1" id="fdec1" size=15 value="&lt;?php echo $fdec1; ?&gt;"&gt;&lt;/p&gt;
&lt;p&gt;Object coordinates (#2) RA &lt;input type="text" name="fra2" id="fra2" size=15 value="&lt;?php echo $fra2; ?&gt;"&gt;  Decl &lt;input type="text" name="fdec2" id="fdec2" size=15 value="&lt;?php echo $fdec2; ?&gt;"&gt;&lt;/p&gt;
  &lt;p&gt;&lt;input TYPE=SUBMIT VALUE="Calculate distances"&gt;&lt;/p&gt;


&lt;/form&gt;
&lt;?php
echo "&lt;table&gt;&lt;tr&gt;&lt;td&gt;Date:&lt;/td&gt;&lt;td&gt;".$fday."/".$fmonth."/".$fyear." "."0000UT&lt;/td&gt;&lt;/tr&gt;";
echo "&lt;tr&gt;&lt;td&gt;Julian Day: &lt;/td&gt;&lt;td&gt;".JulianDay($fday,$fmonth,$fyear,"0")."&lt;/td&gt;&lt;/tr&gt;";
echo "&lt;tr&gt;&lt;td&gt;Ecliptic latitude of the Sun: &lt;/td&gt;&lt;td&gt;".$sollat."&amp;deg; (assumed)&lt;/td&gt;&lt;/tr&gt;";
$sollong = SolarCoords($fday,$fmonth,$fyear,"0");
echo "&lt;tr&gt;&lt;td&gt;Ecliptic longitude of the Sun: &lt;/td&gt;&lt;td&gt;".$sollong."&amp;deg; (".converttodms($sollong).")&lt;/td&gt;&lt;/tr&gt;";
echo "&lt;tr&gt;&lt;td&gt;Earth's axial inclination: &lt;/td&gt;&lt;td&gt;".$earthincl."&amp;deg;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;";

//echo "\$feclong ".$feclong."&lt;br /&gt;&lt;br /&gt;";

$deltaSol = round(asin(sin($sollat*M_PI/180)*cos($earthincl*M_PI/180) + cos($sollat*M_PI/180)*sin($earthincl*M_PI/180)*sin($sollong*M_PI/180))*180/M_PI*10000)/10000;
$alphaSol = round(acos(cos($sollong*M_PI/180)*cos($sollat*M_PI/180) / cos($deltaSol*M_PI/180))*180/M_PI*10000)/10000;
if ($sollong&gt;180) {
 $alphaSol = 360-$alphaSol;
}
echo "&lt;table&gt;&lt;tr&gt;&lt;td colspan=2&gt;Sol&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;RA: &lt;/td&gt;&lt;td&gt;".$alphaSol."&amp;deg; (".converttohms($alphaSol).")&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Dec:&lt;/td&gt;&lt;td&gt;".$deltaSol."&amp;deg; (".converttodms($deltaSol).")&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;";

//spherical angular distance
//cos(theta) = sin(delta_a) sin(delta_b) + cos(delta_a) cos(delta_b) cos(alpha_a-alpha_b)
if ($fra1&lt;&gt;"" AND $fdec1&lt;&gt;"") {
  $theta1 = round(acos(sin($deltaSol*M_PI/180)*sin($fdecd1*M_PI/180) + cos($deltaSol*M_PI/180)*cos($fdecd1*M_PI/180)*cos(($alphaSol-$frad1)*M_PI/180))*180/M_PI*1000)/1000;
}
if ($fra2&lt;&gt;"" AND $fdec2&lt;&gt;"") {
  $theta2 = round(acos(sin($deltaSol*M_PI/180)*sin($fdecd2*M_PI/180) + cos($deltaSol*M_PI/180)*cos($fdecd2*M_PI/180)*cos(($alphaSol-$frad2)*M_PI/180))*180/M_PI*1000)/1000;
}

if ($fra1&lt;&gt;"" AND $fdec1&lt;&gt;"" AND $fra2&lt;&gt;"" AND $fdec2&lt;&gt;"") {
  $theta3 = round(acos(sin($fdecd1*M_PI/180)*sin($fdecd2*M_PI/180) + cos($fdecd1*M_PI/180)*cos($fdecd2*M_PI/180)*cos(($frad1-$frad2)*M_PI/180))*180/M_PI*1000)/1000;
  echo "&lt;p&gt;&lt;font color=\"#0000FF\"&gt;Angular distance between Object #1 and Object #2 is: ".$theta3."&amp;deg;&lt;/font&gt;&lt;/p&gt;";
}

if (($fra1&lt;&gt;"" and $fdec1&lt;&gt;"") or ($fra2&lt;&gt;"" and $fdec2&lt;&gt;"")) {
  echo "&lt;table&gt;&lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td align=center&gt;&lt;b&gt;RA&lt;/b&gt;&lt;/td&gt;&lt;td align=center&gt;&lt;b&gt;Dec&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Solar elong.&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;";
}
if ($fra1&lt;&gt;"" AND $fdec1&lt;&gt;"") {
  echo "&lt;tr&gt;&lt;td&gt;Object #1:&lt;/td&gt;&lt;td&gt;&lt;font color=Maroon&gt;".$fra1."&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font color=Maroon&gt;".$fdec1."&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=Maroon&gt;".$theta1."&amp;deg;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;";
}
if ($fra2&lt;&gt;"" AND $fdec2&lt;&gt;"") {
  echo "&lt;tr&gt;&lt;td&gt;Object #2:&lt;/td&gt;&lt;td&gt;".$fra2."&lt;/td&gt;&lt;td&gt;".$fdec2."&lt;/td&gt;&lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;".$theta2."&amp;deg;&lt;/td&gt;&lt;/tr&gt;";
}


?&gt;
&lt;/body&gt;
&lt;/html&gt;