Jump to content

Jenk

Members
  • Posts

    778
  • Joined

  • Last visited

    Never

Posts posted by Jenk

  1. [quote author=SemiApocalyptic link=topic=107879.msg433253#msg433253 date=1158131109]
    Yes, register_globals should be switched off, for security reasons over anything else - check the manual for more information on that. As far as I understand, what register_globals actually does, it registers global variables. So, once you create them they are available throughout your PHP pages. For example, on page one we define the variable '$name' and assign the value 'Kris', then on page two we can just echo $name and it will print 'Kris' to the screen, this is without passing it via get, post, cookie or session. Please, anyone, correct me if I have misunderstood register_globals.
    [/quote]Not quite correct, it doesn't register session variables for you (your example with $name will not work with register_globals alone.)

    All register globals does is define each index of $_REQUEST, $_SESSION and $_SERVER as a standalone variable in the global namespace.
  2. run the query manually in mysql command prompt/phpmyadmin/mysql administrator to see expected results.

    Ravi - no, that will not work. You have specified for mysql_fetch_array to return a numerically indexed array, but then go on to use associative index's..

    mysql_fetch_assoc() will do fine, changing to *_array was unecessary.
  3. Sending an SQL statement over POST... that's the security vulnerability.

    You are limiting the accessibility of such functionality to a select few, but for a start you might as well just write down your DB schema on a piece of paper, make a paper plane out of it and launch it out the window :)


    I am utterly surpised no one has pointed out mysql_connect() does not have to have the host specified as 127.0.0.1/localhost everytime.. you can use other hosts (machines) ..
  4. one of the biggest unofficial no-no's in OOP is the use of globals :)

    'good' OOP practice is pass values around as parameters when and where needed, not to blanket label something for all to see :)

    [code]<?php

    $config = new XMLConfig('config.xml');

    $db = new DataBaseClass;

    $db->connect($config->db_host, $config->db_user, $config->db_pass);

    //etc.
    ?>[/code]

    For what you have posted above re: loading, I suggest your read up on the Service Locator pattern, Dependancy Injection and also the use of a Registry.
  5. I did explain, in plain English too. You did not - You asked for advice on your logic, I gave advice on your logic.

    Also note, this is a public discussion forum. Hence it being open to discussion.

    So next time I explain the use of || or && I have to post an example?

    Ok.

    [code]<?php

    $a = 1 || 2;

    $b = 1 && 2;

    ?>[/code]

    done.
  6. PHP_SELF can be tainted with user input, so don't use it. Use SCRIPT_NAME instead.

    and pagination in it's most simplest form:
    [code]<?php

    $link = mysql_connect(/* db details */) or die('Connection error');
    mysql_select_db(/* db */, $link) or die('Db error');

    if (!empty(trim((int)$_GET['page'])))
    {
        $page = (int) $_GET['page'];
    }
    else
    {
        $page = 1;
    }

    $max = 10;
    $start = $max * ($page -1);

    if (!$result = mysql_query("SELECT * FROM `table` LIMIT $start, $max", $link))
    {
        die ('Query error');
    }

    while ($row = mysql_fetch_assoc($result))
    {
        foreach ($row as $cell => $val)
        {
            echo '<p>' . htmlentities($cell) . ' => ' . htmlentities($val) . '</p>' . chr(10);
        }
    }


    $result = mysql_query('SELECT COUNT(*) AS A FROM `table`');
    $numpages = ceil(mysql_result($result, 0) / $max);

    for ($i = 1; $i < $numpages; $i += $max)
    {
        $j = $i / $max;
        echo '<a href="' . htmlentities($_SERVER['SCRIPT_NAME']) . '?page=' . $j . '">' . $i . '</a>&nbsp;';
    }



    ?>[/code]
×
×
  • 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.