Jump to content

deadimp

Members
  • Posts

    185
  • Joined

  • Last visited

    Never

Posts posted by deadimp

  1. Wait... Are you having the user's input as the MySQL connection's information? If so, that's a massive no-no, for obvious reasons (which can be explained if you want).

     

    would like to rub minds with any one

    I got a weird picture in my head after reading this...

  2. Let the positive rule overrule the negative one. Just use OR to do the logic between multiple groups.

    If that doesn't work out in certain situtations, see if there's some sort of priority you can assign to a group/permission... I dunno.

  3. Undefined offset means that you're trying to access a part of an array that doesn't exist (it's in the for-loop you're doing this).

    Use print_r() on $row2 to see if you're getting anything from the query. You should be, since the number of rows shows that you're getting something.

     

    Also, use code tags!

  4. TheFilmGod's advice wasn't spam, and try to be somewhat grateful. Looking at your code, it looks like you need to sit down with a few tutorials, or just go look at some site's HTML/CSS source. My suggestion would be, if you want to play around with CSS, get some development tools that let you actively edit your page, something like Firebug for Firefox.

  5. I honestly don't see the need for a templating engine, unless you're allowing for custom pages and you need security. I just use PHP short-tags for small amounts of content (<?=$var?>).

     

    Liquid Fire << If you're worried about messing up your HTML code, use a validator. The extension for Firefox is extremely helpful, in addition to the sytnax highlighting for the source view, and especially FireBug.

  6. I logged in, or at least it said it thought I logged in, and the only thing that really changed was the header (the login section disappeared). After that, I couldn't figure what else had changed (though I know that's not the point of all this at the moment).

     

    I couldn't figure out how to log out, so I used another browser to screw around some. The login gives different messages for different passwords that I try, so I'm not sure what could be causing that. I'm not that much of a hacker in the sense of network security, so I'm not sure what else to try.

  7. I'm also doing the same kinda thing also with Thacmus.

     

    I agree with dbo that PHP has a large amount of resources and libraries, and that you don't need to spend too much time re-writing low-level functionality that may have already been implemented. The only time you might need to that if you wish to have your own style, or maybe just an implementation for practice's sake, but if it's different styling you're after, a basic wrapper could do that for you. Just don't go crazy with it all.

     

    For your html/xhtml classes, you ought to look into DOM and SimpleXML under the PHP documentation.

    As for the session class, I'm not sure you'll really need it if it's just a different venue for $_SESSION. When you design a wrapper for something, you generally want to make it so that it's easier / more compact to do something (and make it easy to change the low-level stuff without really having to change much else).

  8. Ah, crap. I just ran into a problem using ReflectionMethod.

    If I try and invoke one of the extended class's methods using ReflectionMethod::invoke/invokeArgs(), it throws an exception with the message "Given object is not an instance of the class this method was declared in".

     

    Code:

    /virtual.php

    <?php
    //Thacmus [http://sourceforge.net/projects/thacmus/] - Core - 'Virtual' class
    
    //Virtual class defintion
    //Is there a way to do this more statically? Or no?
    //To get all of the variables, a temp class has to be constructed
    //I'm not sure if there are any magic overloads to fool the instanceof / is_a / == [class] operators...
    class Virtual {
    //That's right... Just about the only private variable in all of Thacmus
    private $_base=null; //List of ReflectorClass's - Idea from 448191 (http://www.phpfreaks.com/forums/index.php/topic,152955.msg691897.html)
    //Initialize 
    	//Can only be called once
    	//$ctor - Call constructors - suggested to be true
    	//[...] - Classes to extend (define using string)
    		//Format: string $class -OR- {[string] $class, $arg1, $arg2...} (args are for ctor)
    		//__construct() will be called for the class if it exists.
    	//Order of definition means priority. First defined is first constructed, and copied.
    	//This also pertains to function search order. The first class that has a method undefined in the actual class has its method called.
    	//This is unlike C++, where defining two basic functions would have the compiler stop. Remember: run-time.
    function extend($ctor) {
    	$list=&$this->_base;
    	if ($list) {
    		trigger_error("Virtual::extend(): Already called",E_USER_WARNING);
    		dump_callstack();
    	}
    	$list=array();
    	$func_arg=func_get_args();
    	$start=1;
    	if (!is_bool($ctor)) {
    		$start=0; //Start at that, since the ctor flag is off
    		$ctor=false;
    	}
    	for ($i=$start;$i<count($func_arg);$i++) {
    		$def=&$func_arg[$i];
    		$class=$def;
    		$arg=array();
    		if (is_array($def)) {
    			$class=$def[0];
    			$arg=$def;
    			array_shift($arg); //Pop the front off
    		}
    		$class=new ReflectionClass($class);
    		if ($ctor && $class->hasMethod("__construct")) {
    			//Calling the ctor ought to init some of the variables
    			$this->callMethod($class,"__construct",$arg);
    			//What happens if a diamond structure causes one ctor (the very base) to be called twice... Igh...
    		}
    		//Check the base class, copy any variables not init'd by the ctor
    			//Only shallow copying should be needed since objects can't be instantiated in the class definition
    			//I'm not sure how well this will handle statics and private variables...
    		//Note: This can get ugly with multiple classes... It might be alright with the dreaded diamond structure,
    			//but using classes with the same variables but different initial values (that have a vital role as that) could screw some stuff up
    		//Can't figure out how to get values of default properties from ReflectionProperty
    		$vars=get_class_vars($class->getName()); //Gah! This doesn't exclude statics!
    		foreach ($vars as $var => $value) {
    			if (!property_exists($this,$var)) $this->$var=$value; //Not sure how the whole statics thing might affect this
    		}
    		//Add class name to base list
    		$list[]=$class;
    	}
    }
    //Redirect non-specified (ie. $this->func() instead of Class::func()) calls to class
    function __call($func,$arg) {
    	foreach ($this->_base as $class) {
    		if ($class->hasMethod($func)) {
    			return $this->callMethod($class,$func,$arg);
    		}
    	}
    	//Didn't work, warn
    	dump_callstack();
    	trigger_error("Unknown virtual method: ".get_class($this)."::$func()",E_USER_FATAL);
    }
    //Call a method, since call_user_func() doesn't scope inside the class
    	//I made a post about this on http://www.php.net/manual/en/function.call-user-func.php
    function callMethod($class,$func,$arg=array()) {
    	$call=$class->getMethod($func);
    	return $call->invokeArgs($this,$arg);
    }
    }
    
    /* //Example 
    class Test extends Virtual { //Do not extend the other classes - extend only Virtual
    function __construct() {
    	//This call adds the class definitions, and calls the constructors if they exist
    	Virtual::extend(true, OrderedItem, UserItem, array(SomeClass, "biscuit",-2));
    }
    }
    //It may just be with my PHP installation, but non-defined constants return strings of that identifier
    //Therefore, using the actual class names (not simply strings) will work
    */
    ?>

    Test:

    <?php
    include("../thacmus/virtual.php");
    
    class Test extends Virtual {
    function __construct() {
    	Virtual::extend(Sub);
    }
    function blarg() {
    	echo "blarg ";
    	Sub::test();
    }
    }
    class Sub {
    function stuff() {
    	echo "stuff ";
    }
    }
    $obj=new Test();
    $obj->stuff();
    ?>

  9. What do you mean by "since call_user_func() doesn't scope inside the class"?

    I tried the following callbacks in a call_user_func() call inside of a $this method (non-static):

    > array($class,"method") - If the method references to $this, then it would generate the standard error that $this was unknown. If you try and invoke the constructor, it will say that it cannot be invoked as a static. This isn't the same as simply calling [class]::method() directly in the code.

    > array($this,"$class::method") OR "$class::method" - It would throw an error about invalid callback (this was on PHP 5.2.2, though. I've upgraded, but haven't tested this out the same yet).

    I had made a comment about this on call_user_func() in the manual, but it seems to have gotten lost. I probably didn't submit it right or something or other (though it did tell me that it got through).

     

    If for some reason you want to avoid call_user_func, surely you could use Refelction and not resort to eval???

    Yeah, I don't know why, but I was afraid to look into the Reflection library. That's probably a whole lot better than what I'm doing now.

    Thanks for the tip!

  10. Just a couple of other projects you might want to try out if it doesn't work:

    Thacmus - Has a Media module, which can do section [batch] resizing and thumbnailing. If you just want the resize code, go to /db/media.php and look at Media::imgResize().

    BAIR - Library meant for resizing

     

    To test your scripts a little more easily, you'll want to setup a small, local test server. I'd suggest using XAMPP, which comes with PHP 5.2.3 and MySQL 5.x (and you can switch to PHP 4.x if you want). That way, debugging can go a lot quicker.

  11. This may not be the cause of that memory usage, but why are you connecting to your database in your execute_mysql() statement? It'd be better if you connected outside of that function so you don't have to write as much for that function - in fact, there's not much use for it.

     

    As for Sajax and all that, I'm not sure, since I haven't worked with it much. But why are you using a timer to execute ajax requests? Could that possibly overlap? Plus, why do you define InitializeTimer() with secs=1, in which you call StartTheTimer(), which then checks if secs==1, where you could just move that code to InitializeTimer() without the conditional in it.

     

    Do you know what happens when you try a different browser?

  12. Try dumping the raw info using print_r($_POST).

     

    EDIT: Ah, forgot! You can't store values in a checkbox. It's either on or off. One thing you could try is setting some different indexes for your control, like this:

    <p>
    <input type='checkbox' name='type[brunch]'>
    <input type='checkbox' name='type[dance]'>
    <input type='checkbox' name='type[game]'>
    </p>
    ...
    <?
    //Check submit
    $type=$_POST['type'];
    foreach ($type as $key => $value) {
    echo "$key: ".($value ? "Y" : "N")."<br>";
    }
    ?>

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.