Jump to content


  • Posts

  • Joined

  • Last visited

Posts posted by Drongo_III

  1. Hi Ben


    Firstly you would be best to have a setter method on your first calculator class e.g.:

    public function setNumbers($propName, $propValue){
            $this->{$propName} = (int)$this->$propValue;

    You then call that method like this to set a new property without being constrained to particular methods:


    $WhateverYourObjectIsCalled->setNumbers('number1', 50);


    Extends vs include


    The point of extending a class is that you inherit all of the properties from the parent class and these can be overridden with new versions of the property or methods from the extending/child class.


    When you extend a class you do not need to implicitly instantiate the parent class and you can access all of it's methods using $this-> - i.e. as if those properties and methods were part of the extending class.


    However, if you simply included the new class and instantiated you would have to access the base class' properties via an instance of that object.


    This is best illustrated in code:

    //############ Preferred inheritance route ##########
    class a {
    	public $somePropFromA = 'Prop from A!';
    class b extends a{
    	public function getProp(){
    	echo $this->somePropFromA; //Can access any property of method from 'a' using $this->
    $b = new b;
    //############ include route - not preferred ##############
    //lets imagine you have included class 'c' file here 
    class c {
    	public $somePropFromC = 'Prop from C!';
    //note we are not extending C in this instance
    class d {
    	public function __construct(){
                   //because the class is now included and not extended the properties aren't inherited and can only be accessed
                   //from an object instance - in this case c = new c;
    		$this->c = new c; 
    	public function getProp(){
    	      //echo $this->somePropFromC;  CANNOT NOW ACESS C's properties using $this-> because we arent inheriting them
    		echo $this->c->somePropFromC; //this is how we must now access properties
    $d = new d;

    So hopefully from the code above you can see by not extending the class you lose the ability to inherit it's properties and methods - though they can still be accessed via a much more verbose syntax.


    It's hard to see the significance in the simplistic calculator class but once the complexity of the base class increases you then begin the see the power and flexibility afforded by inheritance via extending parent classes.


    I am sure that someone else will propose additional benefits but this is one of the main ones that springs to my mind.

  2. Hello all


    I am implementing TinyMCE in a small CMS system. I have enabled the 'image insert/edit plugin' (as per code below/attached screenshot) but it's very limited. 


    I therefore would like to edit the popup for this plugin to include a custom button which will pop an additional overlay displaying all available images from the server (rather than just the text list that the plugin by default allows).


    The problem is that the plugin is minified in the production version of tinyMCE, so I it's hard to work directly on that, and when I download the development version of tinyMCE I cannot see the corresponding image plugin that exists in the production version.


    So, can anyone advise on:


    a) Should I be using the development package to edit this plugin?

    b) Is the plugin simply not available in the development package? Or is in under some other name?

    c) is there actually a much simpler way to add a button to this popup that doesn't require changing the plugin at all?



    Any help would be massively appreciated!



    <script type="text/javascript">
        selector: "textarea",
    	 plugins: "image",
             image_advtab: true,
  3. Ok so my first post didn't garner much of  a response but hopefully now I have more of an idea of what I need to achieve one of you bright sparks can nudge me on course.


    I'm using php/mysql to create a search engine for a site i am working on.


    I've resorted to using MATCH/AGAINST in Boolean mode (code snippet below) but I really am quite stuck on how I might go about ordering the results based on relevancy.  IF someone could point me in the right direction on this it would be very helpful :/

    SELECT * FROM articles
    WHERE MATCH (title,body) AGAINST ('database' IN BOOLEAN MODE);
  4. Hello


    I soon need to build a php/mysql search feature for a website and I am hoping someone can nudge my research in the right direction.


    The search functionality is essentially an index of pages. The database table will likely never hold more than 1000 rows max.


    I read on the MYSQL website that using natural language full text searches are the way to go. However, it also states that where a table contains limited rows, and therefore where occurrences of a search term appear more than 50% of the time, this can return no results.


    So here are my questions:


    1. Is it correct to use natural language full text searches for a table with no more rows than around 1000?
    2. If not, can anyone propose another method. For instance should I simply stick to using  LIKE searches?
    3. Any tips for ensuring efficiency?


    Any help you can provide is much appreciated as I've not tried to build a search function before so this is all a bit new!



  5. Hi Guys


    I am after a little advice.


    I'm working on a fairly large volume site -2-3 mill hits a month for a large company. The reason this is significant will become clear.


    I'm creating a multistage signup form (though it is very specific and volumes are likely to be quite low) and part of it requires image uploads - around 2-6 images with max total file size of around 10mb.


    However, I am a little concerned as to whether this image upload represents a vulnerability. Images get uploaded halfway through the registration process irrespective of whether the user completes because we use the uploaded images to display as thumb nails in the page as they upload each one.


    I have a cron script set to run each day that cleans downs images of more than 1 day old that don't have a corresponding database record. But my concern is if someone wanted to attack the form they could probably automate an upload to the site over and over and potentially cause big problems.


    I was wondering if anyone else had ever encountered the same issue or concern and how you recommend getting around it.


    Possible ways I can think of are:


    • log IPs and deny multiple submissions from the same IP
    • Run the cron more frequently to clean up

    I have also considered some sort of unload ajax event that would call a cleanup script but I wasn't sure that would really fix this issue since a seasoned attacke rwould likely circumvent that quite easily.


    Any advice is very welcome.





  6. Thanks guys - that's a very definitive answer.


    I realise it's just an OR statement but I've never tried to return one of two values -  I would ordinarily evaluate the statement and return one or the other via a conditional, which seems to be the consensus. But I suppose there might be handy instances where it's worth using.


    Thanks all.

  7. Hello


    I've recently been working with some JS code that has a return statement that will return one or other of a value. A terrible example...

    function blah(){
      return 1==2 || 2==2;

    Obviously this is just to illustrate the point.  I have to admit this was new on me and I would usually do some evaluation before returning and I didn't realise you could do what the code above does.


    I cant really find anything on this so I have some basic questions:


    1. Does this simply return the first of the two that resolves to true?
    2. Can it only be used with boolean statements?
    3. Can this be used in other languages?
    4. And does it have a name?
  8. Hello


    I am trying to create a script that will animate the sizes of images based on the user scrolling up or down the page. 

    My intention was to use the scroll values to increase and decrease the size of an image based on the scroll value. So if the user is going down then increase the size and if the user is scrolling up then decrease the image size.


    I've been trying to code below but the issue is that the scroll event seems to fire inconsistently.  Scrolling down might fire 15 'down' events, but then scrolling up only triggers 7 'up' events. So when I apply this to an image the image ultimately grows and never shrinks back to it's original size.


    Hopefully someone can point me in the right direction or suggest a better method.

    			var start = 0;
    			$(window).scroll(function() {
    				var st = $(this).scrollTop();
    				var timeout = setTimeout(function(){
    					if(st < start){
    					else {
    				}, 100);			
    			start =$(this).scrollTop();
  9. Try the following rewrite rule

    RewriteRule ^card/somepage/otherpage/ default.php [QSA]

    default.php should be in your sites root folder



    The default.php file is in the card directory. So I tried

    RewriteEngine On
    RewriteRule ^card/somepage/otherpage/ /card/default.php [QSA]

    If I do this as a straight redirectMatch it works fine but I don't think the query string is presreved in that instance.

  10. Dont use absolute http urls for the replacement url. This will cause a redirect. Just provide the path to the file the rewrite rule should perform the request to

    RewriteEngine On
    RewriteRule ^/card/somepage/otherpage/ default.php [QSA]

     The url site.com/card/somepage/otherpage/ and site.com/card/somepage/otherpage/?id=345 should call default.php. To get the id from the query string use the $_GET['id'] superglobal variable



    Unfortunately this doesn't appear to work.


    I just get:


    The requested URL /card/somepage/otherpage/ was not found on this server.

    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


    I assume the apach isn;t finding a match.  Any suggestions?

  11. Hi Guys


    I wonder if someone can help. 


    I need to rewrite a url that so a pretty url such as /card/somedir/somepage?id=345 will rewrite to the real script page with queries strings


    I have been trying the following to no avail:

    RewriteEngine On
    RewriteRule ^/card/somepage/otherpage/ http://www.mysite.com/card/default.php [QSA]

    I really need to bone up on this stuff because I find from one server to the next things seem a bit inconsistent. But anyway if anyone could point out where I am going wrong it would be appreciated.



  12. Hello


    Not sure if anyone can help but I am trying to setup cross domain tracking on Google analytics.


    Does anyone know of a particular cookie on analytics I should look out for to confirm cross site tracking is working. Is there a cookie that carries a particular id for instance ?


    Done a bit of searching around on this but to no avail.





  13. This is just a stab in the dark but you might want to try using the jquery method .prop() instead of attr(). I believe that since jquery 1.6 attr() gets the value set in the markup - which is likely undefined. Whereas .prop retrieves it from the dom.


    A way to test if this is the case would be to console.log or alert the value of var newscrollHeight and see what you're getting each time the ajax runs. You may have already done that tho! 

  14. I might have misunderstood your issue but you can of course use something like .htaccess file to redirect requests for images - or indeed anything else.


    For example in a .htaccess file:

    RewriteEngine On
    redirectmatch .*\.(jpg|gif|png)$ http://www.google.com

    This will send any request for any file ending in those extensions to google. Very simplistic example but gives the idea.

  15. Few things to check:


    1) make absolutely certain your connection exists -I.e mysql_error()


    2) did u recreate the tables in the new database and r u sure the structure and naming is the same? Again running error reporting after your queries one by one will identify this.


    3) Are you aware that mysql is deprecated ?

  16. Can u post your code again? Based on the original I can't see why that error would be there.


    also your script currently won't actually write anything to the file as all it does now is open it for writing and then closes it again .


    Have you looked at php.net? U can pretty much copy their example herehttp://www.php.net/manual/en/function.fwrite.php


    Also take a look at the parameters for fopen because some of the modes will overwrite the file each time and some will append to it http://www.php.net/manual/en/function.fopen.php

  17. Handle the image operations external to PHP. For instance, exec() out to ImageMagick or similar. PHP's memory limits and other restrictions do not apply to external processes. Such programs may also have better optimizations and do the job quicker.



    I am interested in understanding this better so apologies if I'm being slow. When you say use exec do you mean to execute a program on an external server? How would using exec on the same server get around the issue of using up memory since the server resource will be used just the same?  Sorry i realise this is all a bit abstract but I can foresee a time in the future when I'll need to build something similar for a much higher volume website so I'd like to understand a  good approach.

  18. Hello


    I have recently been working with gd library as part of an image upload system. I noticed that one of my scripts was failing due to exceeding the available memory.


    Anyway researching this I discovered that gd library can be quite memory hungry and the pixel width height of even a small image can require a lot of memory - even when the file size is quite low.


    So my question is how do really big sites deal with this? If u have a high volume upload form for instance I could imagine the drain in memory being quite massive.


    So do they just throw hardware at it or are there more efficient image libraries than gd?


    Incidentally I corrected the memory issue by changing the ini setting for the script. Just in case anyone has that problem.

  • 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.