Forum Moderators: phranque

Message Too Old, No Replies

PHP Code Not Working on Windows/Apache Server

         

cascade27

10:05 pm on Feb 8, 2010 (gmt 0)

10+ Year Member



Hello,

I'm working on Joomla 1.5.15 that runs on Windows/Apache server. I have a block of PHP code named "Research Calculator". The program asks a user to enter the beginning date and the due date of an assignment and it calculates and displays the number of days to do with suggested steps to complete the assignment in time. I have this PHP code on Joomla 1.5.15 which is wrapped in Jumi tags but it is not working. When I submit, it simply takes me back to the home page. When I insert the same PHP code (wrapped in Jumi tags) on a Linux/Apache web server, it works fine. So, I know that the code itself is fine. It appears that some settings on the Winodws/Apache server is blocking this PHP code to execute. I looked into php.ini but I couldn't tell. The program requires instructions.php and it is properly located in the root directory. Again, the code works fine on the Linux/Apache server. I have a snapshot of working research calculator but this forum doesn't seem to allow me to attach an attachment. I can email it to you if you are interested. Please let me know.

I'm using Jumi to wrap the PHP code to put on a Joomla page but I also tried the mod_php extension and it didn't work either.

Any insight would be greatly appreciated! Thank you in advance!

The following is the PHP code in question.

<?php
include("instructions.php");
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>">
<table align="center" border="0" >
<tr>
<td align="right" class="txt1">Date you will begin the assignment:</td>
<td valign="top" class="txt5">

<?php pres_date(one,date("j"),date("n"),date("Y")); ?>

</td>
</tr>
<tr><td align="right" class="txt1">Date the assignment is due:</td>
<td valign="top" class="txt5">

<?php pres_date(two,"","",date("Y")); ?>

</td></tr></table>

<center><input type="submit" name="submit" value="Calculate Assignment Schedule!"></center>
</form>

<?php


/***********************************************************
Comments:
Modified to allow register_globals to be turned off.
**********************************************************/


if($_REQUEST['submit']){

$today = date("Ymd");



//set up the times

$date1 = "$_GET[monthone]/$_GET[dayone]/$_GET[yearone]";
$date2 = "$_GET[monthtwo]/$_GET[daytwo]/$_GET[yeartwo]";

$time1 = strtotime($date1) + 43200;
$time2 = strtotime($date2);
?>
<div class="div2_2">
<div><strong>Starting on: &nbsp;<?php echo $date1;?></strong></div>
<div><strong>Ending on:&nbsp;<?php echo $date2;?></strong></div>
<?php $days = days_between($time1, $time2);?>
<div><strong>According to the dates you have entered, you have <span class="txt1"><?php echo (int) $days; ?> days</span> to finish.</strong> </div>
</div>
<?php


$dates = out_of_time($time1, $time2, $instructions, $bedTime, $ampm);
?>

<div style="color:#FF0000;"><?php if(days_between($time1, $time2)<0) {

echo "<b>Negative Number of Days:</b> Probably you entered the dates wrong...<br />";

} else if(days_between($time1, $time2)<1) {

echo "You have <b>less than one day</b> to get this done. I hope you're just playing with this thing.<br />";
}

if(days_between($time1, $time2)>99) {

echo "It's never too early to start!<br />";
}?></div>

<?php


echo "<br /><table cellpadding=4 width=100%>";

for($i=0;$i<sizeof($instructions);$i++) {

$j=$i+1; //hacked in because someone forgot the zero item in the array...
?><tr <?php if($i%2==0){ echo 'class="div6"';}?> ><td align=left width=120><div class="txt1">Step <?php echo $j; ?></div></td><td>
<?php
//description
echo "<b>By $dates[$i]:</b> <i>";
$datum = date("Ymd", strtotime($dates[$i]));
echo $instructions[$i][1] . "</i></td></tr>";
?>
<tr <?php if($i%2==0){ echo 'class="div6"';}?>><td></td><td>
<?php
//what should be done
for($j=0; $j<sizeof($instructions[$i][2]); $j++){
echo "&#149; " . $instructions[$i][2][$j] . '<br />';
}

echo "<br />";?>
</td></tr>
<?php
}
echo "</table>";

}
?>

jdMorgan

2:16 pm on Feb 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might want to add some temporary code for testing -- add a few "echo" statements here and there to check for differences in server variables.

For example, just before your form code, add

<br>
<?php echo $_SERVER['PHP_SELF'];?>
<br>

and then check to be sure that the path to the script is correct (is the same and/or appropriate) on both servers.

Jim

cascade27

4:30 pm on Feb 9, 2010 (gmt 0)

10+ Year Member



I tried your suggestion. The returned path on the Linux/Apache server is /index.php/research-guide/research-calculator while the returned path on the Windows/Apache server is /index.php. I'm using the exact same code for the form. What might be causing this to redirect to the home page?

cascade27

5:52 pm on Feb 9, 2010 (gmt 0)

10+ Year Member



The form action was set to
<form action="<?php echo $_SERVER['PHP_SELF'];?>">.
I changed that to the following hard coded path and the form is working now.

<form action="/index.php/research=guide/research-calculator">

Thank you for the great tip, Jim!

cascade27

5:59 pm on Feb 9, 2010 (gmt 0)

10+ Year Member



Simply inserting an empty string instead of the hard coded path worked as well. This is probably a better way to handle this problem.

Also, as I was researching, I came across the following website. They warn about the possible vulnerability of using $_SERVER['PHP_SELF'].

[mc2design.com...]