Jump to content

TeddyKiller

Members
  • Posts

    1,056
  • Joined

  • Last visited

    Never

Everything posted by TeddyKiller

  1. I sort of made a function // Check username function valUsername(FIELD) { if(FIELD.value.length < 4) { FIELD.setAttribute("class", "bad"); } else { if(FIELD.value.length > 30) { FIELD.setAttribute("class", "bad"); } else { FIELD.setAttribute("class", "good"); } } } It's alright for an offclick.. which is what it seems to do for an onchange... though I want it to execute the javascript everytime the value changes...
  2. I'm not sure what you mean.. The cookie would be created in javascript on the initial load... correct? I can use ajax to get an external page which would be in php to check for the cookie.. and do whatever if it doesn't exist. .. though with it being ajax.. browsers can disable it can't they? - I've seen many sites, facebook included.. where if javascript is turned off, or isn't loaded in time (Like for slow browsers.. it'll take significantly longer to load it) then it states 'Javascript is turned off' I use alot of ajax.. but a few tweaks of javascript.. but if javascript is disabled, then ajax would be wouldn't it? As they both use the javascript script tags... I think my javascript is important when I use it. I don't use it for pointless things..
  3. good idea, but what if cookies are turned off?
  4. Hey sexy karl. Try this regex. ^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$ Whats my source? Google.
  5. Hi. Right, I'm mega confused about this topic. Lets say we have a textbox... I believe on the textbox onchange, I'd like to validate it. A simple javascript function for that textbox, to check if the value is smaller than 4. If it is smaller, to change the class of the textbox to '.bad' else if the value is bigger than 4, to change the class of the textbox to '.good' Any ideas how I can do it? Thanks
  6. I want to know how to check if javascript is turned on in the users browser. I found the function get_browser(), would this do what I want it to do.. $browser = get_browser(null, true); if($browser['javascript'] == 0) { //Javascript is not on! } Any help? Thanks
  7. As a string then. It's not a very good idea. You should use MySQL's DATE datatype May I ask, why isn't it a good idea?
  8. May I ask why you have.. <select name="assisted_frequency[<?php echo $i; ?>] ... Whats the advantage of the [$i;] because thats now considered as an indexed array. If it's a unique ID. Just do.. <select name="assisted_frequency-<?php echo $i; ?> ...
  9. $sql="INSERT INTO badges (username, badge, date) SELECT username, '$badge', $today' FROM users"; Would this actually work? it's selecting 3 information from the users table, and not really inserting it?
  10. In future, do not post code with the actual details to your server. They are located in the file. I would recommend changing the pass asap incase someone stumbles upon the post and says bye bye to your database. I don't know the problem, there is alot of code. Can you tell me where I should be looking?
  11. Do you recieve an mysql_error? If so, what error is it. You might also want to consider using mysql_real_escape_string for all values going into the query.
  12. Has a table method not occured to you? <table> <tr> <td> <label for="Neatherlands">Neatherlands</label> <input type="checkbox" name="neatherlands" id="Neatherlands" value="" /> </td> <td> <label for="United Kingdom">United Kingdom</label> <input type="checkbox" name="united kingdom" id="United Kingdom" value="" /> </td> </tr> </table>
  13. Well.. I believe what you want to do is: Get all the usernames from the users table via a query. Do a while for that query, and inside the while.. would be inserting that username into the badges table with the nessecary badge etc. Example <?php if(isset($_POST['submit'])) { $query = mysql_query("select username from users"); while($row = mysql_fetch_assoc($query)) { $today = date("d.m.y"); $query = mysql_query("INSERT INTO `badges` (username, badge, date) VALUES ('".$row['username']."', 'THE BADGE', '$today')"); } } echo 'Give badges to all users'; echo '<form action="" method="post"><input type="submit" value="submit" name="submit" /></form>'; This should work, but you can do it like what CodeMaster said.
  14. Bingo. Found something nice. <?php define("_VALID_PHP", true); include('../include/config.php'); include('func.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Chained Select Boxes using PHP, MySQL and jQuery</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#wait_1').hide(); $('#drop_1').change(function(){ $('#wait_1').show(); $.get("func.php", { func: "drop_1", drop_var: $('#drop_1').val() }, function(response) { setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400); }); return false; }); }); function finishAjax(id, response) { $('#wait_1').hide(); $('#'+id).html(unescape(response)); $('#'+id).show(); } </script> </head> <body> <p> <form action="" method="post"> <select name="drop_1" id="drop_1" size="7"> <option value="" selected="selected" disabled="disabled">Select a Category</option> <?php getTierOne(); ?> </select> <br /><br /> <span id="testing"> <select name="test"> <option value="" selected="selected" disabled="disabled">Choose one</option> <?php $editranks = $db->query ("SELECT * from clan_ranks WHERE clanurl = 'url' order by `rankname` asc"); while($res = $db->fetch($editranks)){ echo '<option value="' . $res['rankname'] . '">' . $res['rankname'] . '</option>'; } ?> </select> <span id="wait_1" style="display: none;"><img alt="Please Wait" src="ajax-loader.gif"/></span> </span> <span id="result_1" style="display: none;"></span> <br /><br /> <?php echo '<input type="submit" name="submit" value="Submit" />'; ?> </form> </p> </body> </html> func.php holds the functions for it all etc. The problem is, when you select the first value.. it works fine, the loading bar displays, then disappears. Although when you click another value, it doesn't display the loading bar. Other than that it works, just wondering if you can help out with that? I believe its something with the ajax.
  15. My code is below. I'm wanting to pass the php variable $db, to the function called. The line where I'm having issues is db: <?php echo $db ?> $(document).ready(function() { $('#wait_1').hide(); $('#drop_1').change(function(){ $('#wait_1').show(); $('#result_1').hide(); $.get("func.php", { func: "drop_1", drop_var: $('#drop_1').val() db: <?php echo $db ?> }, function(response){ $('#result_1').fadeOut(); setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400); }); return false; }); }); How can it be done? Thanks
  16. Actually, there is a problem. I can't save the fields. Like.. they get generated on the page, but for some reason they aren't in the source code when I view it. So when I process the form, the drop down is like.. empty. It has no value.. Any reason for this?
  17. Yeah. I found one.. well I used one on a previous site with two drop downs, i forgot about it.. and then I remembered. It seems to do the job. - I didn't know a drop down is actually a select menu with a different size otherwise I wouldn't of posted this. Thanks for replying though
  18. It's not like that though. It's a form, with a button. When the button gets pressed, the ajax does it work. Now.. the form displays some information from the database. I'd like that to be refreshed. It's got nothing to do with the external php page for the form validation.
  19. We have a select menu, which is populated by a PHP Mysql query. What I want to do.. is populate the drop down menu.. based on what is clicked in the select menu. It sort of.. gets the value of whats clicked.. and insert it into a mysql query.. and then populate the drop down menu. Any help? I know most of it would be in PHP. Although... the bit would be.. getting the value.. and then allowing me to do stuff with it to populate the drop down.
  20. Thanks... although I'm more or less looking for it to include an external php file for it to load?
  21. Ohmy. I did some checking. A function wasn't working. public function getUserInfo($table, $field, $value) { global $db; $sql = "SELECT * FROM `" . $table . "` WHERE `" . $field . "` = ' " . $value ." '"; $result = $db->execute($sql); if (!$username) : return false; endif; if ($db->numrows($result) > 0) : return $db->fetchassoc($result); else : return null; endif; } Two problems. The white space in the query, and the $username. Sorted it... sorry for the thread.. although I guess someone could of suggested the echoing of the sessions in turn. Anyway.. Thanks.
  22. $this->id = $_SESSION['uid'] = $this->userinfo['id']; $this->hashkey = $_SESSION['hash'] = sha1($this->id . $this->ip . $secret_key); This sets the sessions. So I don't get why it don't work. No errors get shown. Before the return true in the login function. I did "echo 'logged in'; exit;" and it echos out logged in. So its doesn't it correctly. but not setting any sessions. I really don't understand why.. If I click the remember me button. I recieve this error.. Warning: Cannot modify header information - headers already sent by (output started at /home/jeanie/public_html/new/include/session.php:38) in /home/jeanie/public_html/new/include/session.php on line 116 Line 116.. is ..setcookie("HORBLECOOKIE", $this->hashkey . '-' . $this->id, $this->time + COOKIE_EXPIRE); Maybe this is the problem? although.. how can I fix it, is it because of the echo's I have.. because thats giving out output.. or is it another thing.. arghhh. I removed the echo's.. tried to login, with checking the remember me too. It doesn't work... It needs sorting asap. =[
  23. Done some error checking. When you are logged in, or even when you aren't the echos come up. public function startSession() { session_start(); echo 'Sessions started '; } and if(isset($_SESSION['uid']) && isset($_SESSION['hash'])) { //$user = $session->checkLogin($secret_key); echo 'Sessions are set'; exit; } else { echo 'sessions arent set'; } It keeps saying "sessions started sessions arent set" Seriously.. what's doing this..
  24. if ($check != $this->uid) {/i] should of been if ($check != $this->hashkey) { Although this doesn't fix the problem.
  25. I have a database factory. I believe all is working - no errors. I have a users class. Which has all 'valid email' etc etc. I have a session class. Which has all the 'login' and process functions etc. Now when you login, it redirects you to main.php - Which is what it should do. In config.php, it calls all the classes, etc. It starts a new session. Though, if two sessions are set, it calls the checkLogin function. When a user logs in, gets redirected to main.php, it'll load the config file, and process the checkLogin. I call the users username (To see if its getting the users logged in information) To call a username, it would be .. $user->username; and it doesn't get displayed. When a user logs in, $this->logged_in is set as 1. I do a check, if $this->logged_in, is set. If it isn't.. it'll redirect back to the index page. What it does, is redirects back to the index page. So not only is $this->logged_in, not being set, it's not getting the information of the current logged in user. I don't really know the problem.. i just know thats what it's doing. config.php - I cut out the variables for the connections <?php require_once("db.php"); require_once("user.php"); require_once("session.php"); $db = DatabaseAdapterFactory::factory('mysql', DB_SERVER, DB_USER, DB_PASS, DB_NAME); $db->connect(); $session = new Session; $secret_key = '103041231'; if(isset($_SESSION['uid']) && isset($_SESSION['hash'])) { $user = $session->checkLogin($secret_key); } ?> main.php <?php require_once("include/config.php"); if(!$session->logged_in) : redirect("/new/index.php"); endif; echo $user->username; ?> Part of the login page. Got the call to the login function, doesn't have the form as it isn't nessecary. <?php require_once("include/config.php"); if ($session->logged_in) : redirect("main.php"); endif; /* Lets do the login */ if (isset($_POST['login'])) : $result = $session->login($_POST['username'], $_POST['password'], isset($_POST['keep']), $secret_key); if ($result) : redirect("main.php"); endif; endif; ?> session.php - missing a few functions. If you need the code for certain functions. let me know. - I just put the most important functions in. <?php class Session extends User { public $time; public $logged_in = NULL; public $ip; public function __construct() { $this->time = time(); $this->ip = $_SERVER['REMOTE_ADDR']; $this->startSession(); } public function startSession() { session_start(); } public function checkLogin($secret_key) { global $db; if (isset($_COOKIE['HORBLECOOKIE'])) : $data = explode('-', $_COOKIE['HORBLECOOKIE']); $_SESSION['uid'] = $data[1]; $_SESSION['hash'] = $data[0]; endif; $this->uid = $_SESSION['uid']; $this->hashkey = $_SESSION['hash']; if (!isset($this->uid) || !isset($this->hashkey)) {} else { $check = sha1($this->uid . $this->ip . $secret_key); if ($check != $this->uid) { $this->logout(); } else { $query = $db->execute("SELECT * FROM users WHERE id='".$this->uid."'"); $userarray = $db->fetchassoc($query); if ($db->numrows($query) == 0) { $this->logout(); } foreach($userarray as $key=>$value) { $user->$key = $value; } $this->logged_in = 1; return $user; } } } public function login($username, $password, $keepmein, $secret_key) { global $msgError; $this->username = clean($username, 1, 1, 2); $this->password = clean($password, 1 , 1, 0); if (empty($this->username) || empty($this->password)) { $msgError = "You have left empty fields!"; return; } $result = User::confirmUserPass($this->username, $this->password); if ($result == 1 || $result == 3) { $msgError = "Please enter valid username and password."; return; } elseif ($result == 2) { $msgError = "Your user account has not been activated yet!"; return; } if (empty($msgError)) { $this->userinfo = User::getUserInfo('users', 'username', $this->username); $this->id = $_SESSION['uid'] = $this->userinfo['id']; $this->hashkey = $_SESSION['hash'] = sha1($this->id . $this->ip . $secret_key); User::updateUserField('users', $this->username, "last_login", $this->time); User::updateUserField('users', $this->username, "ip", $this->ip); if ($keepmein) { setcookie("HORBLECOOKIE", $this->hashkey . '-' . $this->id, $this->time + COOKIE_EXPIRE); } $this->logged_in = 1; return true; } else { return false; } } public function logout() { if (isset($_COOKIE['HORBLECOOKIE'])) { setcookie("HORBLECOOKIE", "", $this->time - COOKIE_EXPIRE); } session_unset(); session_destroy(); $this->logged_in = 0; redirect("/new/index.php"); } } ?> Basically. with that $this->logged_in check, when you login, it'll redirect you back the index page.. because it simply isn't being set. I don't know if the checkLogin function is being stopped somewhere.. and returning true without doing the rest of it.. or anything. Any ideas?
×
×
  • 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.