2:34 PM

Adware-alexa? There is Adware in the Alexa toolbar

posted under by FR3@K | Edit This
At least, that is what my virus scanner told me.

Today I was wanting to be a “regular reader” to some of my sites, so I switched back to Internet Explorer, and I got myself equipped with the Google Toolbar and Alexa Toolbar.

I didn’t have these installed on Firefox, because the SearchStatus add-on could help me tell the Google PageRank and Alexa Traffic Rankings of the sites (which is essentially what I need for each of the toolbars).

To my horror, when I tried to install the Alexa Toolbar, my virus scanner told me that the toolbar comes with Adware!

Now, tell me. Which should I believe - the virus scanner, or Alexa?

I guess I won’t take chances. Out you go, Alexa. I’ll stick to Firefox and SearchStatus. I’d browse happy.

Interestingly Alexa has a nice little box on the toolbar download page that goes like this:

My oh my… looks like something went wrong somewhere huh.

3:24 AM

PHP : Simple Login/Logout System with Sessions

posted under by FR3@K | Edit This
This tutorial will help you create a really basic user login system.

Here is what we are going to do in English: The user can login with an email & password. If the email and password match then create a session and allow the user to access the private members page. If an unauthorized user tries to access the members page without logging in, they will be forced to return to the login page.

So lets start off by creating a new database to store emails and password.

CREATE DATABASE test;

Next we can create a table in the database to store the users email and password. If you can’t figure out how to create the database and table, I recommend Googling for some general MySQL & PHPMyAdmin tutorials. They will help you a lot.

CREATE TABLE usersystem
(
id int AUTO_INCREMENT NOT NULL,
email varchar(120) NOT NULL,
password varchar(30) NOT NULL,
PRIMARY KEY (id)

);


INSERT INTO usersystem(email,password)
VALUES ('test@brendewilson.com','123');


INSERT INTO `usersystem` (email,password)
VALUES ('anothertest@brendenwilson.com','1234');

If the SQL code above was correctly entered into the ‘test’ database then you will have three columns in the database, ID, Email and password. The ID field is there to identify each entry as unique. Some people might have two accounts with the same email and if that happens, the ID field will allow us to differentiate between the two. The primary key part says that the ‘ID’ field will be unique for every row. The last two rows insert test data into the database so we can test the login system when it is finished.

Now create a file called include.php. This file will store all the code we want place at the top of every page.

<?php

session_start();



$host = "localhost";

$username = "USERNAME";

$password = "PASSWORD";

$db = "test";

@mysql_connect($host,$username,$password) or die ("error");

@mysql_select_db($db) or die("error");

?>



We are going to include this file at the very beginning of every page we setup. It will start the session and then connect your page with the MySQL database.

One thing to note: If you get an error saying that the headers were already sent, your start_session() probably wasn’t at the very top of the page. The start_session() has to be at the very top of the page.

Now create a login.php with this code.

<?php

require_once('include.php');

$error = '';

$form = $_POST['submit'];

$email = $_POST['email'];

$password = $_POST['password'];



if( isset($form) ) {



if( isset($email) && isset($password) && $email !== '' && $password !== '' ) {



$sql = mysql_query("SELECT * FROM `usersystem` WHERE email='$email' and
password='$password';");



if( mysql_num_rows($sql) != 0 ) { //success

$_SESSION['logged-in'] = true;

header('Location: members.php');

exit;

} else { $error = "Incorrect login info"; }

} else { $error = 'All information is not filled out correctly';}

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Login</title>

</head>

<body>

<form action="<?php $PHP_SELF; ?>" method="post" >

Email<br />

<input name="email" type="text" value="<?php echo "$email";?>" /><br /><br />

Password<br />

<input name="password" type="password" /><br />

<input name="submit" type="submit" value="Log In" />

</form>

<?php

echo "<br /><span style=\"color:red\">$error</span>";

?>

</body>

</html>




Lets break this code down so it a little easier to understand.

In English, here is what the code means:
Include the include.php file.
Set the $error variable to a blank value.
If the form was submitted, put the values into the variables, $form, $email, $password so we can use them later.
If the form is submitted....
And the email and password fields are filled out and they aren't blank...
Check to see if there are any rows in the database that have a matching email and password.
If there are, that means the user entered a matching email and password.
Set the session.
Change the page to members.php.
And stop running the php code.
If the user didn't enter a matching email and password, throw an error.

Now create the members.php. This page will only be available to people who have signed in on the prior page. Here is the code that goes in that page.

<?php

require_once('include.php');

// is the one accessing this page logged in or not?

if ( !isset($_SESSION['logged-in']) || $_SESSION['logged-in'] !== true) {



// not logged in, move to login page

header('Location: login.php');

exit;

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Freak's Blog</title>

</head>

<body>

Sweet you lgged in.

<a href="logout.php">logout</a>

</body>

</html>




This block of code is actually pretty simple. Just like on all the other pages, we include the include.php file at the top. The include.php file sets the session up and connects to the MySQL database. Then, if the appropriate session is not set (the user didn’t login), we move the user to the login page and exit the code. If the users has logged in, and their session is appropriately set, they will see the rest of the page. This pages format can be copied to create additional hidden pages.

Now to the final step. Create logout.php and enter this code:

<?php

session_start();

// if the user is logged in, unset the session

if (isset($_SESSION['logged-in'])) {

unset($_SESSION['logged-in']);

}

// now that the user is logged out,

// go to login page

header('Location: login.php');

?>




This page doesn’t have any HTML in it. The first line starts the session, and then if the user is logged in, the session will be destroyed and the user will be redirected to the login page.

I hope you enjoyed the tutorial. Please leave me feedback through the comment system below so I can improve my tutorials in the future.

3:22 AM

PHP : Set Cookie Function

posted under by FR3@K | Edit This
It's perhaps common knowledge these days as to what a cookie is. A cookie sits client-side in a user's browser and is sent to the server when the page is loaded. Cookies, however, can go a little deeper than just setting and receiving.

PHP Code:
setcookie('myCookie', 'TalkPHP.com', time() + 2592000);
The setcookie() function accepts a total of 7 arguments. The first 2 are the only mandatory arguments. The above code probably looks familiar - we give the cookie a name, give it a value and set its duration to 30 days. The 3rd argument, the time argument, will default to 0 if you leave it empty and thus the cookie will expire at the end of the session - typically when the user closes their browser.

The 4th argument in setcookie() is the cookie path. By default, if you leave this argument empty, it will set itself as the directory you are currently in. For instance, if I'm in the directory TalkPHP.com/members/ (this could be a mod-rewrite URL) then the cookie path will be /members/. What this means is that if I were to then navigate back to the index, that cookie I set would not be valid for the index and thus not be transferred to the server. In order to make the cookie available to the entire site, no matter which directory you happen to be in, you must specify the 4th argument like so:

PHP Code:
setcookie('myCookie', 'TalkPHP.com', time() + 2592000, '/');
The next argument along, number 5), is the domain argument. Again, this will default to the domain you are on. Many problems can arise with this argument, especially with www. and non-www. You see, setting the path to www.talkphp.com would make the cookie only available to the www sub-domain. Therefore if I omitted the www the cookie would not register. To get around this you can specify the 5th argument:

PHP Code:
setcookie('myCookie', 'TalkPHP.com', time() + 2592000, '/', '.talkphp.com');
Moving swiftly along to the next argument, the secure argument. This simply tells the browser whether or not to transfer the cookie only over a secure connection - HTTPS. If it is set to true then the cookie will only be transferred when the protocol being used is HTTPS and not the plain old HTTP. The default, however, is false which means that the cookie will be sent regardless of the protocol being used at the time. Now we have:

PHP Code:
setcookie('myCookie', 'TalkPHP.com', time() + 2592000, '/', '.talkphp.com', false);
Looking swish, eh? There is 1 last argument to mention and that is the 'HTTP only' argument. In a nutshell this means that the cookie will not be available by such scripting languages as Javascript. Therefore if we were to set it:

PHP Code:
setcookie('myCookie', 'TalkPHP.com', time() + 2592000, '/', '.talkphp.com', false, true);
Then using the following code would give us a blank alert box, since JavaScript will not be able to access the cookie information:

Code:

<script type="text/javascript">

alert(document.cookie);

</script>



This is truly awesome because it prevents a lot of XSS attacks! All modern day browsers will obey this rule - users still using ancient browsers may still be vulnerable but really that's their own fault for not hitting the oh so prominent update button.


That's all there is to the setcookie() function. Once we have set our cookie, PHP will automatically retrieve it and place it into the $_COOKIE superglobal variable, as well as the $_REQUEST superglobal variable.

3:14 AM

PHP Sessions and Cookies

posted under by FR3@K | Edit This
I'm going to teach you the basics of MySQL and showing the contents of a database table.

Read from here if you haven't got phpMyAdmin

first of all you'll have to create a database and a table of course
sorry for the ones who haven't got PHP MyAdmin, but hey don't be afraid register @ FreeSQL.org and you have it for free!

first for the ppl who haven't got PHP MyAdmin open the link and scroll down you'll see a form
enter the username, password, database name, and just a few numbers in the creation code. Below email adress should be MySQL selected, if not select it
then just submit. I don't know if you get an e-mail I think so.
okay after registration scroll up, and on the right you see Database Administration then just click phpMyAdmin enter your username and password and phpMyAdmin opens!

Let's get started

phpMyAdmin is open now
normally u see this now:

MySQL
Create a new database [Documentation]
and an input box

okay just enter the name you want and submit after you clicked the submit button u should see a text area that's where u have to enter the sql code:

Code:
CREATE TABLE `products` (
`id` INT( 8 ) NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 255 ) NOT NULL ,
`price` INT( 8 ) NOT NULL ,
PRIMARY KEY ( `id` )
);


okay let's explain
CREATE TABLE is obvious I think
`products` is the name of the table
`id` this is the number that belongs to the product
NOT NULL means this value must be filled in
AUTO_INCREMENT means that if you add a product with a form, the id number will increase automaticly with 1
`name` is just the name of the product
VARCHAR means 1 or more characters ( 225 ) is the maximum characters
NOT NULL is obvious I will not mention this anymore
`price` the price of the product
INT means only numbers no numbers with a , in it
so not �1,5 or $50,99
PRIMARY KEY ( `id` ) is the key to your table, so you only need the id then you automaticly have the entire information of the product that belongs to that id it was of course also possible that `name` was the primary key but id is better

okay just click the first Start button
good the table is ready!

Adding records to the db table

Here you will learn to add products to your database later in the tut this will happen with a form

to add a record, we use the INSERT commando

Code:
INSERT INTO `products` (`name` , `price` )
VALUES ('Mousepad', '10');


let's explain
INSERT INTO is obvious
`products` is the name of the table
(`name` , `price` ) are the rows of the tables
VALUES ('Mousepad', '10'); these are the values of course

don't do this:

Code:
INSERT INTO `products` (`name` , `price` )
VALUES ('10', 'Mousepad');


I hope you see why
the values are not in the correct order!!! the price is Mousepad

okay you've added your first record!

Select records from your table

now I'm going to teach you how you can select your records
to do that, we use the SELECT commando. To select all the records (I know it's only 1) there is just 1 commando

Code:
SELECT * FROM `products`


* doesn't mean all records, but all table rows so id, name and price
if you do this

SELECT name FROM `products` only the name will appear

let's add some more records

Code:
INSERT INTO `products` (`name` , `price` )
VALUES ('Graphix card', '150');
INSERT INTO `products` (`name` , `price` )
VALUES ('Keyboard', '50');
INSERT INTO `products` (`name` , `price` )
VALUES ('Windows XP', '200');
INSERT INTO `products` (`name` , `price` )
VALUES ('PHP Designer 2005', '110');
INSERT INTO `products` (`name` , `price` )
VALUES ('Adobe Photoshop CS 2', '150');


okay this is our shop =)
if u do this now again
SELECT * FROM `products`
you will see the entire table, but most of the times you only want to see just 1 product. well thank you php because that's why we use the WHERE clausule
oh.. PHP

Code:

SELECT * FROM `products` WHERE `name` = 'PHP Designer 2005';

I think it's obvious let's explain it anyway it simply just selects all information where the name of the products = PHP Designer 2005 from the table products

it's just that simple!

Code:
SELECT price FROM `products` WHERE `name` = 'PHP Designer 2005';

this only selects the price of the product where name = PHP Designer 2005 from
the table products

the same for price and id
Code:
SELECT * FROM `products` WHERE `id` = '1';

this selects all records with the id 1 (it's only 1 record of course)

Code:
SELECT * FROM `products` WHERE `price` = '150';

this selects all records where the price = 150
so I think it was photoshop and a new graphix card

So far the select commando and where clausule

Operators

we can use the = sign but we can also use operators for example: we only want to show the products that are more expensive than 100

Code:
SELECT * FROM `products` WHERE `price` > '100';

simple, isn't it?

or you want to select all the records that are cheaper than 50?
Code:
SELECT * FROM `products` WHERE `price` < '50'; u can also use the >= or <= signs Code: SELECT * FROM `products` WHERE `price` <= '50'; this selects the records where the price is = or cheaper than 50 I don't think you ever thought it was that simple ?! More functions with WHERE there's more, you want to select the IDs of the products that are smaller than 3 and you want to select the products that are cheaper than 100? no problem! PHP will take care of it here we will use the AND command Code: SELECT * FROM `products` WHERE `price` < '100' AND `id` < '3'; and there's more... you want to select the products that are cheaper and 50 but also that are more expensive than 200 (I don't know why somebody would do that but it's just an example) here we use the OR command Code: SELECT * FROM `products` WHERE `price` < '50' OR `price` > '200';


Simple eh

Order your records

You want to order your records from cheap to expensive? No problem PHP will take care of it

Code:
SELECT * FROM `products` ORDER BY `price`


you'll get your entire list of products ordered from cheap to expensive but you don't want it this way, but from expensive to cheap? No problem! Just add DESC after price

Code:
SELECT * FROM `products` ORDER BY `price` DESC

DESC means descending

you only want to see a specified ammount of products then you just do this:
SELECT * FROM `products` ORDER BY `price` LIMIT 0,3
0 indicates that he will start counting from 0 and he will take the 3 numbers after 0
so, 1,2,3

SELECT * FROM `products` ORDER BY `price` LIMIT 2,3
he will start counting from 2 and takes the 3 numbers after it
3,4 and 5

UPDATE your records
OMG!!? I've entered the wrong price, I will lose customers!
no problem, that's why we have PHP if you want to update your records, u use the UPDATE command

Code:
UPDATE `products` SET `price` = '250' WHERE `name` = 'Graphix Card';


This will update the price of the graphix card from 150 to 250
(geh thanx, I will lose customers anyway )

if you do this:
Code:
UPDATE `products` SET `price` = '250';

all prices of all your products will change to 250 so beware!

Also here you can use the AND or OR commands in the WHERE clausule!

Combine MySQL and PHP

first of all you'll have to connect to the database open up a new php doc and paste this:

PHP Code:
$server = "localhost";
$user = "username;
$password = "password";
$db = "db";

$connection = mysql_connect($server,$user,$password)
or die ("Could not connect to the database");
mysql_select_db($db,$connection)
or die ("Could not select the db");


server is most of the times localhost, but for freesql.org users it's freesql.org I thought. user is the username u used to register and password as well db is the name of the database u gave while registering ok save this file as connect.php we'll include this file in our other files

open up a new doc
and paste this:

PHP Code:

<?php

include "connect.php";

$query = "SELECT * FROM `products` WHERE `prijs` > '50' ";

$sql = mysql_query($query);

?>




include "connect.php"; just means that all content of that file also are in force in this file.
$query = "SELECT * FROM `products` WHERE `prijs` > '50' ";
this makes the query
$sql = mysql_query($query); this executes the query

now we only have to show all products more expensive than 50

PHP Code:

<?php

include "connect.php"; //make connection

$query = "SELECT * FROM `products` WHERE `prijs` > '50' ";

$sql = mysql_query($query) or die ( mysql_error( ) );



while($record = mysql_fetch_object($sql)){

echo"".$record->name."

";

}

?>



This shows all the products more expensive than 50 or you can do this

PHP Code:

<?php

include "connect.php"; //make connection

$query = "SELECT * FROM `products` WHERE `prijs` > '50' ";

$sql = mysql_query($query) or die ( mysql_error( ) );



while($record = mysql_fetch_object($sql)){

echo"You can buy ". $record->name ." for ". $record->price ." each."

";

}

?>



it always makes a new table
so u better do this:

PHP Code:

// here starts the php
?>?>?>?>?>?>?>?>?>?>?>?>?>?>?>?>?>?>?>?> '50' ";
$sql = mysql_query($query) or die ( mysql_error( ) );

while($record = mysql_fetch_object($sql)){
echo"
".$record->name."";
}
?>
// and close the table
ProductPrice
".$record->price."


well this is not pretty easy to explain but you'll understand after some tries or if u know the while structure

it's not that difficult eh?

More functions with PHP & MySQL
hey I forgot how many products I had no problem PHP takes care of it

PHP Code:

<?php

include "connect.php"; //make connection

$query = "SELECT * FROM `products` WHERE `prijs` > '50' ";

$sql = mysql_query($query) or die ( mysql_error( ) );

$records = mysql_num_rows($sql);

echo ('There are ".$records." in the database');

?>



mysql_num_rows($sql); counts how many records there are in the table

Like I said before, we're going to add records with a form that's exactly what we're going to do now
first we're going to check if the submit button has been clicked
if not: the form will show up
else: we will insert the input into the database

name this doc: insert.php :

PHP Code:

<?php

if ($_POST['submit']) { //if the submit button has been clicked

include"connection.php"; //includes connection.php



$query = "INSERT INTO `products` (`name` , `price` ) //makes the query

VALUES ('".$_POST['name']."', '".$_POST['price']."');"

$sql = mysql_query($query) or die(mysql_error()); //executes the query

echo"You have entered the new product";



}else{

?>

<form method="post" action="insert.php">

Product name: <input type="text" name="name"><br>

Product price: <input type="text name="price"><br><br>

<input type="submit" value="Submit!">

<?

}

?>



I hope this tut helped you out.

3:04 AM

PNG color mismatch on the web: an easy fix

posted under by FR3@K | Edit This
To clarify, this is an easy fix if you have saved your png files from Photoshop and, of course, still have access to the software. I stumbled across this fix in PS and haven't tested in any other applications. Feel free to point out other ones that work in a similar fashion. Note: I was using CS2.

The problem with colors in a png image not matching with other images (such as jpg) or hex color values has been around a long time. It's bugged the hell out of me that I couldn't ever find a very convenient way to get around this issue because png is a superior format to gif. From my understanding, this happens because of gamma correction data that is embedded in the file's meta data. Some browsers will read it, others ignore it. As a result, the actual color of the image can be slightly different than actual color values outside of a color calibrated environment. It's not terribly noticeable most of the time, but if you're working with tiled images it tends to stand out. I've done plenty of digging around (maybe not enough) and the only solutions I ever came across were using 3rd party applications that can read and modify the meta data of a png file, and strip it of the gamma correction information.

Two of the apps I came across that appeared most promising were TweakPNG and PNGCRUSH. TweakPNG is a Windows app, and being that I'm on a Mac this wasn't terribly convenient. While I can certainly boot into Windows or use Parallels to run the app, it's just not worth the trouble. PNGCRUSH is a command line app for DOS or Unix/Linux. Also more effort than it's worth for me.

While working on a site today, I decided to try and work with this problem more to see if anything would come of it. I went ahead and made all the imagery (save for a couple photos in jpg format) png. I thought I could pull it off, but I still had a couple spots where I was using a background color in my stylesheet so it didn't match up with the png images. I remembered the methodology behind the two previously mentioned applications and I started browsing around the menus in PS to see if I could get at any of the embedded data. Turns out, it's completely possible and I'm an idiot for not thinking about it earlier. I suppose it's probably not some hidden menu that no one knew about but I certainly never saw it brought up in any discussions about the png color mismatch dilemma.

After you've saved your file in png format (preferably through the save for web feature), close it and reopen it (so to make sure it's reading the embedded data that was saved with the file). Go to the file menu, then file info. You'll see a window with a list of categories on the left. Go to the Advanced category. Your window should look something like this. Delete the Adobe Photoshop Properties item and the item that just says http://ns.adobe.com/png/1.0/. Click ok, then save your file. The data in the file causing the color shift will now be gone and your images will match up with other image formats and hex color values correctly. It's important to know that if you reopen the file in PS and do any sort of modification (allowing it to be saved again) then it may reapply the embedded data. One additional thing be aware of is that you can put these steps into an action to be reused at any time. It does seem to keep track of how the file info is modified when recording the action.

This fix is kind of stupidly simple, but I was never able to find anyone who used the same method. As a result, I'm writing about it here. If I just completely suck at harnessing the power of Google and it turns out this information is widespread and others have blogged about it, then feel free to ridicule me. Hopefully this helps some folks out anyway.

UPDATE: After some discussion with Jesse, he pointed out that Safari was still forcing a slight color shift (though much less significant than prior to the data stripping). I managed to fix this, at least for myself, by in Photoshop going to the edit menu, then Assign Profile. I assigned a file my working space color profile along with stripping the data out and this seems to make it display correctly in Safari with no color shift. I'm currently unaware if this only repairs it for someone with the same color profile or not but I'll continue testing. However, it does seem that Internet Explorer 6 continues to color shift. All other browsers/platforms I've tested work.

top