Re: [PHP] Re: Programming general question

2009-01-28 Thread Usamah M. Ali
On Wed, Jan 28, 2009 at 11:07 PM, Terion Miller  wrote:
> On Wed, Jan 28, 2009 at 3:54 AM, Ondrej Kulaty  wrote:
>> Thanks for all the information, I was asking because I inherited thousands
> of lines of code that had used mysql_fetch_object(), yet I kept getting so
> many errors so I starting playing with changing them to mysql_fetch_assoc()
> and things seem to work better, so I was wonder why sometimes data from a db
> field can be used as an object or array, the arrays, objects, classes still
> confuses me..oh add functions to that, is there a hiearchy?
>

If an object is not an ACTUAL class instance, then it's no more than a
syntactic sugar array. For example:

$user = new stdClass(); // General class name, used internally by PHP
$user->username = 'John Doe',
$user->email = 'john_...@example.com';
$user->password = md5('some_hard_or_easy_password_string');
...

is almost typical to:

$user = array();
$user['username'] = 'John Doe';
$user['email'] = 'john_...@example.com';
$user['password'] = md5('some_hard_or_easy_password_string');
...

Many programmers particularly use objects for retrieving database
results because they require less verbose than arrays:

$result->username is just easier and less error-prone than $result['username'].

Using objects as class instances is totally different than using
arrays as many repliers have said. They're usually used, objects that
is, within OOP (Object-Oriented Programming), which relies on the idea
of thinking of programming in resemblance to real-world things
(objects). Thinking in this paradigm is, again, totally different than
traditional procedural programming, and requires a hard shift in the
way you think about programming in general. I suggest consulting the
manual sections on OOP (specially for PHP5), or other basic tutorials
or books on this huge subject.

Regards,
Usamah

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Zend (or other) Framework...where to start?

2009-01-14 Thread Usamah M. Ali
On Thu, Jan 15, 2009 at 1:59 AM, Paul M Foster  wrote:

> If you're going to go with a prebuilt framework, I'd recommend
> CodeIgniter for your first time out. If the docs look good to you (and
> they are pretty good), you'll probably do fine with it. It's about the
> lightest weight platform out there. It doesn't get in your way too much,
> but gives you the benefits of using a framework.
>

I downloaded CI because of recommendations from this list as well, but
was totally shocked when I discovered that its codebase is written in
PHP4! I looked up for an alpha version that is written in PHP5 to no
avail. I just can't understand why would they still be in PHP4 while
Symfony, a framework born after CI, requires PHP5 since version one
and takes full advantage of PHP5's advanced OO features!

Regards,
Usamah

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: why are passwords stored encrypted in databases even when thedatathey protect is stored in the same database?

2008-06-13 Thread Usamah M. Ali
Taking into mind that email addresses extracted out of hacked
databases is one of the main spam industry seeders, I always wonder
why web application developers don't consider encrypting emails the
same way they consider encrypting password! Once a hacker has full
access to a database, an encrypted password becomes like locking the
door while keeping the window open!

Say a user has an account in some discussion forum, that uses an open
source, or visible-source software. She has about 5000 posts in which
she has expressed her personal opinions on just about many things. Now
what a hacker has to do is to dump the database into a local server
running the same software, and begin analyzing the data, creating
well-crafted lists of "potential customers" for which he's going to
deliver very well-targeted mailing newsletters!

Regards,
Usamah

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Forum coded in PHP with mail and news gateway

2008-06-12 Thread Usamah M. Ali
On Thu, Jun 12, 2008 at 4:34 PM, Bastien Koert <[EMAIL PROTECTED]> wrote:

>>
>> PHP does not support threading AFIAK.
>
>

He probably meant "threading" as in "forum threads", i.e. topics where
discussions are presented in a threaded way.

Regards,
Usamah

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] A problem with fgets()

2008-06-05 Thread Usamah M. Ali
Well, finally found an explanation and a solution: calling fgets()
twice. Because if there's no length limit supplied (and it's not EOF)
when calling the function, it continues reading until it finds the
first newline character. So calling fgets() again will ensure that it
will read from the _beginning_ of the *next* line:



To clarify more, if the first call to fgets() reads the line
containing the city name 'Alexandria', it might be read as:
andria

Now calling fgets() again will definitely read the whole next line:
Dallas


>
> Yes, I agree that that note is complete hogwash, and have just deleted
> it!
>
> Cheers!
>
> Mike
>

Thanks. :)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Quickly verifying single word.

2008-06-05 Thread Usamah M. Ali
On Thu, Jun 5, 2008 at 12:02 PM, Usamah M. Ali <[EMAIL PROTECTED]> wrote:

> Won't work either. The problem lies in using the === comparison
> operator. preg_match() returns 0 if no match is found, and FALSE if an
> error occurred. So using === will always echo 'No spaces' whether
> there were spaces or not, provided that no error has occurred.
>
> if (!preg_match('/\s+/i', $string))
> {
>echo 'No spaces';
> }
>
> should suffice.
>
> Regards,
> Usamah
>

Won't work either. :)

This should work fine:
if (preg_match('|\s+|i', $string) === 0)
{
echo '$string does not contain white spaces!';
}
elseif preg_match('/\s+/i', $string)
{
echo 'One or more white spaces found!';
}
else
{
echo 'An error has occurred!';
}

According to your needs, it could be simply shortened to the first if:
if (preg_match('/\s+/i', $string) === 0)
{
echo 'No white spaces';
}

Hope that works well.

Regards,
Usamah

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Quickly verifying single word.

2008-06-05 Thread Usamah M. Ali
On Thu, Jun 5, 2008 at 9:19 AM, Per Jessen <[EMAIL PROTECTED]> wrote:
> Shawn McKenzie wrote:
>
>>> if (preg_match('/[\s]*/', $string) === false) {
>>> echo 'No spaces!';
>>> }
>>>
>>> -Shawn
>>
>> Second one doesn't work for some reason.  No time now to test, will
>> later.
>
> How about:
>
> if (preg_match('/\s/', $string) === false) {
>echo 'No spaces!';
> }
>
>
Won't work either. The problem lies in using the === comparison
operator. preg_match() returns 0 if no match is found, and FALSE if an
error occurred. So using === will always echo 'No spaces' whether
there were spaces or not, provided that no error has occurred.

if (!preg_match('/\s+/i', $string))
{
echo 'No spaces';
}

should suffice.

Regards,
Usamah

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] A problem with fgets()

2008-05-29 Thread Usamah M. Ali
On Fri, May 30, 2008 at 4:21 AM, Chris <[EMAIL PROTECTED]> wrote:
>
>
>> I just need to figure out why when using fgets() with fseek() &
>> rand(), the script returns partial strings form the city names.
>
> Because fseek doesn't necessarily put you at the start of a line.
>
> It puts you anywhere (which could be the start, middle, 3 chars from the
> end) according to the number of bytes you tell it to start at.
>
> Then fgets reads the rest of the line.
>
> A file that looks like this:
>
> (numbers are the "bytes" for ease of explanation)
>
> 123456789
>
> is going to be different to a file that looks like this:
>
> 1234
> 56
> 789
>
> and if you tell me you want to start at "byte 5", then in file 1, that's
> the middle - in file 2 that's the start of the second line (#4 is a
> newline char :P).
>

So you're confirming that fgets() doesn't necessarily read a whole
line? This user note existed on the manual's page of fgets() since
2004 and nobody deleted it or commented about:

rstefanowski at wi dot ps dot pl
12-Aug-2004 09:03

"Take note that fgets() reads 'whole lines'. This means that if a file
pointer is in the middle of the line (eg. after fscanf()), fgets()
will read the following line, not the remaining part of the currnet
line. You could expect it would read until the end of the current
line, but it doesn't. It skips to the next full line."

That was my source of confusion.

Regards,
Usamah

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] A problem with fgets()

2008-05-29 Thread Usamah M. Ali
On Fri, May 30, 2008 at 3:38 AM, Chris <[EMAIL PROTECTED]> wrote:
> fseek doesn't go to the start of a line, it goes to a particular byte -
> so that's where the problem lies (not with fgets). There's no function
> (that I could see) which would go to the start of the line based on that
> offset (I guess you could fseek to a particular spot then reverse char
> by char until you find a newline - but that'll be rather slow for
> anything that has a long line).
>
>
> You could read the whole thing into an array and do a rand on that:
>
> $cities = file('filename.txt');
>
> // take 1 off from the max number as $cities is a 0 based array
> $number_of_cities = sizeof($cities) - 1;
>
> $city_number = rand(0, $number_of_cities);
> $city = $cities[$city_number];
>
> Though if you have a big file that reads the whole thing into memory etc.
>

I didn't say fseek() goes to the start of a line. I said that fgets()
should read a whole line, no matter where the pointer is at. I've
already managed to get the result I want by using file() as you've
suggested and array_rand(), and the result is very good.

I just need to figure out why when using fgets() with fseek() &
rand(), the script returns partial strings form the city names.

Regards,
Usamah

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] A problem with fgets()

2008-05-29 Thread Usamah M. Ali
Hello,

I have a function that picks up a random entry from a file consisting
of city names, each name on a separate line. The random value is
generated by rand() before fseek()ing to the position determined by
it. The problem is that when using fgets() to get a random line, it
returns a part of the city name, not the whole name. AFAIK, fgets()
reads a whole line, and even if it's in the middle of a line, it reads
the whole next line.

Some sample of the city names file is as follows:

Amsterdam
Zurich
Alexandria
Dallas
Rome
Berlin

And the scripts outputs them weirdly enough something like:
Amster
andria
Da
me
Berlin

Here's the function:



I'm using XAMPP on Windows, PHP 5.2.1.

What am I missing here?

Regards,
Usamah

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: RES: [PHP] page suck attack

2008-05-21 Thread Usamah M. Ali
Sorry, the link:
http://www.javascriptkit.com/howto/htaccess13.shtml

Usamah

On Thu, May 22, 2008 at 1:15 AM, Usamah M. Ali <[EMAIL PROTECTED]> wrote:

>
>
> On Wed, May 21, 2008 at 8:51 PM, robert <[EMAIL PROTECTED]> wrote:
>
>> Cool! yes Fasterfox could be it. If anyone cares, it also gave me some
>> clues to what I was looking for: "offline browsing". Certainly better
>> keywords than "page suck" :)
>>
>> thank you everyone!
>>
>>
> Well, "site rippers" is a more suitable name today, as most people are on
> fast DSL/cable connections so no need for "offline browsing". Those days are
> gone.. sigh!
>
> Is your site content-heavy? It could be someone trying to download your
> site's content to use for whatever reason it might be, or it might be just a
> script kiddie trying enjoying his time. Anyway you should it take it
> seriously and investigate the information available at your hand about the
> source and cause of these actions.
>
> Here's a nice tutorial on how to deal with these scripts by blocking them
> through the use of robots.txt and .htaccess. It's a part of a series so
> you'd better start from the first part.
>
> Regards,
> Usamah
>


Re: RES: [PHP] page suck attack

2008-05-21 Thread Usamah M. Ali
On Wed, May 21, 2008 at 8:51 PM, robert <[EMAIL PROTECTED]> wrote:

> Cool! yes Fasterfox could be it. If anyone cares, it also gave me some
> clues to what I was looking for: "offline browsing". Certainly better
> keywords than "page suck" :)
>
> thank you everyone!
>
>
Well, "site rippers" is a more suitable name today, as most people are on
fast DSL/cable connections so no need for "offline browsing". Those days are
gone.. sigh!

Is your site content-heavy? It could be someone trying to download your
site's content to use for whatever reason it might be, or it might be just a
script kiddie trying enjoying his time. Anyway you should it take it
seriously and investigate the information available at your hand about the
source and cause of these actions.

Here's a nice tutorial on how to deal with these scripts by blocking them
through the use of robots.txt and .htaccess. It's a part of a series so
you'd better start from the first part.

Regards,
Usamah