ignace
Moderators-
Posts
6,457 -
Joined
-
Last visited
-
Days Won
26
Everything posted by ignace
-
Post your database table structure DESCRIBE table1; DESCRIBE table2; ..
-
Yes it does if it wouldn't REFERER would be broken your iframe is the caller which is tes1 so last REFERER for tes2 is tes1 If you want tes the remove the iframe. Don't forget the iframe makes a different request (tes1) then your own (tes)
-
The manual could told you that: Those are 2 real advantages of PDO over MySQLi. IMO Stick with MySQLi unless you want to distribute your software for which I would recommend Doctrine or Zend_Db.
-
Zend framework. IMO the best out there.
-
I actually wanted to hide this kind of complexity from him Now he has to deal with <<, >>, ~ and ^ instead of only | and & function setbit($flags,$position) { return $flags|(1<<$position); } function resetbit($flags,$position) { return $flags&(~(1<<$position)); } function togglebit($flags,$position) { return $flags^(1<<$position); } function readbit($flags,$position) { return ($flags|(1<<$position))?1:0; } N-Bomb check this manual page out: http://php.net/manual/en/language.operators.bitwise.php
-
Try this piece of code to get a hang on it: <form action="" method="post"> <label for="real_name">Show real name:</label> <input type="checkbox" name="real_name" id="real_name"> <label for="email_address">Show email address:</label> <input type="checkbox" name="email_address" id="email_address"> <label for="street_address">Show street address:</label> <input type="checkbox" name="street_address" id="street_address"> <label for="country">Show country</label> <input type="checkbox" name="country" id="country"> <label for="phone_number">Show phone number</label> <input type="checkbox" name="phone_number" id="phone_number"> <label for="cellphone_number">Show cellphone number</label> <input type="checkbox" name="cellphone_number" id="cellphone_number"> <label for="gender">Show gender</label> <input type="checkbox" name="gender" id="gender"> <label for="political_preferences">Show political preferences</label> <input type="checkbox" name="political_preferences" id="political_preferences"> <input type="submit"> </form> <?php if ('POST' === $_SERVER['REQUEST_METHOD']) { $show_real_name=1; $show_email_address=2; $show_street_address=4; $show_country=8; $show_phone_number=16; $show_cellphone_number=32; $show_gender=64; $show_political_preferences=128; $flags = 0; if (isset($_POST['real_name'])) $flags |= $show_real_name; if (isset($_POST['email_address'])) $flags |= $show_email_address; if (isset($_POST['street_address'])) $flags |= $show_street_address; if (isset($_POST['country'])) $flags |= $show_country; if (isset($_POST['phone_number'])) $flags |= $show_phone_number; if (isset($_POST['cellphone_number'])) $flags |= $show_cellphone_number; if (isset($_POST['gender'])) $flags |= $show_gender; if (isset($_POST['political_preferences'])) $flags |= $show_political_preferences; echo 'decimal: ', $flags, ' binary: ', decbin($flags), '<br><br>Public viewable data:<br>'; if ($flags & $show_real_name) echo 'real name<br>'; if ($flags & $show_email_address) echo 'email address<br>'; if ($flags & $show_street_address) echo 'street address<br>'; if ($flags & $show_country) echo 'country<br>'; if ($flags & $show_phone_number) echo 'phone number<br>'; if ($flags & $show_cellphone_number) echo 'cellphone number<br>'; if ($flags & $show_gender) echo 'gender<br>'; if ($flags & $show_political_preferences) echo 'political preferences<br>'; } ?>
-
1 exif if supported, 2 gd if supported and not jpeg or tiff, 3 getimagesize otherwise
-
Some more explanation of what laffin is saying: (2^0 = 1) = 0001 (2^1 = 2) = 0010 (2^2 = 4) = 0100 (2^3 = = 1000 You notice a pattern in the above code 0001, 0010, 0100, 1000 the one moves from right-to-left. Now each place represents wether or not he wants to show a certain field for example email, birthday, friendlist, .. $birthday = 1; // 1 = 0001 $email = 2; // 2 = 0010 $friendlist = 4; // 4 = 0100 list($bitflags) = mysql_fetch_array($result, MYSQL_NUM); $bitflags = intval($bitflags); // assume: $bitflags = 3 = 0011 (user wants to show email and birthday but nothing else) if ($bitflags & $email) { // 0011 & 0001 = 0001 (true) .. } if ($bitflags & $birthday) { // 0011 & 0010 = 0010 (true) .. } if ($bitflags & $friendlist) { // 0011 & 0100 = 0000 (false) .. } You need to understand binary math to be able to understand why this works: or: 0 | 0 = 0 0 | 1 = 1 1 | 0 = 1 1 | 1 = 1 and: 0 & 0 = 0 0 & 1 = 0 1 & 0 = 0 1 & 1 = 1 xor: 0 ^ 0 = 0 0 ^ 1 = 1 1 ^ 0 = 1 1 ^ 1 = 0
-
Take a look at getimagesize and filesize
-
number_format or if you use linux and your OS supports strfmon money_format
-
Is it my math? I bet it is my math. It is always my math.
ignace replied to Lamez's topic in PHP Coding Help
What's wrong with a simple query? $q = 'UPDATE ' . TBL_PEOPLE . ' SET online = 0 WHERE timestamp + 300 < now()'; -
You should avoid using Singleton's as discussed here: http://www.phpfreaks.com/forums/index.php/topic,283313.msg1343157.html
-
This is also usefull for other business logic for example if your post count should not increase if you post in a certain forum. Being one reason, second reason would be because most likely it's going to appear as a widget in the left or right nav of the website and when you have many visitors (and thus many posts) your using your database intensively (calculating the total post_count over and over) to provide you with data that is trivial to your website.
-
Problem with calling mySQL queries into meta tags
ignace replied to Johns3n's topic in PHP Coding Help
Yeah I'm so used of people using mysql_fetch_array() without the second parameter I'm now just writing it out of habit -
Yeah unless they give those @php.net e-mails away for free?!? Plus your recent Guru promotion means your words have a much higher-value then if some john doe said something, like me . I believe this is everyone's secret I already got the manual on speed dial Plus because of the authority the PHP manual has on Google it' easy for me to just type: php some_function In my Firefox URL address bar which is the same as I'm feeling lucky on Google search add in a nice add-on and you can just type the function name in the upper right search bar of Firefox, what's not to like? PHP Manual ROCKS!!
-
You should avoid calculation as much as you can. Instead add a post_count to the users table and then use ORDER BY post_count DESC Increment the post_count on each new post the user makes. This is also usefull for other business logic for example if your post count should not increase if you post in a certain forum.
-
Your constructor should never do real work only initialization logic: class SomeClass { private $_db; public function __construct($value) { $this->_value = $value;/* <-- no work */ } public function getDb() { if (null === $this->_db) { $this->_db = new MySQLi(...); } return $this->_db; } } When you are programming remember to always lazy-load everything hold the creation of an object off until you absolutly need it.
-
Though I must say that because of your rep. my first thought was that they removed it and had to look it up to be sure
-
Your setup is completly wrong and actually should be: <table> <tr> <table border = 2 > <tr><th>Total</th><th>Postage and Packaging</th><th>Grand Total</th></tr> <td><?php print get_subtotal(); ?></td> <td>+ £5.95 (VAT)</td> <td><?php print get_total(5.95); ?></td> </table>
-
Problem with calling mySQL queries into meta tags
ignace replied to Johns3n's topic in PHP Coding Help
Strange that everyone missed this: while($site_params = mysql_fetch_assoc($params)) { echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"; echo "<html xmlns='http://www.w3.org/1999/xhtml'>"; echo "<head>"; echo "<meta name='Keywords' content='" . $site_params['site_keywords'] . "' />"; echo "<meta name='Description' content='" . $site_params['site_description'] . "' />"; echo "<title>" . $site_params['site_title'] . "</title>"; } Which should be: <!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> <?php $site_params = mysql_fetch_assoc($params, MYSQL_ASSOC); ?> <meta name='Keywords' content='<?php print $site_params['site_keywords']; ?>' /> <meta name='Description' content='<?php print $site_params['site_description']; ?>' /> <title><?php print $site_params['site_title']; ?></title> Edit: oeps apparently Buddski did My bad! -
http://www.php.net/manual/en/language.operators.comparison.php, are you sure?
-
if($logged['userlevel']==9){echo'user is administrator show admin links} is IMO bad practice. This may work for you as you know what each number represents however new project members will have to come ask you over and over: "What group was 9 again?" It also makes your code unreadable, for example: if (2 == $userlevel || 4 == $userlevel) { .. } else if (6 == $userlevel) { .. } else { // assume 1,3 or 5 .. } Where using: class User { const ROLE_GUEST = 'guest'; const ROLE_MEMBER = 'member'; const ROLE_AUTHOR = 'author'; const ROLE_EDITOR = 'editor'; const ROLE_ADMINISTRATOR = 'administrator'; private $_role = self::ROLE_GUEST; public function getRole() { return $this->_role; } public function isGuest() {} public function isMember() {} public function isAuthor() {} public function isEditor() {} public function isAdministrator() {} } Would result in: if ($user->isAuthor() || $user->isEditor()) { .. } else if ($user->isAdministrator()) { .. } else { // assume isGuest(), isMember() .. } So, which would you prefer? [ot]Vanwaar in België ben je ergens?[/ot]
-
No because they aren't accessible anyhow because it is under the webroot however on a shared hosting environment you are not allowed to have such setups and everything needs to be contained within the htdocs directory whereby all application directories would be accessible however using .htaccess and chmod you can deny access. Only in a few rare occassions am I forced into this setup.
-
PHP5 - Creating a single instance for an entire application?
ignace replied to Perad's topic in PHP Coding Help
UserRepository and AuthService are obviously not controllers but models.