Jump to content

davidmyers

Members
  • Posts

    37
  • Joined

  • Last visited

    Never

Everything posted by davidmyers

  1. Well the fact that you've already thought about it and taken it into consideration when doing things is a huge step forward. Keep up the good work.
  2. This looks really good. It'd be interesting to see what all has gone into the framework, but it works great from what I saw. I wish I was this far along when I was still in high school, haha. My only question would be if you've thought much about scalability. Just because you're making a social network to be better than facebook and if you're really serious about this you'll have to consider scaling at some point. Another reason to consider it is because the site may be running great now, but what about when it has 100,000 users or 1 million and so on. It can seem to far off to worry, but to prepare for scalability as far as databases goes completely changes the database design and functionality.
  3. Yeah, or include it in an external JS file. Also, make sure you call it inside of: It's just a jQuery thing to make sure it doesn't try to run before the page is finished loading.
  4. Ok, so I found a solution to my problem. Here is the code that I've ended up with: function SetValue() // Used to set values in current object { if(func_num_args() != 0) // Check for arguments { $Arguments = func_get_args(); // Get arguments $Variable = $Arguments[0]; // Set variable if(is_array($Variable)) // Check if first argument is an array of multiple variables to be set { $ObjVars = get_object_vars($this); // Grab associative array of Class variables foreach($Variable as $key => $value) // Loop through argument array { if(array_key_exists($key, $ObjVars)) // Check if argument array key is valid class variable { $this->$key = $value; // Set object variable with new value } else { // Send error return "error"; } } } else // Argument isn't an array so we're only setting one variable { $Value = $Arguments[1]; // Set variable $ObjVars = get_object_vars($this); // Grab associative array of Class variables $Variable = strtolower($Variable); // Convert argument of variable name to lowercase if(array_key_exists($Variable, $ObjVars)) // Check to see if argument is valid class variable { $ObjVars[$Variable] = $Value; // Update array with new variable value foreach($ObjVars as $key => $value) // Loop through array of variables { $this->$key = $value; // Set object variable with new value } } else // Not a valid class variable { // Send error return "error"; } } } else { // Send error return "error"; } } I know this topic was up for less than 24 hours, but it seems like every time I post a question I get almost no responses and no one ever gives me a solution. Either I'm not doing something right when I ask for help, or I guess there isn't much help to be had for more advanced issues? It's kind of frustrating because instead of getting the help I'm seeking I end up just getting answers that are irrelevant and solving the problem myself eventually. Sorry for the rant. In any event, here is the code for a completely dynamic Class Setter function that will either accept a variable and value or an associative array of variables and values. EDIT: I forgot two $'s in the code above.
  5. This is the kind of jQuery AJAX call you're going to want: var data = "&settingone=1&settingtwo=2"; $.ajax({ url: "index.php?option=dothis", type: "POST", data: data, success: function(string, variable){ if(variable === "success"){ alert(string); } else{ alert(string); } } }); It's a fairly straightforward piece of code. Data is anything you want to POST (or GET if you change type: to equal GET) to the Url. The function returns a string and a variable. The variable tells whether or not the AJAX call was successful or not and the string is whatever the Url returned. On it's own this will continuously make AJAX calls to that page.
  6. Ok, so I tried the .htaccess option first since it's the easiest but it didn't do anything. I'd try the first solution but I don't know where that file is. Ideally I'd like a solution that doesn't involve changing settings in PHP that have been deprecated for a reason. I realize that the way I initially tried to get this to work was the wrong way, but I can't think of any other way and that's really where I'd like help.
  7. I appreciate you trying to help, but I have no idea what you're talking about and that doesn't answer anything.
  8. That syntax is correct, but that doesn't work because get_object_vars is not written to return references. Your solution won't really work for me because it isn't dynamic in the way that I'm wanting. I'm trying to reference class/object variables without explicitly naming them anywhere except in the argument to the function if that makes sense. Also, the GetValue() function I posted works perfectly, it's the SetValue() version of the same code I'm trying to get working.
  9. I feel like I use to have a couple links to sites regarding this, but I can't find them. I do know of this one link though: http://www.developphp.com/view.php?tid=1037&t=Website_Design_Theme_Application_Tutorial_Using_PHP_Cookies_to_Change_CSS This guy uses cookies to store users theme choices and you can't customize them, but it's a good way to see step by step some of the things you'll need to get your own version working. Really though that's gonna be the easy part. Personally I'm a fan of jQuery and it would make the customization form a lot easier to process imo. I've been planning on building a feature similar to this, just with much customization. Mostly only letting users customize colors. But I'm thinking of possibly writing some tutorials in the future. If you'd be interested I could do this one first, just let me know.
  10. If you notice, I had found that out and said as much towards the end of my first post. Also, I'm not attempting to retrieve an object, I'm trying to get references to the variables of an object.
  11. I just realized that you said you were creating a form to add a new template to the site. To do this you would want to have them choose their options (which can be anything definable in css) and then use those to create a new stylesheet for that template using PHP. Then you would use the same kind of system that I already described to fetch the correct template for them whenever they visit a page. If you're setting it up where a site admin would do this but it would affect the entire site for every user, you would just check the "template" column value for the admin and apply that stylesheet every time the page is loaded. Honstly, creating a new template for the site in this way is valuable but will take a lot of work to write, especially if you're trying to make it really customizable. Also just saw your new post and I'm not sure what you would be using the textareas for. If you're including customization for page titles and such then you'll want to store that information in the database and call it like the stylesheet. In fact, if you have a lot of things you want to store about the templates, I'd make a table for template info and then have an entry for every user that specifies all of their options, like page header, css template name, etc.
  12. Ok, this is way different than what I initially thought you were wanting. If I understand this correctly, you want to have different site templates/layouts/themes that users can select to alter what the site looks like for them. First off you'll want to have every template/layout/theme work with the same base HTML, meaning that you have a bunch of div tags making up the page and what the site looks like is completely dependent upon the css applied to it. Then once you have all of your different template/layouts/themes created and working, have a place where the user can select the one they want. You can store their selection in a database either as a number or a name that references the particular template. So for instance a table column named "template" which holds the name of the template they chose. Then at the beginning of every page, just check the current users template variable and call the correct stylesheet accordingly. Hopefully this helps.
  13. I don't think I understand what it is you are trying to do. If you could explain in more detail or include code of what you've got that would help. If you're trying to make a form that is completely dynamic then it's pretty much the same principle of what I've shown you but will include accepting and handling lots of arguments, and will need lots of conditional statements.
  14. As a note, I've also attempted calling the function as a reference: $ObjVars = &get_object_vars($this); On the off chance that get_object_vars would return a reference, this was what I found to be the way to try it.
  15. What kind of errors are you getting? Because it is perfectly logical to put if else statements within loops.
  16. The easiest way to do this is (in my experience so far) to create a function such as this: function NewForm() { echo ' <form id="NewForm" > <div id="Header">Header</div> <div id="FormContent"> Name: <input type="text" id="UserName"> </div> <div id="Footer"> <input type="submit" value="Submit"> </div> </form>'; } That way you can make specific types of forms one time and then re-use them whenever necessary just by calling the function. Of course you'd need code to handle processing the form data and adding it to a database, but this shows you what I think you're looking for.
  17. If you're willing to not customize the message with the recipient's name, ie "Dear, (recipient's name)" you can achieve the same thing but without calling the mail function multiple times. If you use the Pear Mail function it's much more efficient at sending multiple messages. The only real difference in the code would be to include an array of email addresses as an argument as opposed to just one like you do now. If you're interested, I just posted an example of how to do this in another thread similar to this one: http://www.phpfreaks.com/forums/index.php?topic=338197.msg1593938#msg1593938
  18. What kind of template are you referring to? I'm going to assume you're talking about a template for a page, ie storing standard paoge layout/markup to be re-used by calling a function ( or in your case a database query). If that's what you're talking about then it's much much easier to just create a PHP class with functions that echo the different parts of the page/template that you want when you call them.
  19. I don't really know about this particular error, but I do know that I was pretty recently looking at sending multiple emails at once. When checking out the PHP Manual page for mail() it explicitly says that mail() isn't really intended for more than one email at a time since it opens a new smtp socket for each request. Because of this it can take a couple of minutes just to send 20-30 emails. Regardless of the errors you're currently getting, it's really a much better idea to use Pear's Mail function. Luckily Pear is a PHP Module that's usually already installed by most hosts. And it's really simple to use as well. Here's an example of how I used it to send a text message to a user: require_once 'Mail.php'; function SendTXT() { $mail =& Mail::factory("mail"); // Define $mail as the Pear Mail function $CarrierArray = array('@txt.att.net', '@vtext.com', '@tmomail.net', '@messaging.sprintpcs.com', '@message.alltel.com', '@psms.bluesky.as', '@myboostmobile.com', '@cellcom.quiktxt.com', '@mobile.celloneusa.com', '@csouth1.com', '@cwemail.com', '@sms.cvalley.net', '@gocbw.com', '@cingular.com', '@cingulartext.com', '@sms.cleartalk.us', '@sms.mycricket.com', '@echoemail.net', '@mobile.gci.net', '@msg.globalstarusa.com', '@gscsms.com', '@myhelio.com', '@mobile.kajeet.net', '@mymetropcs.com', '@messaging.nextel.com', '@api.panaceamobile.com', '@zsend.com', '@sms.pocket.com', '@qwestmp.com', '@rinasms.com', '@mmst5.tracfone.com', '@email.uscc.net', '@utext.com', '@viaerosms.com', '@vmobl.com'); // Set CarrierArray with all possible carrier options so user receives txt regardless of carrier $GetNumber = mysql_query("SELECT Object FROM $Database->tbl_Users WHERE id = '$this->Recipient'"); $TempObject = mysql_result($GetNumber, 0, "Object"); $TempObject = unserialize($TempObject); $Permission = $TempObject->GetValue(TextPermission); $Number = $TempObject->GetValue(CellPhone); $NumberArray = array(); $headers = array("From"=>"Website Name <notifications@randomaddress.com>"); if($Permission != 1) { return "This user does not allow text messages."; } if($Number == "") { return "Error, User does not have cell phone number and cannot receive texts."; } $Length = count($CarrierArray); // Find number of message recipients for($x = 0; $x < $Length; $x++) // Loop through recipients { $NumberArray[$x] = $Number . $CarrierArray[$x]; // Create email address using cell number plus carrier info echo $NumberArray[$x] . "<br>"; // Display current email address } $mail->send($NumberArray, $headers, $this->Message); // Send message to multiple recipients. } The Pear mail function gives you the ability to send your message/email to an array full of addresses. Assuming that you don't need to customize the message per user, then this should be a great solution for you.
  20. After doing a quick search it looks like if you run a linux server you're going to have to install a library of some sort to accomplish what you want. But if you run a windows server there are some built-in PHP functions that you can use. Here's the best link I found: http://stackoverflow.com/questions/757675/website-screenshots-using-php The first answer talks about using libraries and the second answer talks about using the windows functions and give great examples of how to use them.
  21. In the past for my getter and setter functions I've always just used a switch statement with a case for each class variable. However, I decided to re-write them to be more dynamic because those switch statements can get really really long and also I would have to change them anytime I made a change to the class variables, ie adding or removing any. So this is what I came up with for the getter function: function GetValue($Variable) { $ObjVars = get_object_vars($this); // Grab associative array of Class Variables $Variable = strtolower($Variable); // Convert argument of variable name to lowercase if(array_key_exists($Variable, $ObjVars)) // Check to see if argument is valid class variable { return $ObjVars[$Variable]; // Return value of requested variable } else { $Error = new Error("You must supply a valid variable to User->GetValue()", $_SESSION['CurrentUser']->GetValue(ID), 'User', $_SESSION['CurrentPage'], 'PHP', 'Medium'); $Error->Log(); $Error->Display(); return "error"; } } Obviously though this solution doesn't exactly work for a setter function since changing the value of a variable in $ObjVars won't have any effect on the actual class/object variable. The idea I had was if I could pass $this as a reference to get_object_vars then it would give me references to the variables and by changing the values in $ObjVars I would in change the actual class/object variables. So I tried: $ObjVars = get_object_vars(&$this); But got this error: "Call-time pass-by-reference has been deprecated" Upon researching this I realized it was because you don't pass references in this way in PHP. As far as I can tell, unless a function is written to return it's value as a reference, there really isn't a way to make it do so. So short of writing my own function to emulate get_object_vars and have it return references, is there another way to solve this? I feel like if this can't be done how I'm currently trying, that means there's a better way to do it. I just haven't figured it out yet. So any and all help or suggestions are greatly appreciated.
  22. So I've found a solution to my problems on my own. Firstly, I've decided to make a compromise on the object model/database storage solution. For the user system, I'm going to have columns for UserID, Username, PassHash, and Object. This way I keep the advantages of storing all of the objects I create but I can utilize MySQL in the areas that it's best, like searching the database for login confirmation. I also figured out the issues I was having with foreach(). foreach() is supposed to automatically loop through an array according to the PHP manual description. But for some reason it wasn't looping. It would only run once, regardless of what variables I changed. I've changed the code and logic to work with a for loop and the class now works perfectly. This is the for loop that has replaced the foreach() logic in the User class: for($x = 0; $x < $QueryRowCount; $x++) { $Temp = mysql_fetch_assoc($LoginQuery); $TempObject = unserialize($Temp[Object]); $TempUser = $TempObject->GetValue(Username); $TempPass = $TempObject->GetValue(PassHash); if($TempUser == $NewUsername && $TempPass == $NewMD5Hash) { $Success = 1; break; } }
  23. I was working under the assumption that doing things using this object model would increase overall speed. I really only grab all of the database entries in a couple of places and so far haven't seen a performance hit, however I haven't had a chance to see it scale yet. In most cases I'm able to just grab a specific object and instantly have all of the information I need. Doing things this way has dramatically decreased the amount of code that I have because I'm not constantly having to do many database queries and set tons of individual variables. Another thing, when using an object class model, it defies logic to continually break up and recreate objects every time you need to store or retrieve the information. You're essentially wasting all of your time destroying and then re-creating the same objects over and over again when you can instead just store the objects and instantly store and retrieve any changes. I do understand what you're saying, but I'm just not sure that you're correct about the performance. I was initially planning on doing some benchmarking to see what kind of a difference I would experience, but in the end decided that I didn't need to take the time as I was sure it would be an improvement. Perhaps I'll need to do that now. Could you please explain to me why it's not looping in my login function? foreach() is supposed to loop through an array, but apparently it's not? Thanks again for the help.
  24. PS: I apologize ahead of time for the lack of comments
  25. For convenience and efficiency purposes I'm changing my MySQL database to store PHP Objects as opposed to tons of individuals variables. In converting the user/login system I've come across a really weird problem. I can register a new user to the site, but only the first one in the database will work. I can register others and they get put in the database correctly, but for some reason the app doesn't see them or even recognize that they exist. Only the first entry in the database will work as it's supposed to. For instance, if I drop the first database entry, the second one (now first) will begin to work. In most cases, I'm pulling all Object entries from the database and looping through them with foreach() to find the specific one I want. I've just come off of an 8 hour coding spree and my brain is just shot at the moment. I really think I just need a new pair of eyes. I'm sure that it's something simple, but I can't see it atm. I'm attaching the User class file which handles login, registration, and anything that I think would be affecting this. Thanks for the help. [attachment deleted by admin]
×
×
  • 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.