Jump to content

HDFilmMaker2112

Members
  • Posts

    547
  • Joined

  • Last visited

    Never

Everything posted by HDFilmMaker2112

  1. This is bugging me; it's only a error notice. So when I turn error reporting off it goes away, but I'd like to stop it all together. $url=$_SERVER['REQUEST_URI']; list($junk, $key) = explode("?", $url); The above is giving: Notice: Undefined offset: 1 on Line 5 Line 5 is the list
  2. So if that works the way I think it does, it would save thousands of queries. That would get all the status updates of all the friends in the friends list that are linked to the user id, correct?
  3. This a continuation from my XML thread. If I were to go the Database route, how would I organize all the data retrieved from the DB? Here's how my tables would be laid out: Friends Table: id | user_id | friend_id Status Updates Table: id | user_id | status_message | time_posted Comments Table: id | user_id | comment | time_posted | status_id So from there I would query the friends table for the users friends, take the results from that query, and query the status updates table for status updates in a loop from the friend ids. So I would end up with roughly something like this: User Friend #1: Status Update #1 - 6/10/2012 at 4:00 PM Status Update #2 - 6/7/2012 at 1:23 PM Status Update #3 - 6/5/2012 at 12: 24 PM User Friend #4 Status Update #1 - 6/10/2012 at 5:00 PM Status Update #2 - 6/7/2012 at 3:23 PM Status Update #3 - 6/5/2012 at 11: 24 PM So how would I order those returned status updates in chronological order, starting with the most recent? From the above, User Friend #4's Status Update #1 would need to be placed before User Friend #1 Status Update #1, and User Friend #4 Status Update #2 would need to be placed before User Friend #1 Status Update #2, etc. Then I would need to add the comments from the comments table based on the status_id and order by time_posted (which this step is fairly straight forward). I'm assuming this is definitely a place for PDO, transactions, and prepared statements.
  4. It just seems like a logistical nightmare to run these via database queries. I'd have to query the "connections" table to generate the users friends list, then pull all their friends status updates, then somehow order them in chronological order, since each friends status updates would be pull individually. So I'd have iterate through 4000 queries in to the status updates table, and them somehow in PHP cobble them together in the correct order. Then on top of all this, we'd have introduce the comments tables which would need to run queries for each and every status update. So 4000 friends with 10 status updates each, would probably put the amount of queries at 40,000 then multiple by 10 times for the rough amount of times each user might come back to their news feed in any given browsing session. I'm at 400,000 queries for one user in a matter of an 30 minutes or so. Would it not be better to produce the output on writing, not trying to read it dynamically? There will be significantly more reads then writes; Probably 100 to 1 or more.
  5. Use sessions to repopulate the input fields with the stored value in the session. <input type="text" name="" id="" value="$_SESSION['session_name']" /> When each page is submitted assign the $_POST to a session, and don't unset the sessions until all the data is finally submitted.
  6. Social Networking site. I'm figuring it would be less resource intensive to write a XML file of every bodies news feeds, instead of querying the database every single time they reload their news feed. So say a user posts a status update, and they have 4000 friends, that update would be sent to those 4000 XML files. As opposed to say those 4000 people at some point loading their news feed page say 10 times each in any given browsing session; that's up to 40,000 possible database queries; instead of 1 query and 4000 xml file writes.
  7. I know of the SimpleXML extension in PHP. But I'm looking for a bit of an example on how it would be put to use. I would be generating a XML file from a database and then saving that file to the server. Are there any examples of this is actually done with SimpleXML? An example of what I would probably be generating: <news_feed> <status_update> <user>User 432612</user> <message>This is a test message.</message> <date>6/9/2012 at 3:00 PM</date> <comment>Comment 1</comment> <comment>Comment 2</comment> <comment>Comment 3</comment> <comment>Comment 4</comment> <comment>Comment 5</comment> </status_update> <status_update> <user>User 423172</user> <message>This is a test message.</message> <date>6/9/2012 at 12:00 PM</date> <comment>Comment 1</comment> <comment>Comment 2</comment> <comment>Comment 3</comment> <comment>Comment 4</comment> <comment>Comment 5</comment> </status_update> <status_update> <user>User 441422</user> <message>This is a test message.</message> <date>6/9/2012 at 9:00 AM</date> <comment>Comment 1</comment> <comment>Comment 2</comment> <comment>Comment 3</comment> <comment>Comment 4</comment> <comment>Comment 5</comment> </status_update> <status_update> <user>User 434212</user> <message>This is a test message.</message> <date>6/7/2012 at 6:00 PM</date> <comment>Comment 1</comment> <comment>Comment 2</comment> <comment>Comment 3</comment> <comment>Comment 4</comment> <comment>Comment 5</comment> </status_update> </news_feed> From there, how would I retrieve the file and read it? I'd be looking to load the file in my login.php page (just a processing page, nothing is shown here); then store that data some how for display on the page the user gets sent after the login page. If I've read write, I would need to store the XML as a string in order to store some where PHP can use it later. If so, how would I then get the data out of it?
  8. I have a work around, but it's not OO though. Just running a function like this works without issue: function mysqli_sanitize($conn,$formValue){ if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { $formValue = stripslashes($formValue); } $formValue = $conn->real_escape_string($formValue); return $formValue; } $DB = new DBConnection; $LoginDB = $DB->connect('mysqli', 'persist', 'db418598519'); /*Encode - Sanitize user input for query*/ $sanitized_email = mysqli_sanitize($LoginDB, $login_username);
  9. It's actually not a live site. And I figured out the issue (a session expired that I manually set myself, pretty much not related what I'm trying to do here), everything's all good now. Plus I got this working somewhat. The below connects without an issue, its just now giving me an error of: Fatal error: Call to undefined method mysqli_errordisplay::mysqli_sanitize() So it's seeing it as the errordisplay class; which I guess is a good thing for the connection, but not the sanitize function. /*Connect to DB*/ $DBConnect = new DBConnection; $LoginDB = $DBConnect->connect('mysqli', 'persist', 'db418598519'); /*Encode - Sanitize user input for query*/ $sanitized_email = $LoginDB->mysqli_sanitize($login_username); class DBConnection { private $DBconnect; public function connect($mysqlipdo, $persistcoe, $dbname, $user = 'dbo418598519'){ if($mysqlipdo=="pdo" && $persistcoe=="persist"){ $this->DBconnect = new SafePDO_errordisplay("mysql:host=db.1and1.com;dbname=$dbname", $user, "pass", array(PDO::ATTR_PERSISTENT => true)); } elseif($mysqlipdo=="pdo" && $persistcoe=="coe"){ $this->DBconnect = new SafePDO_errordisplay("mysql:host=db.1and1.com;dbname=$dbname", $user, "pass"); } elseif($mysqlipdo=="mysqli" && $persistcoe=="persist"){ $this->DBconnect = new mysqli_errordisplay('p:db418598519.db.1and1.com', $user, "pass", $dbname); } elseif($mysqlipdo=="mysqli" && $persistcoe=="coe"){ $this->DBconnect = new mysqli_errordisplay('db.1and1.com', $user, "pass", $dbname); } else{ } return $this->DBconnect; } public function mysqli_sanitize($formValue){ if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { $this->formValue = stripslashes($formValue); } $formValue = $this->real_escape_string($formValue); return $this->formValue; } } I tried $DBConnect->mysql_sanitize and that didn't work. Also tried $this->DBConnection->real_escape_string in the function.
  10. Well my entire site is broken now, so I'm just abandoning the whole thing.
  11. Yeah, I'm unfortunately completely broke; I can't afford a book.
  12. So I'm basically going to have to recreate every single method used by MySQLi? Cause that's where this is headed. At that point screw OOP. I thought once I established a connection I'd be able to use the built in functions of php. A query method would essentially be this correct: public function query($query){ return $this-DBconnect->query($query); } Would there some how be a way to tie in the mysqli connection class into the DBConnection class? Or would that not solve the issue here? /*Include errors for mysqli connections*/ class mysqli_errordisplay extends mysqli { public function __construct($host, $user, $pass, $db) { parent::__construct($host, $user, $pass, $db); if (mysqli_connect_error()) { die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } } }
  13. Now I'm getting: Fatal error: Call to undefined method DBConnection::query() /*Connect to DB*/ $LoginDB = new DBConnection; $LoginDB->connect('mysqli', 'persist', 'db418598519'); /*Encode - Sanitize user input for query*/ $sanitized_email = $LoginDB->mysqli_sanitize($login_username); $encoded_password = md5s($login_password); /*run query*/ $result = $LoginDB->query("SELECT * FROM user WHERE email_address='$sanitized_email' AND password='$encoded_password'"); $num_rows = $result->num_rows; $rows = $result->fetch_assoc(); class DBConnection { private $DBconnect; public function connect($mysqlipdo, $persistcoe, $dbname, $user = 'dbo418598519'){ if($mysqlipdo=="pdo" && $persistcoe=="persist"){ $this->DBconnect = new SafePDO_errordisplay("mysql:host=db.1and1.com;dbname=$dbname", $user, "pass", array(PDO::ATTR_PERSISTENT => true)); } elseif($mysqlipdo=="pdo" && $persistcoe=="coe"){ $this->DBconnect = new SafePDO_errordisplay("mysql:host=db.1and1.com;dbname=$dbname", $user, "pass"); } elseif($mysqlipdo=="mysqli" && $persistcoe=="persist"){ $this->DBconnect = new mysqli_errordisplay('p:db.1and1.com', $user, "pass", $dbname); } elseif($mysqlipdo=="mysqli" && $persistcoe=="coe"){ $this->DBconnect = new mysqli_errordisplay('db.1and1.com', $user, "pass", $dbname); } else{ } return $this->DBconnect; } public function mysqli_sanitize($formValue){ if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { $this->formValue = stripslashes($formValue); } $formValue = $this->DBconnect->real_escape_string($formValue); return $this->formValue; } }
  14. I'm also looking to convert the mysqli_sanitize to a class as well: class mysqli_escape extends DBConnection{ public function mysqli_sanitize($formValue){ if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { $this->formValue = stripslashes($formValue); } $formValue = $this->real_escape_string($formValue); return $this->formValue; } } With that, the error is now: Fatal error: Call to undefined method DBConnection::MySQLi_sanitize() /*Connect to DB*/ $LoginDB = new DBConnection('mysqli', 'persist', 'db418598519'); $LoginDB->connect(); /*Encode - Sanitize user input for query*/ $sanitized_email = $LoginDB->mysqli_sanitize($login_username);
  15. Alright, I changed it to this: class DBConnection{ public function __construct($mysqlipdo, $persistcoe, $dbname, $user = 'dbo418598519'){ if($mysqlipdo=="pdo" && $persistcoe=="persist"){ $this->DBconnect = new SafePDO_errordisplay("mysql:host=db.1and1.com;dbname=$dbname", $user, "pass", array(PDO::ATTR_PERSISTENT => true)); } elseif($mysqlipdo=="pdo" && $persistcoe=="coe"){ $this->DBconnect = new SafePDO_errordisplay("mysql:host=db.1and1.com;dbname=$dbname", $user, "pass"); } elseif($mysqlipdo=="mysqli" && $persistcoe=="persist"){ $this->DBconnect = new mysqli_errordisplay('p:db.1and1.com', $user, "pass", $dbname); } elseif($mysqlipdo=="mysqli" && $persistcoe=="coe"){ $this->DBconnect = new mysqli_errordisplay('db.1and1.com', $user, "pass", $dbname); } else{ } } public function connect(){ return $this->DBconnect; } } $LoginDB = new DBConnection('mysqli', 'persist', 'db418598519'); $LoginDB->connect(); Still same problem. And I'm not using the real_escape_string with pdo. I'm calling a MySQL persistent connection through the DBConnection class.
  16. I'm trying to condense all of my connection functions down into one class, to make the whole process easier. Instead having to remember the names of 4 functions; I just have to remember one class and the attributes used in the class. I'm running in to a problem though. /*Connect to DB*/ $LoginDB = new DBConnection('mysqli', 'persist', 'db418598519'); /*Encode - Sanitize user input for query*/ $sanitized_email = MySQLi_sanitize($LoginDB, $login_username); This code is generating: Fatal error: Call to undefined method DBConnection::real_escape_string() The class: class DBConnection{ public function __construct($mysqlipdo, $persistcoe, $dbname, $user = "username"){ if($mysqlipdo=="pdo" && $persistcoe=="persist"){ $DBconnect = new SafePDO_errordisplay("mysql:host=db.1and1.com;dbname=$dbname", $user, "pass", array(PDO::ATTR_PERSISTENT => true)); } elseif($mysqlipdo=="pdo" && $persistcoe=="coe"){ $DBconnect = new SafePDO_errordisplay("mysql:host=db.1and1.com;dbname=$dbname", $user, "pass"); } elseif($mysqlipdo=="mysqli" && $persistcoe=="persist"){ $DBconnect = new mysqli_errordisplay('p:db.1and1.com', $user, "pass", $dbname); } elseif($mysqlipdo=="mysqli" && $persistcoe=="coe"){ $DBconnect = new mysqli_errordisplay('db.1and1.com', $user, "pass", $dbname); } else{ } return $DBconnect; } } function /*Sanitize user input for MySQLi connections*/ function mysqli_sanitize($conn,$formValue){ if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { $formValue = stripslashes($formValue); } $formValue = $conn->real_escape_string($formValue); return $formValue; }
  17. Guess they have back-up/duplicate servers?
  18. Some what off topic, but is anybody else having issues loading php.net?
  19. Solved with this. function make_ascii($word) { $arr = str_split($word); foreach ( $arr as &$c ) { $c = '&#'.ord($c).';'; } return implode($arr); } function replace_word($string){ $words = array(); foreach ($words as $word) { $string = preg_replace('/\b'.preg_quote($word).'\b/ie', "make_ascii('\\0')", $string); } return $string; }
  20. Still not having any luck. I could generate the array with each capitalization manually, but I'm looking at an array with nearly 300 values in it then.
  21. Well I came up with this preg_match... I just have no idea where to put it, or what to run in the If statement. if(preg_match_all("/\b$words[$i]\b/i", $string)){ } That would only work of course, if it's inside the for loop.
  22. I had thought the same thing, but that returns "Test" no matter what the initial capitalization. Also test2 is processed as test, so the ASCII code ends up looking like this: This is a &#84;&#101;&#115;&#116; and this is &#84;&#101;&#115;&#116;2 and this is &#84;&#101;&#115;&#116;. (This form software converts ampersands into & #38; so that's what those are in the php box.)
  23. I modified it a bit. It works, but not quite how I want it to. <?php error_reporting(E_ALL); function replace_word($string){ $words = array('Test', 'test2'); for ($i=0;$i < count($words);$i++){ $ascii = ''; $index = 0; while($index < strlen($words[$i])) { $ascii .= "&#".ord($words[$i][$index]).";"; $index++; } $string=str_replace($words[$i], $ascii, $string); } return $string; } $text="This is a Test and this is test2 and this is test."; echo replace_word($text); ?> It does replace "Test" and "test2" but I also want it to replace "test". It should be a case insensitive search, but a case sensitive ASCII code generation. So if "Test" and "test" are found in the string it should replace both, but they should be replaced with the ASCII that would generate "Test" and "test" respectively. It should also find TeSt, tEsT, TesT, tEST, etc. and replace with the ASCII to recreate those capitalizations. I could manually put in every single possible capitalization of the words, but that would be a nightmare to make sure I don't miss anything.
  24. Alright, I came up with the following; but it's returning a blank page. <?php error_reporting(E_ALL); function replace_word($string){ $text=""; $words = array('TEst', 'Test2'); foreach($words as $word){ if(stristr($string, $word) === TRUE) { $ascii = ''; $index = 0; while($index < strlen($word)) { $ascii .= "&#".ord($word[$index]).";"; $index++; } $text=str_replace($word, $ascii, $string); } } return $text; } $text="This is a test."; echo replace_word($text); ?>
  25. I really can't figure out how to set-up the conditionals in this situation. The function should take the the string, look through it and if it founds a matching word in the string to the words in the array list, replace it. The search should be case-insensitive, but the output of ASCII code should match the original input case on all letters. I'm not sure where to properly put the if statement or how/what I should be using to do the matching. I was figuring preg_match, but I have no idea how to use that with an array. EDIT: Maybe a foreach to iterate over the array, with a preg_match matching any full word (if that's possible); then returning a true or false if a match is found, then wrap the second foreach in an if statement checking to see if the value is true? <?php error_reporting(E_ALL); function replace_word($string){ $words = array('Test', 'Test2'); foreach($words as $word){ if($word==$string){ $ascii = ''; $index = 0; while($index < strlen($word)) { $ascii .= "&#".ord($word[$index]).";"; $index++; } echo $ascii . '<br />'; } } return $string; } $text="This is a test."; echo replace_word($text); ?> The expect output should be "This is a (ASCII code for the word "test").".
×
×
  • 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.