Any php pros around today?

6 replies
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?
#php #pros #today
  • Profile picture of the author Andy Fletcher
    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.
    {{ DiscussionBoard.errors[2564604].message }}
    • Profile picture of the author Brandon Tanner
      Hey Andy,

      Yeah, I know just enough php to be dangerous.

      Thanks for your help with this... works great now!
      Signature

      {{ DiscussionBoard.errors[2564841].message }}
  • Profile picture of the author zeeshi570
    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
    {{ DiscussionBoard.errors[2565025].message }}
  • Profile picture of the author bugbuguk
    Your if statement is incorrect you need to repeat if $variable == ?? || $varibale ==
    Signature

    Google News Press Releases , PM For Details :)

    {{ DiscussionBoard.errors[2574612].message }}
    • Profile picture of the author ussher
      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;

      Signature

      "Jamroom is a Profile Centric CMS system suitable as a development framework for building entire communities. Highly modular in concept. Suitable for enterprise level development teams or solo freelancers."

      - jamroom.net
      Download Jamroom free: Download
      {{ DiscussionBoard.errors[2575842].message }}
      • Profile picture of the author Brandon Tanner
        ^^^Thanks guys! I already figured it out, but I cannot edit my original post to reflect that, for some reason.

        Thanks anyways
        Signature

        {{ DiscussionBoard.errors[2577304].message }}

Trending Topics