Page 1 of 1

Need help with a simple date script

Posted: Wed Mar 16, 2011 2:24 pm
by Sartor
Hey guys, this is my first post here. I'm by no means a PHP dev, I know this and that about PHP but not extensively. So heres the deal:

I'm trying to post a certain set of dates to a customer. The formula is whatever day they signup on, plus 19 days, and the end of the dates is 77 days from the 19 days. So if a customer signed up today, march 16th, their dates would be:

March 16th + 19 = April 4th
April 4 + 77 = June 1st

Dates = April 4th to June 1st

So heres the code I have right now that captures those dates:

Code: Select all

<?php
$startdate = mktime (0,0,0,date("m") ,date("d")+19,date("Y"));
$tpstart = date("l F j", $startdate)  ."," . date(" Y");
$enddate = mktime (0,0,0,date("m") ,date("d")+77,date("Y"));
$tpend = date("l F j", $enddate) ."," . date(" Y");
?>
So when I echo this out everything looks fine. The problem is, alot of our customers aren't going to have these variables on file, because its a new system for us. What happens is when they signup, these dates are added to their unique URL string, which would look something like FirstName=blah&SIGNUP=April+4&TPend=June+1 (where TPend is the end date to their specific dates)

What i need to do is have a script to detect if these variables "SIGNUP" and "TPend" are in the URL string. If they aren't, then I need to echo different dates. so i'm sure it would be some sort of if else statement. For instance

New user browses to our site, with variables SIGNUP and TPend present in the URL. I would simply just do a <?php echo $_GET['SIGNUP']; ?> to post that. But if it doesn't exist in the url, i need to do something else. Its sort of hard to explain so please bear with me. Is there a specific way to detect if a variable is present in a URL, and if it isn't, post a different variable?

Any help appreciated!

thanks!

Re: Need help with a simple date script

Posted: Wed Mar 16, 2011 2:35 pm
by kristen
My answer is 2 parts:

The "here's how you do it" part:

http://www.yoursite.com/customer.php?mid=April&did=1

mid = month
did = date

and so forth...

So you would $_GET['mid'] and $GET['did']

The "this is a really bad idea" part:

I don't know what use you're putting this to, but consider carefully that all the customer has to do is alter those variable = values. If you are using this as ANY kind of security to limit or control access you're in for a nasty surprise. All I would have to do would be to edit my "custom URL" to whatever *I* (the mischievous user) cared for it to be.

Additionally you would never want to just <?PHP echo $_GET['mid']; ?> Ever. For pretty much the same reason as above- the code faithfully goes and gets what's in the URL. Safe or not.

Re: Need help with a simple date script

Posted: Wed Mar 16, 2011 2:46 pm
by Sartor
Thanks for the reply --

This has nothing to do with any security measures and it does not limit any kind of control, so i'm not worried about that at all. its just used to read what dates a specific user has in relation to the information stored in our backend.

I already know how to grab the dates from the url, thats not the problem. The problem is I need to do an else statement if the dates are NOT present in the url.

Re: Need help with a simple date script

Posted: Wed Mar 16, 2011 5:42 pm
by danwguy
try using something like this then...

Code: Select all

if(isset($_GET['SIGNUP'] && $_GET['TPend'])) {
//do what you want if they are there
} else {
//do what you want if they are not there
}