Any php pros around today?

by 6 replies
8
Hey guys,

I'm trying to figure out where I've gone wrong with the following php code. I'm sure it's something basic, as my php skills leave a lot to be desired.

PHP Code:

<?php

// Get URL text from address bar 
// example --> www.website.com/script.php?url_date1=9-6-2010&url_date2=9-7-2010&url_date3=9-8-2010

    
$url_date1=$_GET['url_date1'];
    
$url_date2=$_GET['url_date2'];
    
$url_date3=$_GET['url_date3'];

// Get the current date (EST), and save it as a variable

date_default_timezone_set('America/New_York');

$current_date date("n-j-Y");

// Check to see if the current date matches any of the 3 URL dates. 
// If so, stay on current webpage (www.website.com/script.php). 
// If current date does not match any of the 3 URL dates, redirect to www.website.com/nomatch.html

if ($current_date != ($url_date1 || $url_date2 || $url_date3)) {header("Location: http://www.website.com/nomatch.html");
}

?>
The problem is, it is redirecting to nomatch.html even when it's not supposed to. Any ideas?
#programming #php #pros #today
  • You can't do multiple "if" conditions that way specify them all separately -

    PHP Code:
    if ( current_date != url_date1 && current_date != url_date2 && current_date != url_date3 ) {
      
    // redirect

    PS: I have no idea why it's stripping out variables when I put the $ in front so I've left that off.
    • [ 1 ] Thanks
    • [1] reply
    • Hey Andy,

      Yeah, I know just enough php to be dangerous.

      Thanks for your help with this... works great now!
  • ok but its good if you convert all the dates in time and then compare them.

    strtotime() is good for conversion.
    It would be best if you use
    • [ 1 ] Thanks
  • Your if statement is incorrect you need to repeat if $variable == ?? || $varibale ==
    • [ 1 ] Thanks
    • [1] reply
    • Not sure why, but php code does not display correctly inside the php tags, replace the (DOLLARSIGN) with the real $ sign
      PHP Code:
      // Get URL text from address bar
      // example --> www.website.com/script.php?url_date1=9-6-2010&url_date2=9-7-2010&url_date3=9-8-2010

          
      (DOLLARSIGN)url_date1=(DOLLARSIGN)_GET['url_date1'];
          (
      DOLLARSIGN)url_date2=(DOLLARSIGN)_GET['url_date2'];
          (
      DOLLARSIGN)url_date3=(DOLLARSIGN)_GET['url_date3'];

      // Get the current date (EST), and save it as a variable

      date_default_timezone_set('America/New_York');

      (
      DOLLARSIGN)current_date date("n-j-Y");

      // Check to see if the current date matches any of the 3 URL dates.
      // If so, stay on current webpage (www.website.com/script.php).
      // If current date does not match any of the 3 URL dates, redirect to www.website.com/nomatch.html

      switch((DOLLARSIGN)current_date){
          case (
      DOLLARSIGN)url_date1:
          case (
      DOLLARSIGN)url_date2:
          case (
      DOLLARSIGN)url_date3:
                 
      // the current date DOES match either date 1, 2 or 3 so continue
              
      break;
          default:
              
      //for anything else, redirect.
              
      header("Location: http://www.website.com/nomatch.html");
              break;

      • [ 1 ] Thanks
      • [1] reply

Next Topics on Trending Feed