Jump to content

Hailwood

Members
  • Posts

    51
  • Joined

  • Last visited

    Never

Posts posted by Hailwood

  1. hi there

     

    im am making a php validation class with sub classes that extend it, eg, mobile, suburb, credit_card, ect

     

    so, the idea is you can call

     

    $validation = new Validation('mobile');
    $valid = $validation->validate($number);
    
    $validation->type('suburb');
    $valid2 = $validation->validate($suburb);

    now my idea for doing this is having

     

    class Validation {
        private $v_type = null;
    
        function __construct($type) {
            $this->type($type);
        }
    
        public function type($type) {
            $this->v_type = new $type();
        }
    
        public function validate($info) {
            return $this->v_type->validate($info);
        }
    }

    as a very basic example

     

    but is there a better way of doing this?

  2. hi there,

     

     

    well here is what i am doing:

     

     

     

    $flybuys: 6014359000000928

    $check: 8

    $total = (array_sum($odds))+$evens;
        $total = str_split($total);
        $check = 10 - $total[1];
        echo $flybuys.' % '.$check.': '.$flybuys % $check.'<br />';
        $res = $flybuys % $check;
        echo 'res: '.$res;

     

     

    and the output is:

    6014359000000928 % 8: 7

    res: 7

    yet if i do:

    echo 6014359000000928 % 8;

    i get: 0;, which is correct

    so where is the 7 coming from?

  3. so basically here is a set of if statements that i am trying to optimize, can you please tell me if there are any differences in processing between them

     

     

    if($id!="0"    && $status!=""           && $msg_body=="")
    if($id != 0    && !empty($status)    && empty($msg_body))
    

     

     

    AND

     

     

     

    if($message_type == 0    && $msg_link_id != "0"   && $status==""         && $msg_body!="")
    if($message_type == 0    && $msg_link_id != 0     && empty($status)    && !empty($msg_body))
    

     

     

    AND

     

     

    if($message_type == 0    && $msg_link_id=="0"    && $status==""         && $msg_body!="")
    if($message_type == 0    && $msg_link_id == 0    && empty($status)    && !empty($msg_body))
    

  4. thorpe do you ever sleep?

     

    haha but yeah, i thought about doing that,

     

    except this table has over 300 columns (not designed nor can be changed by me) and so the query is is select * ...

     

     

    while($row = mysql_fetch-assoc...)

    {

    foreach($row as $k => $v )

      $$k = $v;

     

     

    so i cant really do it in the query

     

     

    cheers.

     

     

    came across using strtotime on it before using date

  5. hi guys

     

    so, can anyone tell me why i end up with different results with each of these

    <product_display_price> </product_display_price> = 
    [product_display_price] => SimpleXMLElement Object
                   (
                       [0] =>
                   )
    

     

     

    <product_display_price>Ham $5.00</product_display_price> = 
    [product_display_price] => Ham $5.00
    

     

     

    <product_display_price/> = 
    [product_display_price] => SimpleXMLElement Object
                   (
                   )
    

     

    all i did was

     

    $xml = simplexml_load_string($this->xml_data);

     

            echo '<pre>';

            print_r($xml->xpath('/menu/products_list/product'));

            die('</pre>');

     

    so, why does an empty element give me an empty object

    ^ expected

     

    a element with a string in it give me a string

    ^expected

     

    yet a element with a " " string gives me an object with a " " string in it

    ^not expected

     

    i would have expected it to act as either a string or an empty element

  6. see one way i could do it is to call

     

    $content = ob_get_contents();

    ob_end_clean();

    //replace stuff here

    echo $content;

     

    which would work fine, as i could just put ob_start before the echo $content;

     

    but is there a tidier way to do this?

     

     

     

    so the entire thing to replace would actually be

     

     

    $content = ob_get_contents();
    $headers = array();
        if ( !headers_sent() ) 
          $headers = apache_response_headers();
    ob_end_clean();
    //replace stuff here
    ob_start();
    if ( !empty( $headers ) )
        foreach ( $headers as $name => $value )
            header( "$name: $value" );
    echo $content;
    

       

     

     

  7. then what would you suggest for when you have a default page layout

     

     

    i.e

     

     

    <html>
    <head>
    <!--stylsheets here -->
    <!--javascript here -->
    </head>
    <body>
    <!--header div -->
    <!-- menu div -->
    <?php include($_GET['page.php']; ?>
    <!-- footer div -->
    </body>
    

     

     

    and its not pratical for your site to include the header, footer, and menu divs from anther file

     

     

    now in the the include file you want to change the site title,

    and include another style sheet,

     

     

    so my idea was to have a placeholder variable in the head which i could edit.

     

     

    i am already calling ob_start() at the beginning of every every page so could i use that to edit it?

  8. That is the code there

    <a href="<?php $config->base['url_path']; ?>messaging">Messaging</a>
    

     

    the config class is just an empty class with magic methods for get and set

     

    so i define config things like so

     

     

    $config = new Config();

     

     

    //BASE SETTINGS

    //------------------

    $config->base = array();

    $config->base['abs_path'] = $abs_path;

    $config->base['url_path'] = 'http://localhost/buzzil/';

    $config->base['temp_dir'] = 'tmp/';

    $config->base['env']      = 'dev';

     

     

     

    so the expected output from accessing any url with this code in the file

    <a href="<?php $config->base['url_path']; ?>messaging">Messaging</a>
    

    is

    <a href="http://localhost/buzzil/messaging">Messaging</a>
    

     

     

    but instead from a url such as

    http://localhost/buzzil/templates/list/email

     

     

    i get

    <a href="http://localhost/buzzil/templates/list/messaging">Messaging</a>
    

     

    and yes thorpe,

    at midnight when i have had less than 3 hours sleep in the past 48 hours i do fail at spelling ;)

  9.  

    if i have this in a config file

    $config->base['url_path'] = 'http://localhost/buzzil/';

     

     

    and i have this

    <a href="<?php $config->base['url_path']; ?>messaging">Messaging</a>

     

     

    any idea when i am on a page iwth a url like

    http://localhost/buzzil/templates/list/email

     

     

    why instead of the expected output of

    <a href="http://localhost/buzzil/messaging">Messaging</a>

    am i getting

    <a href="http://localhost/buzzil/templates/list/messaging">Messaging</a>

     

     

    dont know if it will help but here is my htaccess file

     

     

    Options +FollowSymlinks

     

     

    RewriteEngine on

     

     

    RewriteCond %{REQUEST_FILENAME} !-f

     

     

    RewriteRule ^(.*)$ index.php?page=$1

  10. Hi guys,

     

     

    I have a page which submits a form via ajax

    the form submits to add a new user

    users can only access this page if they are logged in,

     

     

    so my question is how do we validate to make sure that the requests are coming only from that page?

     

     

    we thought about validating via the request ip but if the form is submitted via ajax would that not just be the clients ip?

     

     

    Regards,

    Hailwood

  11. ok, so you know the times when you feel really stupid?

     

    yeah this is one of them,

     

    i can get to them doing $this->config->database['name'];

     

    the error had nothing to do with me trying to access them,

     

    the error was because i was doing

    $this->$link

    by accident instead of

    $this->link

  12.  

    Current Status

    Attempt: $this->config->database['name'];

    Error: cannot access empty property

     

     

    Attempt: $this->config->database->name;

    Error: cannot access empty property

     

     

    Attempt: $this->config[database][name];

    Error: Cannot use object of type Config as array

     

     

    Attempt: $this->config->[database][name];

    Error: Incorrect Syntax

  13. strange this is if i do this:

    
    $this->link = $this->config->database['pass'];                             //line 45
            $this->$link = mysql_connect(                                          //line 46
                    $this->config->database['host'],  //Database Host
                    $this->config->database['user'],  //Database User
                    $this->config->database['pass']); //Database Pass
    

     

     

    i get

    Fatal error: Cannot access empty property inC:\server\xampp\htdocs\buzzil2\classes\database.class.php on line 46so why dont i get this error on 45?

    wondering if one of the values was not set properly i went through and changed 45 to user/host/pass/ in turn, but still no error

  14. dunno if it will help but this is how i store the info

    
    //GET AN INSTANCE OF THE CONFIG CLASS
    $config = Config::getInstance();
    
    //DATABASE SETTINGS
    //------------------
    $config->database = array();
    $config->database['host'] = 'localhost';
    $config->database['user'] = 'root';
    $config->database['pass'] = '';
    $config->database['name'] = 'buzzil';
    

    the config class has

    
        public static function getInstance() {
            if (self::$instance== null)
                self::$instance= new config();
            return self::$instance;
        }
    
        public function __set($k, $v) {$this->$k = $v;}
        public function __get($k) {return $this->$k;}
    

     

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