Posts Mentioning RSS Toggle Comment Threads | Keyboard Shortcuts

  • admin 5:21 pm on May 13, 2010 Permalink
    Tags: php, shopping cart   

    Shopping Cart in PHP 

    Here is part of my shopping cart project which I created during my PHP / MySQL studies. Needless to say it is good only for studying purposes because it is insecure and quite immature:

    The funniest thing is that one of the requirements for this cart was to be in just 2 files. So because I couldn’t imagine to fit it in two files I just fitted it in 2 :) Let the fun begin:

    go back to the store and begin shopping :).';
     
    // If post input with 'do' values is coming from the admin area forms we will process it here. This is because we have to use get otherwise the URL will become too long especially when we specify long description for products.
     
    switch ($_POST['do']) { 
     
    	case 'insert':
    		$command = "insert into shop_products (prouct_name, price, product_image, description) values('".addslashes($_POST['product_name'])."','".addslashes($_POST['price'])."','".addslashes($_POST['product_image'])."','".addslashes($_POST['description'])."');";
    		$result = mysql_query($command);
    		print "Data was successfully entered.
    ";
    		mysql_close($db);
    		exit();
    		break;
     
    	case 'update':
    		$command = "update shop_products set prouct_name='".addslashes($_POST['product_name'])."', price='".addslashes($_POST['price'])."', product_image='".addslashes($_POST['product_image'])."', description='".addslashes($_POST['description'])."' where product_id='".$_POST['product']."';";
    		$result = mysql_query($command);
    		print "Data was successfully updated.
    ";
    		mysql_close($db);
    		exit();
    		break;
    }
     
    //Since we are limited to the number of pages we will use switch to simulate all the pages we want :)
     <a href="http://linux.bgsnow.com/shopping-cart-in-php.php#more-223" class="more-link">(More ...)</a>
     
  • admin 9:11 pm on November 14, 2009 Permalink
    Tags: /var/lib/mysql, , pid-file   

    Starting MySQL. ERROR! Manager of pid-file quit without updating file. 

    I got that nasty error after moving around different directories in /var/lib/mysql:

    root@server:/var/lib/mysql# /etc/init.d/mysql start

    Starting MySQL. ERROR! Manager of pid-file quit without updating file.

    There were all kind of suggestions about it on the net, most of which had something to do with incorrect shutdown or incorrect permissions for the pid file.

    One of the suggestions reminded me to read the mysql error log :) Here is what the error log said:

    root@server:/var/lib/mysql# /etc/init.d/mysql start
    Starting MySQL. ERROR! Manager of pid-file quit without updating file.
    root@server:/var/lib/mysql# mysql
    mysql                       mysql_config                mysqldumpslow               mysql_idle_processes.pm     mysqlshow                   mysql_tzinfo_to_sql
    mysqlaccess                 mysql_convert_table_format  mysql_explain_log           mysqlimport                 mysql_sock.pm               mysql_upgrade
    mysqladmin                  mysqld                      mysql_find_rows             mysql_install_db            mysql_tableinfo             mysql_upgrade_shell
    mysqlbinlog                 mysqld-debug                mysql_fix_extensions        mysql_logs.sh               mysqltest                   mysql_waitpid
    mysqlbug                    mysqld_multi                mysql_fix_privilege_tables  mysqlmanager                mysqltestmanager            mysql_zap
    mysqlcheck                  mysqld_safe                 mysqlhotcopy                mysql_secure_installation   mysqltestmanagerc
    mysql_client_test           mysqldump                   mysqlhotcopy.orig           mysql_setpermission         mysqltestmanager-pwgen
    root@server:/var/lib/mysql# mysqld
    mysqld         mysqld-debug   mysqld_multi   mysqld_safe    mysqldump      mysqldumpslow
    root@server:/var/lib/mysql# mysqld
    mysqld         mysqld-debug   mysqld_multi   mysqld_safe    mysqldump      mysqldumpslow
    root@server:/var/lib/mysql# mysqld_safe start
    Starting mysqld daemon with databases from /var/lib/mysql
    STOPPING server from pid file /var/lib/mysql/host.server.bgsnow.com.pid
    091114 13:14:56  mysqld ended
    root@server:/var/lib/mysql# ll /var/lib/mysql/host.server.bgsnow.com.p
    root@server:/var/lib/mysql# touch /var/lib/mysql/host.server.bgsnow.com.pid
    root@server:/var/lib/mysql# chown mysql: /var/lib/mysql/host.server.bgsnow.com.pid
    root@server:/var/lib/mysql# /etc/init.d/mysql start
    Starting MySQL. ERROR! Manager of pid-file quit without updating file.
    root@server:/var/lib/mysql# tail -f /var/lib/mysql
    mysql/    mysqlA/   mysqlOLD/
    root@server:/var/lib/mysql# tail -f /var/lib/mysql/mysql-slow.log
    host.server.bgsnow.com.err  ib_logfile0                mysql-slow.log             optistr2_optistreams/
    ibdata1                    ib_logfile1                optistr2_opti/             optistr2_perldesk/
    root@server:/var/lib/mysql# tail -f /var/lib/mysql/host.server.bgsnow.com.err
    InnoDB: Restoring possible half-written data pages from the doublewrite
    InnoDB: buffer…
    InnoDB: Doing recovery: scanned up to log sequence number 0 43655
    091114 13:16:20  InnoDB: Starting an apply batch of log records to the database…
    InnoDB: Progress in percents: 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    InnoDB: Apply batch completed
    091114 13:16:21  InnoDB: Started; log sequence number 0 43655
    091114 13:16:21 [ERROR] Fatal error: Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist
    091114 13:16:21  mysqld ended
    091114 13:16:52  mysqld started
    InnoDB: Log scan progressed past the checkpoint lsn 0 36808
    091114 13:16:52  InnoDB: Database was not shut down normally!
    InnoDB: Starting crash recovery.
    InnoDB: Reading tablespace information from the .ibd files…
    InnoDB: Restoring possible half-written data pages from the doublewrite
    InnoDB: buffer…
    InnoDB: Doing recovery: scanned up to log sequence number 0 43655
    091114 13:16:52  InnoDB: Starting an apply batch of log records to the database…
    InnoDB: Progress in percents: 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    InnoDB: Apply batch completed
    091114 13:16:53  InnoDB: Started; log sequence number 0 43655
    091114 13:16:53 [ERROR] Fatal error: Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist
    091114 13:16:53  mysqld ended
    root@server:/var/lib/mysql# ls
    ./  ../  host.server.bgsnow.com.err  ibdata1  ib_logfile0  ib_logfile1  mysql-slow.log  optistr2_opti/  optistr2_optistreams/  optistr2_perldesk/
    root@server:/var/lib/mysql# ll ../
    alternatives/     dhclient/         logrotate.status  mlocate/          mysqlA/           pgsql/            rkhunter/         sepolgen/         stateless/        yum/
    dbus/             games/            misc/             mysql/            mysqlOLD/         random-seed       rpm/              spamassassin/     texmf/
    root@server:/var/lib/mysql# ll ../
    alternatives/     dhclient/         logrotate.status  mlocate/          mysqlA/           pgsql/            rkhunter/         sepolgen/         stateless/        yum/
    dbus/             games/            misc/             mysql/            mysqlOLD/         random-seed       rpm/              spamassassin/     texmf/
    root@server:/var/lib/mysql# ll ../mysqlOLD/
    cphulkd/                   host.server.bgsnow.com.err  ib_logfile0                mysql/                     roundcube/                 sentry_stat/
    eximstats/                 host.server.bgsnow.com.pid  ib_logfile1                mysql-slow.log             sentry/                    sentry_traf/
    horde/                     ibdata1                    leechprotect/              mysql.sock                 sentry_mambo/              test/
    root@server:/var/lib/mysql# ll ../mysqlOLD/*
    root@server:/var/lib/mysql# ls
    ./  ../  host.server.bgsnow.com.err  ibdata1  ib_logfile0  ib_logfile1  mysql-slow.log  optistr2_opti/  optistr2_optistreams/  optistr2_perldesk/
    root@server:/var/lib/mysql# mv ../mysqlOLD/
    cphulkd/                   host.server.bgsnow.com.err  ib_logfile0                mysql/                     roundcube/                 sentry_stat/
    eximstats/                 host.server.bgsnow.com.pid  ib_logfile1                mysql-slow.log             sentry/                    sentry_traf/
    horde/                     ibdata1                    leechprotect/              mysql.sock                 sentry_mambo/              test/
    root@server:/var/lib/mysql# mv ../mysqlOLD/* ./
    mv: overwrite `./host.server.bgsnow.com.err’? y
    mv: overwrite `./ibdata1′? n
    mv: overwrite `./ib_logfile0′? n
    mv: overwrite `./ib_logfile1′? n
    mv: overwrite `./mysql-slow.log’? y
    root@server:/var/lib/mysql# /etc/init.d/mysql restart
    Shutting down MySQL. SUCCESS!
    Starting MySQL. SUCCESS!

    root@server:/var/lib/mysql# tail -f /var/lib/mysql/host.server.bgsnow.com.err

    InnoDB: Restoring possible half-written data pages from the doublewrite

    InnoDB: buffer…

    InnoDB: Doing recovery: scanned up to log sequence number 0 43655

    091114 13:16:20  InnoDB: Starting an apply batch of log records to the database…

    InnoDB: Progress in percents: 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

    InnoDB: Apply batch completed

    091114 13:16:21  InnoDB: Started; log sequence number 0 43655

    091114 13:16:21 [ERROR] Fatal error: Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist

    091114 13:16:21  mysqld ended

    Obviously I have forgotten to move back the mysql directory which is responsible for the database for all privileges, databases and so on :)  So moving it back along with the rest of the core files solved the problem:

    root@server:/var/lib/mysql# mv ../mysqlOLD/* ./

    mv: overwrite `./host.server.bgsnow.com.err’? y

    mv: overwrite `./ibdata1′? n

    mv: overwrite `./ib_logfile0′? n

    mv: overwrite `./ib_logfile1′? n

    mv: overwrite `./mysql-slow.log’? y

    root@server:/var/lib/mysql# /etc/init.d/mysql restart

    Shutting down MySQL. SUCCESS!

    Starting MySQL. SUCCESS!

    Thus if you have similar problems, the first thing is to check the MySQL error log and don’t believe the misleading error about the PID :)

     
  • admin 9:35 am on October 17, 2009 Permalink
    Tags: Joomla SEO component, sh404SEF free   

    Best Joomla Modules 

    Joomla is my favorite Content Management System even though it is years behind WordPress functionality. Of course, WordPress is not a CMS :)

    So when I decided to build a new site using Joomla 1.5 I have had to find solutions to the following problems:

    1. SEO component. Joomla SEO / SEF couldn’tt suck more… From the time of Joomla 1.0.* I know that one of the core Joomla developers had a commercial SEO component. I guess that’s why Joomla will never have elementary SEO functions like really friendly URLs. Yes, there are some in-built… but that’s just bullsh*t. Of course, there are 2-3 commercial (or let’s call them paid for political correctness) plugins which probably work fine.

    Anyway, I have made my choice to sh404SEF. Next I have tried a way to get it free of charge. Luckily, I stumbed upon this site offering it for free download :) As a whole, it works fine even though my Joomla is quite complex. It has Joomfish and many other plugins…

     
  • admin 8:11 am on October 11, 2009 Permalink
    Tags: akismet, antispam, project honeypot, spam, spam protection   

    The Toughest Spam Protection 

    A month ago I remembered about an old blog we have had and checked it out… After months of negligence it had 9999 spam comments :) It was outdated and had no spam protection at all… It was quite unpopular (no PR at all) but it has still been of interest to spammers…

    Still spam is more than most people think – it is not only about bots and there is much more than just posts about popular medical products. My experience with Spam fighting comes from a popular hosting forum with Google PR 8 and a few popular blogs (WordPress).

    So when I really want to protect a site from spammers I follow a scenario of 3 steps:

    1. Implement Project HoneyPot. This is the first trap for spammers – both bots and humans. Time has shown that there are many humans posting spam comments and posts. Project HoneyPot detects them all through a large distributed network of honeypots and adds them to a blocklist.

    The project offers integration about almost any application. It has even a beta version of an Apache module so its implementation should not be hard.

    2. The next thing to do is to enable reCaptcha. This way we address all threats from bots because most spam does come from bots. These bots often reside on zombie computers and might not have been spotted by Project Honeypot yet.

    Of course reCaptcha is not perfect and some advanced bots can pass it. Its biggest drawback is that human spammers bypass it easily.

    3. The last step is to set Akismet. This is the final trap, the boss of the Spam defense. It filters posts by hundreds of tests about known spam patterns. It is much advanced than the previous methods and ensures very high level of defense.

    If you implement the above solution with all of its parts you can feel pretty safe about your site or blog. It’s biggest benefit is that it saves you a lot of work and does not require you to update manually anything.

    Still, it is a 99.99% protection. A popular site is targeted by more than 1000 spam attempts a day which means that more than 1 spam post / comment will go through.

    That’s why it is a good idea to monitor and even pre-approve each post / comment.

     
  • admin 8:22 pm on October 28, 2008 Permalink  

    Changing image preview size for attached images in PhpBB3 

    Imagine having a nice PhpBB3 forum where you’d love to attach inline photos in your posts. The problem is that max height for the image size is set to 350 by default for the prosilver theme. I managed to change it only in the following way:

    Open your forums mysql database and find the table phpbb_styles_theme. There go to row theme_name=prosilver, find theme_data field. There will be your whole css for the theme loaded. Find:

    .attach-image {
    margin: 3px 0;
    width: 100%;
    max-height: 350px;
    overflow: auto;
    }

    Change it to:

    .attach-image {
    margin: 3px 0;
    width: 100%;
    max-height: 1350px;
    overflow: auto;
    }

    There are two things to consider:

    1. The above is probably loaded at some time from the file styles/prosilver/theme/content.css. It is a good idea to make the same change there too.

    2. Make sure to clear your forum’s cache, i.e. delete everything inside the cache/ directory.

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel