t0k4rt / phpqrcode

php QRcode generator library
GNU Lesser General Public License v3.0
875 stars 389 forks source link

Cannot set colour via $_GET param #16

Closed mylesagray closed 10 years ago

mylesagray commented 10 years ago

I have used the lib to create a parameterised PHP page that we can generate QR codes from the params in the url:

include( '/qrlib/qrlib.php' );

if (isset($_GET['fg'])&&!empty($_GET['fg'])) {
    $fore_color = $_GET['fg'];
} else {
    $fore_color = 0x000000;
}

if (isset($_GET['bg'])&&!empty($_GET['bg'])) {
    $back_color = $_GET['bg'];
} else {
    $back_color = 0xFFFFFF;
}

QRcode::png($_GET['url'], false, $_GET['err'], $_GET['size'], $_GET['pixel'], false, $back_color, $fore_color);

This works perfectly for url, err, size and pixel but as soon as I try and set the colours from the URL - the respective colour change (fg or bg) just defaults to black.

However, if the variables $fore_color or $back_color are set explicitly (not through the URL and use the else statement then they work. (I should note that if you look at the above they will default to black FG and white BG if the param isn't set).

I have echo'd out the $fore_color and $back_color to check the values are being passed correctly and they are showing up exactly as expected - this behaviour occurs when one or both of the color params are populated in the URL.

I set up a few examples here:

http://rd.exitex.com/qr.php?url=test&size=40&pixel=1&err=L&bg=0xFFFFFF&fg=0x000000

http://rd.exitex.com/qr.php?url=test&size=40&pixel=1&err=L&bg=0xFFFFFF

http://rd.exitex.com/qr.php?url=test&size=40&pixel=1&err=L&fg=0x000000

http://rd.exitex.com/qr.php?url=test&size=40&pixel=1&err=L

Any advice as to this strange behaviour please advise.

wingyiu commented 10 years ago

use 000000

mylesagray commented 10 years ago

It works now as I added a hex to decimal converter as advised on StackOverflow: http://stackoverflow.com/questions/20241735/cannot-set-specific-param-from-get/

elalemanyo commented 10 years ago

Hi, I was having the same Problem and at the end I get the parameter like this:

$backColor = (isset($_GET['backColor']))? hexdec($_GET['backColor']) : 0xFFFFFF;