Jump to content

chronister

Members
  • Posts

    1,438
  • Joined

  • Last visited

Everything posted by chronister

  1. Here is a link to a post with a function that I have posted on here / linked to many many times.. http://www.phpfreaks.com/forums/index.php/topic,234125.msg1087354.html#msg1087354 will do exactly what you want I think.
  2. Well, this has nothing to do with PHP... this is the PHP Help board...... But the image next to it is 124x35 and this image is 128x35. Dunno if that extra 4 pixels would do it, but it may.
  3. I have a few questions regarding sessions. I have used them many many many times and have had no problems with them. I am now trying to move my sessions to a database by resetting the save handler using the following code (this is only the class construct).... <?php function sessionManager() { $this->db = new dbConn('test', 0); // instantiate a new db class object $this->life_time = get_cfg_var("session.gc_maxlifetime"); // get current lifetime session_set_save_handler( // start custom session save handler array(&$this, "open"), array(&$this, "close"), array(&$this, "read"), array(&$this, "write"), array(&$this, "destroy"), array(&$this, "gc") ); } // the open, close, read, write, destroy, and gc(garbage collection) methods have been truncated. ?> So my question is 2 fold here. 1. When using this method, should there be session files on the server? When I look in my tmp directory that sessions are stored in, there are session files being created cooresponding to the session id that is created in the db. I was under the impression that session files would not be used when the database is being used. 2. I have tested that this is indeed writing sessions to the database, however in a login script that I have when the session vars are set (right before a header redirect) they are not being written to the database. I have tried session_commit(); session_write_close(); and they are not working.... Why would this be happening?? I have verified that the above script is in place, and is instantiated before my session_start() is called and that the sessionManager object is instantiated at the time I am trying to save session data. Here is the relevant login script code. <?php $result = $db->getData("SELECT * FROM users WHERE username='$userName' && password='$password'"); if($result['numRows'] > 0){ while($row = mysql_fetch_object($result['result'])){ $firstName = $row->firstName; $userId = $row->userId; } /* NONE OF THE FOLLOWING SESSION VARS ARE BEING SAVED */ $_SESSION['loggedIn'] = 1; $_SESSION['userName'] = $firstName; $_SESSION['userId'] = $userId; $_SESSION['allowEdit'] = 1; header('Location:index.php'); ?> Any help is appreciated. Thanks, Nate
  4. I am not 100% sure this will take care of it.... but I would start with valid HTML ....... echo '<SELECT name="testname">'; foreach ($showtest as $key => $value) { echo '<OPTION value="' . $value . '"> ' . $value . ''; } echo '</select>'; ?>< ........... I believe that attribute values in HTML are supposed to have quotes around them. I don't think it matters whether it is single or double quotes.... just put quotes around and I believe that it will fix it. Nate
  5. I am assuming that through this whole transaction, your doing it over an encrypted connection (https://yoursite.com/blah).... if the url starts with http and not https, then stop right now and get an SSL certificate and get the encrypted connection set first. there are a couple of things you can do to pass information securely. the most obvious one is to use sessions. If your in a shared hosting environment, then this may not be the best thing as a compromised host in the shared environment can mean your site is compromised too. The other way would be to use a database. You may even be able to use a temporary table in this instance so that the table exists for the duration of the transaction, but is not a permanent object that can be accessed. I am not too familiar with temp tables, so you might want to read up on them as far as security and such. If you use a db of any sort, then you are going to want to use a 2 way encryption model so that the data is stored encrypted and you can pull it back out and use it decrypted. I am not too familiar with 2 way encryption either, so check on that. Those are where I would start looking. There may be other suggestions, but this is where I would start. Nate
  6. You would take the code in process.php that handles this form submission, and place it where it says echo 'Form Submitted.... Add your processing code here<br />';... just replace everything inside the { } Nate
  7. <?php if(isset($_POST['SUBSCRIBE'])){ echo 'Form Submitted.... Add your processing code here<br />'; echo '<pre>'; print_r($_POST); echo '</pre>'; }else{ echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">'; echo "<Table width=80%> <TR> <TD width=15%>Name:</TD> <TD width=80%><input type='text' name='name' style='font-size:12px'></TD> </TR> <TR> <TD width=15%>Email:</TD> <TD width=80%><input type='text' name='email' style='font-size:12px'></TD> </TR> <TR> <TD width=15%><input type=hidden name=group value='$group'><BR><BR></TD> <TD width=80%><input NAME="SUBSCRIBE" type='submit' value='Subscribe' style='font-size:12px'></TD> </TR> </Table> </form>"; } ?> Make sure your HTML is proper. Surround your attributes with quotes, and give all your form elements a name. This is the basis for making a 1 page form / form processing page. Nate
  8. Take a look at this topic. I posted in it regarding a "template" type layout. http://www.phpfreaks.com/forums/index.php/topic,230941.msg1070233.html#msg1070233 I have 1 page that is my layout page. It includes all my head information (e.g. css, js ), my header, navigation, and my footer. I then call that page inside each page of my site to "wrap" around my content and have a nice "template" type of layout. When I want to change anything such as header, navigation footer etc, I do it on 1 page only. Works well. I like it and I use it every site I build anymore. *note*, I saw an error in my post. I called the container page index.php, but I actually call it header.php
  9. <?php if(isset($_POST['NameOfSubmitButton'])){ // form has been submitted .... process the form now. }else{ // show form here... it has not been submitted echo '<form name="formName" action="'.$_SERVER['PHP_SELF'].'" method="post">'; // rest of form here } ?> This is basically how you would want to do it. Nate
  10. For testing purposes. I am finally delving into the world of OOP, and writing some classes. I understand that PHP5 offers much better OOP, however on one particular project I am working on I am writing it so that it can be used on PHP4 and PHP5 so I would like to test it on both locally with a single line change to the .htaccess file like 1&1 offers. I can switch between them in the time it takes me to add or delete that line. I know that PHP5 is the direction to go as it is finally being adopted "widespread", but I wish to have PHP4 and PHP5 together. It is also a learning experiment. I want to see if I can learn more about the intricate dance Apache & PHP do together. I may grab an extra hard drive I have and install an OS, and use that to play around with. I don't want to use my current *working* test box to experiment with as it is running a site my wife uses daily that I built for her that has address book, recipes db, movies db, library tracking db etc... I know it is an odd request, but I think it could be a neat (read geeky) learning experience. Nate
  11. Hello All, On my webhost (1&1 ) I can switch from php4 to php5 by adding this line to a .htaccess file. AddType x-mapp-php5 .php I am attempting to do this on my local development machine as well. I have searched google, and PHPFreaks and have not found any assistance in doing this.. The closest I got was an article to run PHP5 on a sub-dir, which I don't want. I actually want to run PHP5 by default and php4 using a .htaccess directive like above. Has anyone done this type of thing? I currently have PHP5 and Apache2.2 running without issue. Any help you folks can provide would be most appreciated. Thanks, nate
  12. Ahh.. CV was a little quicker than me. <?php $allowedTypes = array('image/gif', 'image/jpeg', 'image/png'); if(in_array($fileType, $allowedTypes)){ //upload file }else{ // give error stating this type is not allowed. } ?> nate
  13. echo '<form name="form1" method="post" action="login.php"> <input type="text" name="username" id="username"> <input type="text" name="password" id="password"> <input type="submit" name="submit" id="submit" value="Login"> </form>';
  14. <?php if(isset($_SESSION['loggedIn'])) { // show relevant information }else{ // show login form } ?>
  15. My first suggestion, would be to get rid of the javascript in the buttons. There is nothing more annoying than having a form use javascript to trigger the submit and not work because javascript is off. I feel very strongly about not relying on client side scripting to do core functionality of the form. Yes, most people have javascript turned on, but some don't. I disable it sometimes. So if a person has it turned off, purposely or unknowingly, then your form does not work any longer. On to your question... Your form elements are missing name attributes, which are needed to receive the variables on the processing side. For each item in your form, you should have a piece like this to receive the data. $name = $_POST['name']; $state = $_POST['state']; etc.... The processing code you have looks pretty standard. I suggest you learn what it is doing and apply that to your situation. In PHP, form processing is one of the most common tasks. You should learn valid HTML, and ensure that your HTML form elements have all the attributes you need. The PHP, is pretty standard... here is explanation of what your processing script is doing. <?php //Some variables /* SET ALL THE FORM FIELDS IN EASY TO USE VARIABLES SO THEY CAN BE REFERENCED BY EASY NAMES ADD OR REMOVE ANY FIELDS YOU NEED TO .... INSIDE THE $_POST[] IS THE NAME OF YOUR FIELD. */ $mymail = "info@myemail.com"; $ename = $_POST['ename']; $eemail = $_POST['eemail']; $esubject = $_POST['esubject']; $emessage = $_POST['emessage']; $eip = $_POST['eip']; //Function to check email address /* THIS CHECKS THE EMAIL ADDRESS TO ENSURE IT IS VALID. YOU PASS AN EMAIL ADDRESS INTO IT BELOW */ function checkemail($eemail) { if(eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$",$eemail)) { return true; } else { return false; } } //Mail Processing if ($_POST['esubmit']) { //Check for blank fields /* THIS IS A CHECK TO MAKE SURE NO FIELDS ARE BLANK. THE || MEANS OR...... IF ENAME EQUALS BLANK OR EEMAIL EQUALS BLANK OR ....ETC.. ADD OR REMOVE THE CORRECT VARIABLES THAT WERE SET ABOVE */ if ($ename == "" || $eemail == "" || $esubject == "" || $emessage == "") { echo "<p>It appears that you left a blank field.<br/> Please make sure you fill everything in.</p>"; } //Check to see if the email address is valid /* PART OF THE IF STATEMENT ABOVE. THIS IS WHERE YOU WOULD PASS YOUR EMAIL VARIABLE YOU SET ABOVE TO CHECK IF IT IS VALID */ else if (checkemail($eemail) == false) { echo "<p>It appears that you enter an invalid email address.<br/> Please check your email again.</p>"; } //Send the email if there's no error /* IF YOU GET TO THIS POINT, THE FIELDS ARE NOT EMPTY AND THE EMAIL IS CORRECT FORMAT... SEND MAIL.*/ else { $body = "$emessage\n\nName: $ename\nEmail: $eemail\nIp: $eip"; mail($mymail,$esubject,$body,"From: $eemail\n"); echo "<p>Thank you for your email $ename!</p>"; } } ?> This is an overview of the script. I suggest you study what it is doing and learn the concepts of how it is doing it. Check out the php manual at http://www.php.net/manual/en/funcref.php to see what things do. You will be worlds ahead if you learn how to do this stuff yourself rather than trying to "hack" together scripts. Sorry if this is not what your looking for, but hope it helps. Nate
  16. I am marking this solved even though it is not. I am going to struggle on my own with this as it seems no one can help me with this, or no one wants to attempt to help me with this. Very frustrating when I offer lots of help on this forum, and when I request some help I very rarely get it. Nate
  17. I have determined that there was nothing wrong with my particular function, it was just hitting items (radio buttons and checkboxes) that could not be validated in that manner and then kicking in the return value forcing my form to submit. So now I need to figure out what type of form object the current item is, so I can validate it properly. As is stated, this is a dynamically created form so I have no way of knowing before hand what type of form object is being checked without adding additional items in my validation rules, and I don't want to do that because it is mostly un-necessary. So I have figured out that I can use the .type object to determine the type of some form elements, but when it comes to radio buttons, or checkboxes, it does not work. So how do I determine the type of radio or checkbox in the form? Please someone help me on this one. I am getting there, and learning a decent amount about JS in the process Nate
  18. Yeah, anytime you are referencing form values, you want to ensure that the form is actually submitted first. I generally make the errors an array, so I can display them individually, and I make their key the name of the field they apply to. This allows me to apply class styles to a particular form field, and also fill in the fields again so a user does not have to fill them out again. <?php if(isset($_POST['submitButonName'])){ if(empty($_POST['field1']) && empty($_POST['field2'])) { $error = 'Error: Must fill in at least 1 or the other'; }else{ if(!empty($_POST['field1']) && !empty($_POST['field2'])){ error= 'Error: Must not fill out both'; } } } ?>
  19. You can put this code wherever you wish the message to appear. I have looked over it and tested it on my server, what I posted is correct with no syntax errors. I would need to see yours to know what the problem is. Sample.php is not the code referenced in the errror. <?php if(empty($_POST['field1']) && empty($_POST['field2'])) { echo 'Error: Must fill in at least 1 or the other'; }else{ if(!empty($_POST['field1']) && !empty($_POST['field2'])){ echo 'Error: Must not fill out both'; } } ?> Nate
  20. Can anyone help me here?? What triggers the "true" return value? Is it this line? obj.parentNode.className = 'formError'; I am trying to understand what forces the form to submit to the server. I have looked at many tutorials regarding this, and they do it in a very similar way. A more condensed version of what I need is ... how do I take a js array and run it through a for loop and change the parentNode className when there is an error without triggering a "return true" on the validateForm function?? Please assist me. Thanks, Nate
  21. <?php if(empty($_POST['field1']) && empty($_POST['field2'])) { echo 'Error: Must fill in at least 1 or the other'; }else{ if(!empty($_POST['field1']) && !empty($_POST['field2'])){ echo 'Error: Must not fill out both'; }else{ // send now. } } ?> I think this would take care of what you need. It looks to see if they are both blank, or both filled out. If both hit the else statement, then at least 1 has to be filled out. I think my logic is correct on that one. Nate
  22. Here is an AJAX one right here on PHP freaks. Very good too. I used it and modified it to do a few different things. http://www.phpfreaks.com/forums/index.php/topic,155984.0.html
  23. JS is not my strong point, but it looks to me like the page gets refreshed, rather than an AJAX function doing the work. Try using an AJAX function instead of a jump type menu. Nate
  24. Hello, I am attempting to do some functional JS scripting. I am not real good with JS, so I am struggling here. I have a PHP form class that dynamically creates the form and then does all the processing. I am trying to add JS validation as an option. The JS validation can be flagged on or off when the class is instantiated. Since this is a form with an unknown number of fields, and unknown field names I have taken this approach.... My form class uses a validation array to create server side validation rules. I pass this into the method that creates the meta information (head data) and loop through it to create a JS array of fields that require validation. I end up with this.... <script> var required = new Array(); required[0]="telephone"; required[1]="email"; required[2]="hiddenElement"; required[3]="passwordField"; required[4]="coolApp"; required[5]="boxes"; required[6]="person"; required[7]="month"; required[8]="state"; required[9]="theTextArea"; required[10]="singleCheck"; required[11]="uploadFile"; </script> Then it creates a line that gets added into the form start tag, which passes the required js array into it. onSubmit="return validateForm(this, required)" The function I am trying go create to do this should check to see if the field is empty (I have 2 functions to mimic PHP's functions empty() and trim() ) and if it is empty, it should change the class name of the parent object. My form is set up like so.... <li> <label>The Label</label> <input name="input" id="input" type="text" /> </li> The li tag is what gets changed, this highlights the whole block to denote an error in that field. here is the functions I am attempting to use. function checkEmpty(obj) { var error=false; if(empty(trim(obj.value))) { obj.parentNode.className = 'formError'; error=true; }else{ obj.parentNode.className = ''; } return error; } function validateForm(obj, requiredFields) { var errors=""; for($i=0; $i < requiredFields.length; $i++){ var theField=document.getElementById(requiredFields[$i]); errors = checkEmpty(theField) } return false; } My form still submits and my server side validation kicks in. What am I doing wrong here that is making the validateForm function return true and make the form submit. It seems that there is a problem within the for loop. It seems that this line obj.parentNode.className = 'formError'; is causing the problem. Any help would be appreciated. Thanks, Nate
  25. You can use checkdnsrr for a valid MX record. I use this to validate email addresses. This way at least a person will HAVE to put in a valid domain, even if it is not actually their email address. <?php if(checkdnsrr('yahoo.com' )) { echo 'MX record was found'; } ?> Nate
×
×
  • 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.