Can anyone take a look at my code and tell me whats the problem..

Discussion in 'PHP' started by secretsau, Aug 24, 2009.

  1. #1
    hello,

    this the code of an advertising blog i have :

    	// Session Face
    	$sid  = md5(time()).md5("LeQuangDung");
    	
    	// Redirect Function
    	function redirect($location)
    	{
    		// Redirect for IIS 
            exit("<html><head><meta http-equiv=\"refresh\" content=\"0; url=". $location . "\"></head><body></body></html>");
    	}
    
    	function CheckEmail($Email = "")
    	{
    		if (ereg("[[:alnum:]]+@[[:alnum:]]+\.[[:alnum:]]+", $Email)) {
    			return true;
    		} else {
    			return false;
    		}
    	}
    
    	function Duration($timeposted, $timenow)
    	{
    		$timeleft = $timenow - $timeposted;
    		$days = floor($timeleft / 86400); 
    		$hours = floor(($timeleft - $days * 86400) / 3600); 
    		$mins = floor(($timeleft - $days * 86400 - $hours * 3600) / 60); 
    		$secs = floor($timeleft - $days * 86400 - $hours * 3600 - $mins * 60);
    		return $days;
    	}
    
    	function CurrencyFormat1($number)
    	{
    		return  number_format($number,2);
    /*		if ($number<0)
    		{
    			$number = -$number;
    			$num1 = "-";
    		}
    
    		$num1 .= (int)(($number*100)/100);
    		$num2 = ($number*100)%100;
    
    		if ($num2<10)
    			$num2 = "0".$num2;
    
    		return (string)$num1.".".(string)$num2;*/
    	}
    
    	function CurrencyFormat($part1 = "", $part2 = "")
    	{
    		$num1 = ($part1 == "")?0:(int)$part1;
    		$num2 = ($part2 == "")?0:(int)$part2;
    		if ($num2<10)
    			$num2 = "0".$num2;
    
    		return (string)$num1.".".(string)$num2;
    	}
    
    	function DatetimeFormat($timeStamp)
    	{
    		$date = getdate($timeStamp);$tmpd = getdate(mktime(0,0,0,$m,1,$year));
    		return ($date["mon"]."/".$date["mday"]."/".$date["year"]);
    //		return date("F j, Y, g:i a",$timeStamp);
    	}
    
    	function DatetimeFullFormat($timeStamp)
    	{
    		$date = getdate($timeStamp);
    		$str = $date["weekday"].", ".$date["month"]." ".$date["mday"].", ".$date["year"];
    		return $str;//strtoupper($str); 
    	}
    	
    	function Gettime($hour, $mi, $se, $mon, $day, $year, $AMPM)
    	{
    		if (strtolower($AMPM) == "pm" && $hour<13)
    			$hour = 12+$hour;
    
    		if (strtolower($AMPM) == "am" && $hour>12)
    			$hour = $hour - 12;
    
    		return mktime($hour, $mi, $se, $mon, $day, $year);
    	}
    
    	function generatePassword ($length = 8)
    	{
    
    	  // start with a blank password
    	  $password = "";
    
    	  // define possible characters
    	  $possible = "0123456789bcdfghjkmnpqrstvwxyz"; 
    		
    	  // set up a counter
    	  $i = 0; 
    		
    	  // add random characters to $password until $length is reached
    	  while ($i < $length) { 
    
    		// pick a random character from the possible ones
    		$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
    			
    		// we don't want this character if it's already in the password
    		if (!strstr($password, $char)) { 
    		  $password .= $char;
    		  $i++;
    		}
    
    	  }
    
    	  // done!
    	  return $password;
    
    	}
    ?>
    PHP:
    the problem is, when i want to add a banner ad and everything works good until this error appeared :

    Warning: getdate() expects parameter 1 to be long, string given in /home/blogadve/public_html/adblog/common.php on line 70

    so, can anyone tell me whats wrong with my code? :confused:
     
    secretsau, Aug 24, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try:

     $date = getdate((int) $timeStamp);
    PHP:
    If that doesn't work, it would be helpful to see what's inside the variable.. Do
     echo $timeStamp;
    PHP:
     
    premiumscripts, Aug 24, 2009 IP
  3. secretsau

    secretsau Active Member

    Messages:
    402
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    yep it worked except that the date is wrong!? 12/31/1969
     
    secretsau, Aug 24, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Something is wrong with your input. Show it to me (the echo line)
     
    premiumscripts, Aug 24, 2009 IP
  5. secretsau

    secretsau Active Member

    Messages:
    402
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #5
    sorry i did not get that last bit? "Show it to me (the echo line) " ??
     
    secretsau, Aug 24, 2009 IP
  6. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Go back to my first post, I asked you to add a line. echo $timestamp.
     
    premiumscripts, Aug 24, 2009 IP
  7. secretsau

    secretsau Active Member

    Messages:
    402
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #7
    where do i add that?? In the same place as i put : $date = getdate((int) $timeStamp); and do i replace it??
     
    secretsau, Aug 24, 2009 IP
  8. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Before that line. Doesn't really matter.. It's just output.
     
    premiumscripts, Aug 24, 2009 IP
  9. secretsau

    secretsau Active Member

    Messages:
    402
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #9
    ok i added it then now on the page it says : Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /home/blogadve/public_html/adblog/common.php on line 71
     
    secretsau, Aug 24, 2009 IP
  10. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #10
    You ofcouse need a ; at the end mate.. Did you not copy my original line? If you want to edit PHP yourself, you should at least learn the basics.
     
    premiumscripts, Aug 24, 2009 IP
  11. secretsau

    secretsau Active Member

    Messages:
    402
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #11
    ohh sorry yeah its fixed now?? What do i do?
     
    secretsau, Aug 24, 2009 IP
  12. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Show me the value ofcourse. And if it's not outputting anything, it means you are not passing along the correct input..
     
    premiumscripts, Aug 24, 2009 IP
  13. secretsau

    secretsau Active Member

    Messages:
    402
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #13
    Here it is below

     
    secretsau, Aug 24, 2009 IP
  14. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I didn't ask for that, I asked for the output of the echo statement. Anyway, I think it would be best if you just hired someone..
     
    premiumscripts, Aug 24, 2009 IP
  15. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Apparently so, since if someone doesn't understand the most basic function of PHP being 'echo' , then they don't really know any PHP and could simply be a "cut-n-paste" coder.

    Besides this wouldn't work anyways :

    
    function DatetimeFormat($timeStamp)
    {
    echo $timestamp;
    $date = getdate((int) $timeStamp);
    return ($date["mon"]."/".$date["mday"]."/".$date["year"]);
    //	 return date("F j, Y, g:i a",$timeStamp);
    }
    
    Code (markup):
    Because variables and function names are case sensitive, and as such $timestamp is not the same as $timeStamp being passed. Short of Class Constructors, its best pratice to keep all variables and function names in lowercase.
     
    kblessinggr, Aug 24, 2009 IP
  16. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Only in PHP can someone be a cut'n paste coder :) I wish it wasn't so damn easy ;)
     
    premiumscripts, Aug 24, 2009 IP
  17. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #17
    QBasic
    Javascript
    Visual Basic
    .bat ch files.
    Hell even Pascal
    Or almost any barely human readable procedural language for that matter

    I've seen "Script Kiddies" (as we used to call em) do so in those languages years ago.
     
    kblessinggr, Aug 24, 2009 IP
  18. renownedmedia

    renownedmedia Well-Known Member

    Messages:
    65
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    100
    #18
    Take a look at the function strtotime(), it does a great job of turning random strings into the PHP time format!
     
    renownedmedia, Aug 24, 2009 IP
  19. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #19
    It doesn't convert to PHP time format, converts it to Unix time format.

    Also strtotime() has a bad memory leak if you're using PHP 5.2.8
     
    kblessinggr, Aug 24, 2009 IP
  20. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #20
    Hmm, not using functions because there's a memory leak in a minor version of PHP? That's the user's problem, not the developer's. I guess you could code around it, but why bother? Anyway, how do you know this? Is there some kind of list for these types of things?
     
    premiumscripts, Aug 24, 2009 IP