dadamssg Posted March 4, 2009 Share Posted March 4, 2009 i have a function/form that allows you to select a month,day, and year. I want it to find the difference in days between the date selected and today. If the number of days is negative i want to redirect to an error page, if its a positive number redirect to a page with that number passed through the URL. i just get an Internet Explorer cannot display this page error now. I have yet to actually put together a 'pickadate.php' page but it should still pass the number through the URL heres the code <?php include("sdateselectfun.php"); $start = strtotime($_POST['smonth']."/".$_POST['sday']."/".$_POST['syear']); $today = strtotime("today"); $difference = ($today-$start); // $days = floor($difference/86400); // OR floor($difference/60/60/24); if ($days < 0 ) { header( "Location: htttp://www.mysite.com/test/error.php"); } else { header( "Location: htttp://www.mysite.com/test/pickadate.php?days={$days}"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148009-help-with-header-problem/ Share on other sites More sharing options...
samshel Posted March 4, 2009 Share Posted March 4, 2009 Location: htttp://www.mysite.com/test/pickadate.php?days={$days} u sure it is htttp: ?? it should be http:// Quote Link to comment https://forums.phpfreaks.com/topic/148009-help-with-header-problem/#findComment-776845 Share on other sites More sharing options...
globalinfoco Posted March 4, 2009 Share Posted March 4, 2009 First, you're probably not getting the redirect to work because redirecting using php should use the exit; like this... <?php //code up here that gets the date submitted by user... if ($days < 0 ) { header( "Location: http://www.mysite.com/test/error.php"); exit; //tells php to not try to finish the script, but just exit... } ?> also, can your day be 0? Probably better do if ($days<1){do this}. That way, if it's equal to 1 (the day is the first of the month) it won't execute the code in the curly braces and won't allow the 0 day error. to calculate the date, use the date() function formatted any way you like (check the php manual for how to use date()) then use explode() at your separators to get array chunks to use as your basis for calculation. to pass something submitted from the first page to yet another page after this, I'd use sessions (of course you could use cookies...but whatever)...so at the top of the page, before anything else, you should have... <?php session_start(); //your code here... ?> oops...I totally missed the htttp:// thing. That might do it too. Quote Link to comment https://forums.phpfreaks.com/topic/148009-help-with-header-problem/#findComment-776847 Share on other sites More sharing options...
jamesxg1 Posted March 5, 2009 Share Posted March 5, 2009 header("Location: http://www.mysite.com/test/pickadate.php?days={$days}"); exit; Quote Link to comment https://forums.phpfreaks.com/topic/148009-help-with-header-problem/#findComment-776859 Share on other sites More sharing options...
dadamssg Posted March 5, 2009 Author Share Posted March 5, 2009 wow im an idiot with the htttp, but its still not working...i changed it to > 1, put session_start(), and then put exit(); on both headers. when ever i attempt it, it doesn't redirect, it just pulls up a 404 with the mysite.com/test/calcday.php in the address bar. calcday.php is the name of the redirect script....heres the adjusted calcday.php <?php session_start(); include("sdateselectfun.php"); $start = strtotime($_POST['smonth']."/".$_POST['sday']."/".$_POST['syear']); $today = strtotime("today"); $difference = ($today-$start); // $days = floor($difference/86400); // OR floor($difference/60/60/24); if ($days < 1 ) { header( "Location: http://www.mysite.com/test/error.php"); exit; } else { header( "Location: http://www.mysite.com/test/pickadate.php?days={$days}"); exit; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148009-help-with-header-problem/#findComment-776863 Share on other sites More sharing options...
dadamssg Posted March 5, 2009 Author Share Posted March 5, 2009 well i got it working sort of...the original day calc script i took a piece of uses $difference = abs($today-$start); but i wanted to know if it was a negative number so i took the absolute value part off....thats why it wasn't working, so if i put it back on it works, but i want to know if the value is negative so how do i do this simple little equation? $difference = ($today-$start); ---doesn't work $difference = $today-$start; ---doesn't work Quote Link to comment https://forums.phpfreaks.com/topic/148009-help-with-header-problem/#findComment-776870 Share on other sites More sharing options...
dadamssg Posted March 5, 2009 Author Share Posted March 5, 2009 if a mod is here, i think this thread could be moved to the PHP Math section now... Quote Link to comment https://forums.phpfreaks.com/topic/148009-help-with-header-problem/#findComment-776878 Share on other sites More sharing options...
dadamssg Posted March 5, 2009 Author Share Posted March 5, 2009 please? simple subtraction..and i can't figure it out Quote Link to comment https://forums.phpfreaks.com/topic/148009-help-with-header-problem/#findComment-776897 Share on other sites More sharing options...
corbin Posted March 5, 2009 Share Posted March 5, 2009 I'm confused at what you want to do. Quote Link to comment https://forums.phpfreaks.com/topic/148009-help-with-header-problem/#findComment-776906 Share on other sites More sharing options...
dadamssg Posted March 5, 2009 Author Share Posted March 5, 2009 im just trying to subtract two numbers that are variables and find out what the number is and if its positive or negative. $difference = abs($today-$start); this works but it only displays positive numbers i want $difference to have the ability to be negative abs() makes that number positive even if its really negative Quote Link to comment https://forums.phpfreaks.com/topic/148009-help-with-header-problem/#findComment-776911 Share on other sites More sharing options...
samshel Posted March 5, 2009 Share Posted March 5, 2009 if($start > $today) $difference = $start - $today; else $difference = $today - $start; Quote Link to comment https://forums.phpfreaks.com/topic/148009-help-with-header-problem/#findComment-776913 Share on other sites More sharing options...
corbin Posted March 5, 2009 Share Posted March 5, 2009 $z = $x - $y; if($z < 0) { //it's negative. } Quote Link to comment https://forums.phpfreaks.com/topic/148009-help-with-header-problem/#findComment-776914 Share on other sites More sharing options...
dadamssg Posted March 5, 2009 Author Share Posted March 5, 2009 thanks everybody!!! i figured it out with this if($start > $today) {$difference = $start - $today;} else { header("Location: http://mysite.com/test/home.php";} Quote Link to comment https://forums.phpfreaks.com/topic/148009-help-with-header-problem/#findComment-776921 Share on other sites More sharing options...
dadamssg Posted March 5, 2009 Author Share Posted March 5, 2009 so the current url is mysite.com/test/whatever.php?days=1 im tryin to program a button that will take the days number and put it at the end of another url...i.e. mysite.com/test/anotherpage.php?days=1. heres what i got, but i just get this--mysite.com/test/anotherpage.php?days= days equals nothing..anyways heres the script <?php /*creates a new url with variable to send to justthisday.php*/ session_start(); $days = $_GET["days"]; header("Location: http://www.mysite.com/test/anotherpage.php?days={$days}"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/148009-help-with-header-problem/#findComment-777020 Share on other sites More sharing options...
dadamssg Posted March 5, 2009 Author Share Posted March 5, 2009 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/148009-help-with-header-problem/#findComment-777528 Share on other sites More sharing options...
samshel Posted March 5, 2009 Share Posted March 5, 2009 it should work..try this <?php /*creates a new url with variable to send to justthisday.php*/ session_start(); $days = $_GET["days"]; echo $days; //header("Location: http://www.mysite.com/test/anotherpage.php?days=".$days); ?> if $days is echoed properly, comment echo and uncomment line below. Quote Link to comment https://forums.phpfreaks.com/topic/148009-help-with-header-problem/#findComment-777673 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.