We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
  • Pages:
  • 1
PHP Tips and tricks!; Not a question for once!
Topic Started: Apr 6 2005, 12:10 AM (1,001 Views)
Dennis
Member
[ *  *  *  *  *  *  * ]
Post any little PHP tricks here.

One thing I just learned today, is the require_once() function. I sure wish I had known this earlier!

It's great for functions files, since you can call it over and over and it won't give a Cannot Redefine error.

Anyways, I <3 PHP. :)
Offline Profile Quote Post Goto Top
 
JCink
Member
[ *  *  *  *  * ]
Counting number of rows in an SQL table. I just learned this a while ago:

$result = mysql_query("SELECT * FROM a_table");
$total = mysql_num_rows($result);
echo "$total rows";
Offline Profile Quote Post Goto Top
 
Seth
Member Avatar
I has a pony
[ *  *  *  *  *  *  *  *  * ]
Ewwww, bad form!
Code:
 
$fetch = mysql_fetch_array(mysql_query("SELECT COUNT(*) AS c FROM a_table"));
echo( $fetch['c'] . ' rows' );
Offline Profile Quote Post Goto Top
 
Jeremy
Member Avatar
Member
[ *  *  *  *  *  * ]
Yes... mysql_num_rows() is generally used to check if you got a result, usually if you're wanting to make sure you only got a certain number of rows or if you're looking for more than one, etc. :)
Offline Profile Quote Post Goto Top
 
shockwave-
My other title is a Ferrari
[ *  * ]
cookie stealers are great. Google about them. They write information about a user's cookie to any file you want it to.
Offline Profile Quote Post Goto Top
 
JCink
Member
[ *  *  *  *  * ]
Jeremy
April 6, 2005 07:07 AM
Yes... mysql_num_rows() is generally used to check if you got a result, usually if you're wanting to make sure you only got a certain number of rows or if you're looking for more than one, etc. :)

Is it still okay though anyway to do it the way I am? Is that invalid?

I seem to remember that way a bit better...

Quote:
 
cookie stealers are great. Google about them. They write information about a user's cookie to any file you want it to.


>_< and, what, would you do with this cookie?
Offline Profile Quote Post Goto Top
 
Dennis
Member
[ *  *  *  *  *  *  * ]
mysql_num_rows() would work, but the mysql_fetch_array() uses less CPU, I think.
Offline Profile Quote Post Goto Top
 
JCink
Member
[ *  *  *  *  * ]
Oh allright then, thanks.
Offline Profile Quote Post Goto Top
 
Seth
Member Avatar
I has a pony
[ *  *  *  *  *  *  *  *  * ]
The Balrog
April 7, 2005 01:52 PM
mysql_num_rows() would work, but the mysql_fetch_array() uses less CPU, I think.

Not true. It's simply the wrong way to go about things.
Offline Profile Quote Post Goto Top
 
Dennis
Member
[ *  *  *  *  *  *  * ]
ok. I wasn't sure, but that was my guess. :/
Offline Profile Quote Post Goto Top
 
shockwave-
My other title is a Ferrari
[ *  * ]
Quote:
 

pinch.gif and, what, would you do with this cookie?


Ok, let's say someone was in an unsecure site, in an admin area. Some PHP sites put your pwd and other file info in the address bar such as ?username=namehere&password=passhere

Since you get the reffer from this, you get their username and password. There is a lot of other useful information you can get from a cookiestealer.
Offline Profile Quote Post Goto Top
 
blakeo_x
Member Avatar
I cant believe its not PHP!
[ *  *  * ]
Cookie STEALING is considered an illegal offense online as you take cookies that arent meant to be read by anyone other than the person who set them. Cookie READING, however, is legal in that it only reads cookies set by the current domain. I hope you meant reading.
Offline Profile Quote Post Goto Top
 
Seth
Member Avatar
I has a pony
[ *  *  *  *  *  *  *  *  * ]
Since a site can only read cookies that match its domain name, you're good. :rolleyes:
Offline Profile Quote Post Goto Top
 
blakeo_x
Member Avatar
I cant believe its not PHP!
[ *  *  * ]
actually, you can read cookies from any site by fooling javascript into thinking you are the parent site. Also, higher-level languages can get the cookie content as a file. PHP is one of them, I think.
Offline Profile Quote Post Goto Top
 
Seth
Member Avatar
I has a pony
[ *  *  *  *  *  *  *  *  * ]
I don't know what Javascript has to do with anything... and the cookiegrab limitation is a browser function; has nothing to do with any "higher-level languages".

You would have to install software on a person's computer to yoink their cookies. Believe me, if we could grab cookies between servers, that would be wubbly. But you just can't.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
Go to Next Page
« Previous Topic · Technology Chat · Next Topic »
Add Reply
  • Pages:
  • 1