PHP Date Function

Discussion in 'PHP' started by sonu21, Mar 3, 2012.

  1. #1
    Hello Guys,Can any one help me it's quite easy I think but I am not getting it.I want condition on this code.
    <?php
    //define the year
    $thisYear = date('Y');
    $filtered = array_map("strip", $_POST);
    
    function strip($val){
    $val = strip_tags($val);
    $val = htmlentities($val,ENT_QUOTES);
    return $val;
    }
    
    function renderDropDown($name, $opts, $valueIsKey=true){
    $out = array();
    $out[] = '<select name="'.$name.'">';
    foreach($opts as $key => $val){
        if($valueIsKey){
            $out[] = '<option value="'.$key.'">'.$val.'</option>';
        } else {
            $out[] = '<option value="'.$val.'">'.$val.'</option>';
        }
    }
    $out[] = '</select>';
    
    return implode("\n", $out);
    }
    
    if($_POST['submit'] != 'submit' && !isset($_POST['submit'])){
    //define text months
    for($i=2; $i<=13; $i++){
        $calTime = mktime(0, 0, 0, $i, 0, $thisYear);
        $months[date('m', $calTime)] = date('M', $calTime);
    }
    $renderHTML = true;
    } else {    
        //try to construct a valid date from post data
    if(checkdate($filtered['months'], $filtered['days'], $filtered['years'])){
        //valid date..check if they are 18+
        $validAge = $thisYear - 18;
        if($filtered['years'] <= $validAge){
            //inside you go
            die('Location: http://www.ask.com');
        } else {
            header('Location: http://www.google.com');
        }
    } else {
        //invalid date.. try again mr hacker
    }
    }
    
    if($renderHTML){
    ?>
    <form name="ageVerifier" action="" method="post">
        Day: <?php print(renderDropDown('days', range(1,31), false)); ?>
        Month: <?php print(renderDropDown('months', $months)); ?>
        Year: <?php print(renderDropDown('years', range($thisYear, $thisYear-100), false)); ?>
        <input type="submit" name="submit" value="submit" />
    </form>
    <?php
    }
    ?>
    PHP:
    I have the code but it's not working correctly.If age is under 18 then it redirecting is great but if age is minimum 18 then I want to redirect to another page.Can any one please help me.

    Thanks in Advance.

     
    Last edited: Mar 3, 2012
    sonu21, Mar 3, 2012 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
  3. HiTEC

    HiTEC Well-Known Member

    Messages:
    92
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #3
    I see this code "die('Location: http://www.ask.com');" this seems wrong ;p

    it should be header('Location: http://www.ask.com'); right?

    Regards.
     
    HiTEC, Mar 4, 2012 IP