Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. That's not what a session is. A session helps you to store information server-side instead of using it's alternative: client-side cookies. And if you want to allow a user to only login once you'd need to store each session id and upon login verify if their isn't already a session with the specified username.
  2. Not true. It can also be abstract if it's just not supposed to be instantiated. What purpose does an abstract class serve if there is no abstract method? Like Daniel0 said: That you cannot instantiate an object of that class. Or polymorphism: abstract class Character {} class Naruto extends Character {} class SinJu extends Character {} class Player { public function setCharacter(Character $character) { $this->_character = $character; } } Now the player may have any character: $player->setCharacter(new Naruto()); $player->setCharacter(new SinJu());
  3. Adding mutliple $addresses as a property to an address class defeats the purpose. class Address { protected $_address; public function __construct($address) { $this->_address = $address; } public function __toString() { return $this->_address; } } class Residential { public function setAddress(Address $address) { $this->_address = $address; } } $addresses = array( new Address('..'), new Address('..') ); Altough I think an Address class is overkill and a waste of memory to something meaningless. OOP has many advantages over procedureal programming: 1) encapsulation of shared information between functions: function user_login($username, $password) { global $db;//shared information but accessible by other functions who knows the name //perform login } function user_register($array) { global $db; //perform registration } class User { protected $_db;//db is encapsulated within User and thus not accessible by other parties (global $db) //login(); //register(); } 2) access levels to define inheritance rules: class User { public $id;//will be inherited; private $_username;//will not be inherited private $_password;//will not be inherited protected $_db;//will be inherited } 3) use access levels for functions to define helpers: class User { public function someFunction() { $this->_someHelperFunction(); } } and much more
  4. I assume you are using MySQL the provided code is not entirely portable so you may need the appropriate manual for your specific db vendor. For part 2: add an is_activated column of type BOOLEAN NOT NULL DEFAULT FALSE and activation_code column of type VARCHAR(40) (and an optionally activated_at column of type DATE) Upon registration fill theses columns: INSERT INTO users (.., activation_code) VALUES (.., SHA1(NOW())) -- Or some other code Upon activation: UPDATE users SET is_activated = TRUE, activated_at = NOW() WHERE id = $userId AND activation_code = $activationCode Upon login: SELECT * FROM users WHERE username = $username AND password = $password $result = mysql_query($query); if (mysql_num_rows($result) === 1) { $row = mysql_fetch_assoc($result); if (!$row['is_activated']) { //not yet activated, close } } else { //user not found }
  5. Store the information between submits: $_SESSION['_POST'] = array(); $_SESSION['_POST'] = array_merge($_SESSION['_POST'], $_POST);
  6. function createQueryString($array = array(), $kvSep = '=', $varSep = '&') { $get = array_merge($_GET, $array); $getVars = array(); foreach ($get as $key => $value) { if (is_string($key)) { $getVars[] = implode($kvSep, array($key, $value)); } } return implode($varSep, $getVars); } <a href="page.php?<?php print createQueryString(); ?>"> <?php $_GET['pageno']++; ?> <a href="page.php?<?php print createQueryString(); ?>"> <a href="page.php?<?php print createQueryString(array('pageno' => 5)); ?>"> Outputs: <a href="page.php?category=apples&color=red&pageno=3"> <a href="page.php?category=apples&color=red&pageno=4"> <a href="page.php?category=apples&color=red&pageno=5">
  7. Possibly even personalising the e-mail.
  8. I am not entirely sure if this is the best way but as 1 question has many answers (even on these forums ) you should first retrieve all questions: SELECT * FROM edu WHERE edu._group = 95 And then while you are looping over the questions you retrieve the possible answers: SELECT * FROM edu_answer WHERE edu_answer.qid = $qid But I think their must be a faster, more cleaner way of doing so, maybe? SELECT * FROM edu_answer WHERE edu_answer.qid IN (SELECT id FROM edu WHERE edu._group = 95) AND edu_answer._group = 95 This retrieves all answers for all current questions. But I'm sure it can be even simpler and faster.
  9. ==? I believe that has the effect of $rows2=null and the while to fail (unless mysql_fetch_array($result2) returns false). Edit: Oeps a bit to late thebadbad already said so
  10. And I answered you with a serious answer Ok If you can't laugh, to create that you need to know which tables store that information and then it's as simple as somewhat every script that relies on a database. Can't tell you anymore as I don't really know how smf stores it's information. A good start would be looking for: smf db scheme
  11. Well that's up to you ofcourse You just asked if there is a way to create a summary of the latest threads and I gave you an answer
  12. Yes. If you want to just store it to execute later use nowdoc (as of 5.3.0)
  13. $emptyfile = str_replace($key, $value, $emptyfile);
  14. require_once ('mysql_connect2.php'); // Connect to the db. // Make the query. $query = "SELECT * FROM powercarts WHERE cart_serial LIKE '$se' or charger LIKE '$se' or inverter LIKE '$se' or battery LIKE '$se' or battery2 LIKE '$se' or inverter2 LIKE '$se' or po LIKE '$se'"; $result = @mysql_query ($query); // Run the query. if (mysql_num_rows($result) == 1) { // If it ran OK. // Print a message. echo '<br>Your entry has been found.</br><br/>'; while ($row = mysql_fetch_array($result)) { echo 'PO: '.$row['po']; echo '<br/> Date: '.$row['date']; echo '<br/> Cart Serial: '.$row['cart_serial']; echo '<br/> Charger: '.$row['charger']; echo '<br/> Battery: '.$row['battery']; echo '<br/> 2nd Battery: '.$row['battery2']; echo '<br/> Inverter: '.$row['inverter']; echo '<br/> 2nd Inverter: '.$row['inverter2']; echo '<br/><a href="powercart_edit.php?id=' . $row['cart_serial'] . '" target="_blank">Edit</a> <a href="order_view_carts.php?id=' . $row['po'] . '" target="_blank">View</a>'; echo '<br/><br/>'; } } else { // Not a valid Customer ID. echo '<div id="title">Page Error</div> <p class="error">This page has been accessed in error.</p><p><br /><br /></p>'; } mysql_close(); // Close the database connection. Always remember to properly indent your code. I fixed it for ya.
  15. As far as I know 0000-00-00 is as blank as a DATE will ever get.
  16. Post the entire code please as that would work fine.
  17. Yes. Their has been a post before who had problems sending his mail to multiple recipients using $to. Altough 'to' can accept multiple recipients it's probably better - for spam sake's - to only add 1 'to' recipient and split all others over cc and bcc
  18. Cartesian product of both tables probably. Wouldn't an outer join suffice? SELECT * FROM edu e LEFT JOIN edu_answers ea ON e._group = ea._group WHERE ea._group = '95'
  19. Or you'd create a index.php (possibly also include includes.php) and include a page whenever it is requested (?page=hello) and the default otherwise. Which gives you a single entry point instead of: adding require_once('includes.php') to each and every page.
  20. Make sure your query part never gets removed from the url: Change from: <a href="page.php"> To: <a href="page.php<?php print $_SERVER['QUERY_STRING'] ? '?' . $_SERVER['QUERY_STRING'] : '';?>">
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.