Dec 17 2008

How to fetch data(s) using mysql_fetch_assoc ?

mysql_fetch_assoc — Fetch a result row as an associative array

<?php

$conn

= mysql_connect("localhost", "mysql_user", "mysql_password");

if (!

$conn) {
echo
"Unable to connect to DB: " . mysql_error();
exit;
}

if (!

mysql_select_db("mydbname")) {
echo
"Unable to select mydbname: " . mysql_error();
exit;
}

$sql = "SELECT id as userid, fullname, userstatus
FROM   sometable
WHERE  userstatus = 1"
;

$result = mysql_query($sql);

if (!

$result) {
echo
"Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}

if (

mysql_num_rows($result) == 0) {
echo
"No rows found, nothing to print so am exiting";
exit;
}

// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
//       then create $userid, $fullname, and $userstatus


while ($row = mysql_fetch_assoc($result)) {
echo
$row["userid"];
echo
$row["fullname"];
echo
$row["userstatus"];
}

mysql_free_result($result);

?>

Dec 17 2008

Serious security flaw found in IE

Microsoft Internet Explorer logo, file pic from 2004

Internet Explorer is used by the vast majority of the world’s computer user

Users of Microsoft’s Internet Explorer are being urged by experts to switch to a rival until a serious security flaw has been fixed.

The flaw in Microsoft’s Internet Explorer could allow criminals to take control of people’s computers and steal their passwords, internet experts say.

Microsoft urged people to be vigilant while it investigated and prepared an emergency patch to resolve it.

Internet Explorer is used by the vast majority of the world’s computer users.

It’s a shame Microsoft have not been able to fix this more quickly
Darien Graham-Smith
PC Pro magazine

“Microsoft is continuing its investigation of public reports of attacks against a new vulnerability in Internet Explorer,” said the firm in a security advisory alert about the flaw.

Microsoft says it has detected attacks against IE 7.0 but said the “underlying vulnerability” was present in all versions of the browser.

Other browsers, such as Firefox, Opera, Chrome, Safari, are not vulnerable to the flaw Microsoft has identified.

Browser bait

“In this case, hackers found the hole before Microsoft did,” said Rick Ferguson, senior security advisor at Trend Micro. “This is never a good thing.”

As many as 10,000 websites have been compromised since the vulnerability was discovered, he said.

“What we’ve seen from the exploit so far is it stealing game passwords, but it’s inevitable that it will be adapted by criminals,” he said. “It’s just a question of modifying the payload the trojan installs.”

MICROSOFT SECURITY ADVICE
Change IE security settings to high (Look under Tools/Internet Options)
Switch to a Windows user account with limited rights to change a PC’s settings
With IE7 or 8 on Vista turn on Protected Mode
Ensure your PC is updated
Keep anti-virus and anti-spyware software up to date

Said Mr Ferguson: “If users can find an alternative browser, then that’s good mitigation against the threat.”

But Microsoft counselled against taking such action.

“I cannot recommend people switch due to this one flaw,” said John Curran, head of Microsoft UK’s Windows group.

He added: “We’re trying to get this resolved as soon as possible.

“At present, this exploit only seems to affect 0.02% of internet sites,” said Mr Curran. “In terms of vulnerability, it only seems to be affecting IE7 users at the moment, but could well encompass other versions in time.”

Richard Cox, chief information officer of anti-spam body The Spamhaus Project and an expert on privacy and cyber security, echoed Trend Micro’s warning.

“It won’t be long before someone reverse engineers this exploit for more fraudulent purposes. Trend Mico’s advice [of switching to an alternative web browser] is very sensible,” he said.

This could be the moment when the minnows in the browser wars finally score a significant victory
Rory Cellan-Jones
BBC technology editor

PC Pro magazine’s security editor, Darien Graham-Smith, said that there was a virtual arms race going on, with hackers always on the look out for new vulnerabilities.

“The message needs to get out that this malicious code can be planted on any web site, so simple careful browsing isn’t enough.”

“It’s a shame Microsoft have not been able to fix this more quickly, but letting people know about this flaw was the right thing to do. If you keep flaws like this quiet, people are put at risk without knowing it.”

“Every browser is susceptible to vulnerabilities from time to time. It’s fine to say ‘don’t use Internet Explorer’ for now, but other browsers may well find themselves in a similar situation,” he added.

Source

Dec 10 2008

Let’s Install JSON for PHP 5

Originally by Scott Hebert

* his article has been edited to fit in my case.

JSON (JavaScript Object Notation) LogoI recently started messing around with building my own Facebook application. I figured the best way to start learning was to download the demo application and get it working on the Slaptijack web server. I quickly ran into a problem:

PHP Fatal error:  Call to undefined function json_encode()

The problem is that PHP 5.2 includes the json_encode() and json_decode() functions built right in. Unfortunately, I’m running on PHP 5.0 which doesn’t include native JSON support. Here’s how I resolved that.

1. Install json – This was actually trickier than expected. I assumed I would be able to install this via pear. Apparently, a PEAR Services_JSON package was developed, but it has never been accepted into the official repository.

The trick instead is to use the PECL json package. This was as easy as running pecl install json and watch the compiler do its thing.

When it’s done you should have a json.so file in your PHP modules directory. Usually under: /usr/lib/php/modules/

2. Create a file with nano or vi, named : json.ini and put it in to /etc/php.d/ folder – and simply add extension=json.so to this file and that will enable the extension. *skip this step if you don’t have /etc/php.d/ folder*

In other case, you can just need to add: extension=json.so inside your php.ini file. Easy way, you can run below command from your root access :

echo “extension=json.so” >> [directory_path_to]/php.ini

3. Restart Apache - Not much more to add here. Without the restart, the extension won’t be loaded.

4. Profit!

That’s all it took. Now my PHP 5 installation is kicking along happily with the required JSON functions.

Original source:
http://slaptijack.com/system-administration/lets-install-json-for-php-5/