Jump to content

help with header problem


dadamssg

Recommended Posts

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}");
	}

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
	}

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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}");
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.