Jump to content

jamesjmann

Members
  • Posts

    247
  • Joined

  • Last visited

Everything posted by jamesjmann

  1. I have a script that uses two functions and a simple switch statement. If I wanted to take the value of variables from function 1 and use them in function 2, would I have to declare them global in both functions, function 1, function 2, or outside the functions? For example <?php function function_1() { //Here? global $variable_1; $variable_1 = hello world; return $variable_1 } function function_2() { //Or Here? global $variable_1; echo $variable_1 } //Or here? global $variable_1 //Or in all three places? I want the variable to be available everywhere in the script! ?>
  2. That's extremely complicated...how do you know this?
  3. <?php //**************************************** //***************Includes***************** //**************************************** //Connects to database include "connect.php"; //Selects database include "select.php"; //**************************************** //****************Action****************** //**************************************** switch ($_GET["action"]) { default: case "index": if (!$_SESSION["member"]) { if (!$timeout) { display_form(); } else { echo $timeout_error; } } else { echo "You are already logged in."; } break; case "process": if (!$_SESSION["member"]) { if (!$timeout) { process_form(); } else { echo $timeout_error; } } else { echo "You are already logged in."; } break; } //**************************************** //***************Functions**************** //**************************************** //........................................ //........Function 1: display_form()...... //........................................ function display_form() { global $mysql_connect; echo " <form name=\"login_form\" action=\"?action=process\" method=\"post\">"; if ($rm_field_un || $rm_field_pw) { echo $rm_errors_msg; } echo "<label for="username">Username: </label> <input type=\"text\" name=\"username\" id=\"username\" value=\"$rm_username\"> <label for=\"password\">Password: </label> <input type=\"password\" name=\"password\" id=\"password\"> <a href=\"../fans/forgot_password.php\">Forgot Password?</a> <input type=\"check\" name=\"rememberme_check\" id=\"rememberme_check\" CHECKED> <label for=\"rememberme_check\">Remember me for: </label> <input type=\"text\" name=\"rememberme_days\" id=\"rememberme_days\" value=\"$rememberme_days\"> days <input type=\"hidden\" name=\"ip\" id=\"ip\" value=\""; echo $_SERVER["REMOTE_ADDR"]; echo "\">"; <input type=\"hidden\" name=\"date\" id=\"date\" value=\""; echo date('F d, Y'); echo "\">; <input type=\"hidden\" name=\"time\" id=\"time\" value=\""; echo date('g:I:sa'); echo "\">"; echo "<input type=\"submit\" name=\"submit\" id=\"submit\"> <input type=\"reset\" name=\"reset\" id=\"reset\"> "; } //........................................ //........Function 2: process_form()...... //........................................ function process_form() { global $mysql_connect; //,,,,,,,,,,,,,,,,,,,,,,,,,,,,, //,,,,,,,,,Validation,,,,,,,,,, //,,,,,,,,,,,,,,,,,,,,,,,,,,,,, //When user has failed to login 5 times, a cookie will be created that won't allow them to login until the cookie has expired //In this case, it's 24 hours if ($_SESSION["max_tries"] == 5) { setcookie ("timeout", "timeout", time() + 86400, ".djsmiley.net"); } //While the cookie exists, their timeout exists while ($_COOKIE["timeout"]) { timeout = true; } //Check database to see if both username and password are correct $rm_cl_sql = "SELECT * FROM fans WHERE username = '$rm_username' and password = '$rm_password'"; $rm_cl_result = mysql_query($rm_cl_sql); $rm_cl_count = mysql_num_rows($rm_cl_result); //If username and password do not match... if (!$rm_cl_count) { $rm_errors_found = true; $rm_field_un = true; $rm_field_pw = true; } else { $rm_errors_none = true; $rm_field_un = false; $rm_field_pw = false; } //,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, //,,,,,,,,,,,,,,Variables,,,,,,,,,,,,,,,,, //,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, //----------------------------------------- //--------------Form Elements-------------- //----------------------------------------- //Username and password sent from form $rm_username = mysql_real_escape_string ($_POST["username"]); $rm_password = mysql_real_escape_string ($_POST["password"]); //IP address (records IP the member used last) $rm_ip = $_POST["ip"]; //Submit Button $rm_submit = $_POST["submit"]; //Time Stamp $rm_time = $_POST["time"]; $rm_date = $_POST["date"]; //-------------------------------------------- //---------------Error Trapping--------------- //-------------------------------------------- $rm_errors_found = false; $rm_errors_none = false; $rm_errors_msg = "The username or password you entered is invalid. You have <strong>$tries_left</strong> tries left." //---------------------------------------------- //----------------Invalid Fields---------------- //---------------------------------------------- //Username $rm_field_un = false; //Password $rm_field_pw = false; //---------------------------------------------- //----------------Miscellaneous----------------- //---------------------------------------------- //Timeout $_SESSION["max_tries"] = 0; $tries_left = 5 - $_SESSION["max_tries"]; $timeout_error = "You have reached the maximum number of login tries. Please wait 24 hours before trying again."; //Remember Me $rememberme_check = $_POST["rememberme_check"]; $rememberme_days = $_POST["rememberme_days"]; //Days To Seconds $rememberme_seconds = (($rememberme_days * 24) * 60) * 60); //,,,,,,,,,,,,,,,,,,,,,,,,,,,,, //,,,,,,,,,,,Action,,,,,,,,,,,, //,,,,,,,,,,,,,,,,,,,,,,,,,,,,, //If one or more errors have been found if ($rm_errors_found) { //Add 1 to max_tries $_SESSION["max_tries"] += 1; //Check to see if timeout is true/will only be true if this is the user's 5th try. if ($timeout) { echo $timeout_error; //If timeout is false, it'll check which fields contain invalid information, and decide which errors //exist. It'll then display the login form with error messages displayed } else { display_form(); } //If all of the information the user entered is correct... } else { //Display "Welcome" message echo "Welcome, $rm_username. You are now logged in."; //Insert timestamp into database mysql_query(UPDATE fans SET last_visited_time = $rm_time WHERE username = $rm_username); mysql_query(UPDATE fans SET last_visited_date = $rm_date WHERE username = $rm_username); //Update member's ip address $mysql_query(UPDATE fans SET last_ip = $rm_ip WHERE username = $rm_username); //Insert user into "online" table mysql_query(INSERT INTO fans_online (username) VALUES ('$rm_username'); //Delete user out of "offline" table mysql_query(DELETE FROM fans_offline WHERE username = $rm_username); //Delete user from guest table (assuming their ip address hasn't changed) mysql_query(DELETE FROM fans_guests WHERE ip = $_SESSION["guest"]); //As we are done with all mysql queries, close the connection mysql_close(); //Assign $_POST value of the username they typed into a new $_SESSION variable $_SESSION["member"] = $rm_username; //If they want to be remembered, create cookies that store their information for the number of days they specified. if (isset($rememberme_check)) { setcookie ("username", "$rm_username", $rememberme_seconds, ".djsmiley.net"); setcookie ("password", "$rm_password", $rememberme_seconds, ".djsmiley.net"); } } } ?> Can someone please provide feedback on this script? I've been working on it actively for a whole week. It's rather complicated and has developed quite a bit; it's really confusing to read and understand now. I THINK it's doing what I want it to, but I'm not sure. Criticism and help understanding is much appreciated!
  4. Thanks for clarifying that! The if statement checks to see if variable "$rm_field_un" is true. "$rm_field_un" becomes true if the username does not exist in the database. So if it is true, in the form under the field "username", it'll display an error message saying, "Your username was incorrect." or "The username you entered does not exist." Does that make sense? It's really confusing. My head goes in circles when I think about it haha.
  5. What does a database have anything to do with remembering somebody? And I was under the impression we were discussing "cookies", not "databases".
  6. I'm redoing my login script using functions and a basic switch function checking against a $_GET variable (hope you guys know what I'm talking about). What I want to do is create two functions: 1 that displays the login form and 1 that processes the information The form tag would look like this: <form action=\"<?php $_SERVER['PHP_SELF']?>?action=process\" method=\"post\"> </form> Here's my switch statement: <?php //**************************************** //****************Action****************** //**************************************** switch ($_GET["action"]) { default: case "index": if (!$_SESSION["member"]) { if (!$timeout) { display_form(); } else { echo $timeout_error; } } else { echo "You are already logged in."; } break; case "process": if (!$_SESSION["member"]) { if (!$timeout) { process_form(); } else { echo $timeout_error; } } else { echo "You are already logged in."; } break; } ?> This runs as soon as "login.php" loads. It'll automatically run the commands under case "default" and "index". It'll first check to see if the member's logged in. If not, it'll then check to see if "$timeout" is true ($timeout becomes true if the member has attempted to login 5 times and failed). If not, it'll display the login form, by running "display_form()". Once the form has been filled and submitted, the commands under case "process" will be performed. Again it will first check to see if the member's logged in. If not, it'll check to see if "$timeout" is true. If not, it'll start validating the forms. For the validation, I've created a variable called "$errors_found", and scripted one if statement checking to see if the email and password exist. If so, the variables "$rm_field_un" and "$rm_field_pw" become true, as well as "$errors_found". So, back to submission of the form... If "$errors_found" is true, display the form (when the form is displayed, there will be an if statement within that says "<?php if ($rm_field_un) { echo "Username is wrong."; } ?>", which will be displayed right underneath the username field and label. Same with the password elements). If "$errors_found" is not true, go ahead and register the member. Now, here's where I need help, because I'm really confused as to how to accomplish this. The "display_form()" function will contain a single variable called "$login_form". It will contain a value of the HTML constructed login form, and the function will return the variable. Remember how I stated in the third paragraph up that I will have <php> statements within the form which would display errors if necessary? Well, how do I put those if statements within the HTML, which is contained within the variable? If that last question confuses you, allow me to present you with an instance: <?php function display_form() { $login_form = " <form name=\"login_form\" method=\"post\" action=\"<?php $_SERVER['PHP_SELF']?>?action=process\"> Username: <input type=\"text\"> <?php if ($rm_field_un) { echo "Username is wrong"; } ?> "; return $login_form; } ?> See what I mean? This code confuses me ALOT. I'm not sure if the <php> tags are needed as it is already contained within existing ones, or what. Can somebody please help me out? Any and all help is much appreciated. =D
  7. Ohhhhhhhhhhhhhhhhhhhhhhhhh. I totally get it now. Seems like all I have to do is tweak my login script just a teensy bit. lol. I would still like to address an issue though. You said I shouldn't store the user's password in a cookie, but that's exactly what sites like Facebook DOES. I have often closed my browser, and as soon as I reopen it, I'm logged out, but both forms contain information, and all I have to do is click the "login" button to login. So...if Facebook does it, why can't I?
  8. Okay, first off, your setting your cookies wrong and THAT'S why it's not working. The way I learned, is you write "setcookie" with a "();" containing all of the arguments to the "setcookie" function. The first argument gives a name for the cookie. The second defines a value. The Third contains the expiration date of the cookie. The fourth assigns the cookie to a specific domain name. And the fifth (and last, I think), specifies a certain path within the domain you specify in the fourth argument. DO: <?php setcookie ("username", "$username", time() + 5000, ".mywebsite.com", "/mypath"); ?> DONT DO: <?php //Your assigning a $_COOKIE variable to the variable $username, but you're not giving either $_COOKIE variables an actual value. $username = $_COOKIE['user_id']; $pass = $_COOKIE['pass_id']; setcookie("user_id", "$username", time()+3600); setcookie("pass_id", "$pass", time()+3600); //If you want to create cookies using variables, you want to do them like this: $username = $_POST["username"]; $password = $_POST["password"]; setcookie("username", $username, time() + 3600); setcookie("password", $password, time() + 3600); ?> Hope this helps! Please correct me if I misunderstood your code.
  9. You're welcome =) Now I would assume both login scripts are using the same cookie/session names? I'm pretty sure that if you use the same cookie or session variable names for both logins, they will, essentially, be one in the same. For example you would use <?php $_SESSION["member"]; //for both login scripts if the login succeeds ?> Same with the cookies. <?php setcookie ("stay_on", "$username", time() +4000); //for both login scripts ?> Hope this helps!
  10. In my opinion, you should start the session before doing anything else, and make sure session_start(); is at the top of every page, instead of putting it in an if statement. it should be like this <?php session_start(); //This essentially logs the person in. //There is no need to put the "session_start()" function in the if statement below if (username & password) { $_SESSION["member"] = $username; } ?> Of course it's all a matter of preference, but it keeps your scripts more tidy and (in my opinion) professional, when done in this way.
  11. how does facebook keep people logged in when they close their browser, then? i use cookies, and all it does it remember their username and password and echo it into the forms (not a php echo, but you know what i mean lol)
  12. I don't know what you mean with long, but if your css files get to big, you might want to think about either getting the redundancy out of your sheets, or re thinking your design. Might have a look at this: http://kilianvalkhof.com/2008/css-xhtml/maximum-number-of-supported-classes-per-element/ But if you have 2000 classes your are doing something very very wrong. No i can't say I've reached 2000 yet lol. But I do have quite a few. Maybe 50 per file and about 6 different files. each file is named based on the type of css used. theres id_1, id_2, and id_3 then there's classes_1, classes_2, default, and animations so about 7. but when i combine both class files or all three id files, some ids and classes just stop working. I've checked to ensure they're linked in the header, but that's not the problem. When i say "messed up" i mean the 2nd template's css doesn't work period. No css gets applied to my html elements in all browsers but google chrome and opera. and like i said, it's not the php code, however, i suspect now, that it may be due to all the javascripts I have in place. i've noticed it's been affecting bits of my html as well.
  13. I have another question... Is it possible to set a session time limit? Because I have it set up on my site where when a user logs in and clicks "remember me", a cookie is a created for a set amount of time. the user is permitted to specify how long in "days", but someone wrote on a website that they use a session for that. it would be especially useful for keeping someone logged in even if they close the browser or shut off their computer.
  14. Does it matter where you start your session at? Does it have to be before the <!doctype> tag or can it go anywhere in the page?
  15. In my css code or html code? I can't think of what the problem is. I doubt it's any php code I have, and I have all of my css files linked to both templates. It's really weird because this is the first time I've ever had this problem. Also, when my css files get too long, some of my ids and classes stop working. No idea why this is either. I've been having to make multiple css files because of this.
  16. I have two templates (I use dreamweaver): 1 for the home page and 1 for everything else. I just tested my website in about 4 or 5 different browsers and now for the first time ever my css is messing up. It works on both templates in both Google Chrome and Opera, but only works on the home page template in every other browser. Anyone know of why this may be?
  17. Is it possible to disable the zoom in a user's browser? Cuz I just designed a template in Photoshop and all of my divs are sized using pixels rather than percents and when I zoom in on it the divs get all messed up and start stacking vertically, so I was wondering if its possible to just disable zoom when the user visits my page.
  18. I have music (my own) that I want to put on my website for download, and I was wondering if there is a way to keep track of how many people download each song, by tracking the clicks and displaying that number in a css-styled box. Anyone know how this is done? I don't need help with the css, just the php.
  19. It appears google is using Javascript rather than ajax. You could easily achieve the same effect by using Dreamweaver's built-in spry collapsible panel function. Just change the css to mimic google's and presto! If you don't use Dreamweaver, I strongly recommend getting it, because it comes with a lot of cool js functions like the above. Hope this helps!
  20. I doubt "form jumping" is the actual name for what I need help with, but basically I'm looking for a script that will make the cursor jump to the next form after a certain number of characters has been typed. I've tried about three or four different scripts but none of them worked for me. Anyone know of a simple-to-use script for this?
  21. Couple things... I stored both captcha scripts in a directory called "captcha", called the image generating script "captcha.php", and called the captcha in my html as so: <img src="../captcha/captcha.php?nocache=<?php echo time(); ?>" alt=""/> Is this right? Because the captcha is not being displayed on my website.
  22. What do I name the image generating script file as?
  23. Finally, an image generated captcha script that doesn't require downloading a ton of mb's worth of files. I'll try it out real quick and let you know if I encounter any problems...thanks for the script!
  24. I have it working so that it generates a random string, but I can't get that string to echo in the html so the user knows what to type.
  25. Ok this is what I have so far: <?php if (isset($_POST['submit'])) { $to = "myemailaddress"; $name = $_REQUEST['name'] ; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $subject = $_REQUEST['subject'] ; $header = "Contact Form"; $captcha = $_REQUEST['captcha']; $browser = $_SERVER['HTTP_USER_AGENT']; $ip = $_SERVER['REMOTE_ADDR']; $reason = $_REQUEST['reason']; $admin = "MyName"; for($i=0; $i<10; $i++){ $random_string .= chr(rand(0,25)+65); } if ($captcha != $random_string) { echo("The code you entered for the captcha was incorrect. Please go back and try again."); } else { mail($to, $header, "DJSmiley.Net Feedback\n\nVisitor Information:\n$name\n$email\n$ip\n$browser\n\nMessage - $subject\n$name says:\n$message"); mail($email, $admin, "Thank you for your feedback! I will try to get back to you with a reply when I can! \n\nTil' then \n-DJ Smiley"); echo( "Thank you for your feedback!" ); } } else { ?> <h2><a name="Feedback" id="Feedback"></a>Feedback</h2> <form name="contact" method="post" action="<?php $_SERVER['PHP_SELF']?>"> <table width="100%" border="0"> <tr> <td width="27%">Name:</td> <td width="73%"><label> </label> <label> <input name="name2" type="text" class="commentBoxforms" id="name2" /> </label></td> </tr> <tr> <td>Email: </td> <td> <input name="email2" type="text" class="commentBoxforms" id="email2" /> </td> </tr> <tr> <td>Subject:</td> <td><input name="subject" type="text" class="commentBoxforms" id="subject" /></td> </tr> <tr> <td>Message:</td> <td><label> <textarea name="message" cols="45" rows="5" class="commentField1" id="message"></textarea> <br /> </label></td> </tr> <tr> <td>Reason For Contacting:</td> <td><table width="50%" border="0"> <tr> <td><input name="reason" type="radio" id="endearment" value="endearment" checked="checked" /></td> <td><label for="endearment">Endearment</label></td> <td><input type="radio" name="reason" id="question" value="question"/></td> <td width="43%"><label for="question">Question</label></td> </tr> <tr> <td width="11%"><input type="radio" name="reason" id="general" value="general" /></td> <td width="37%"><label for="general">General</label></td> <td width="9%"><input type="radio" name="reason" id="suggestion" value="suggestion"/></td> <td><label for="suggestion">Suggestion</label></td> </tr> <tr> <td><input type="radio" name="reason" id="professional" value="professional" /></td> <td><label for="professional">Professional</label></td> <td><input type="radio" name="reason" id="technical" value="technical"/></td> <td><label for="technical">Technical</label></td> </tr> </table></td> </tr> <tr> <td><p>Captcha:</p> <p>Are you human?<br /> Enter the following:</p> <p><?php echo "<p class=\"captcha\">" .$random_string. "</p>"; ?></p> <p>*case sensitive</p></td> <td><input name="captcha" type="text" class="commentBoxforms" id="captcha" /></td> </tr> <tr> <td> </td> <td><input type="submit" class="Button1" value="Send Message" id="submit" name="submit"/> <input type="reset" class="Button1" value="Reset Form" /></td> </tr> </table> <a href="places_you_can_find_me.php"></a> </form> <?php } ?> The problem I have here is that I can't get $random_string to = the user input. Help please?
×
×
  • 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.