Jump to content

arbitter

Members
  • Posts

    349
  • Joined

  • Last visited

Everything posted by arbitter

  1. I'm no hero, but what if you use document.getElementById('userinfo').style.visibility='hidden' or 'visible'?
  2. Most sites have a fixed resolution, so you don't have to worry about that. Well 'most sites' is a little much, but I for a fact do it. I work with a width of 1024px, because not many people have a resolution below that. It might not be that nice for people with a very large resolution or people with a resolution lower than 1024 pixels, but that's what you have to pay for that comfort. Nevertheless with no information, nobody can help. You can extract the layout of your site, your divs or whatever, along with the css for it so we can help.
  3. I copied the exact scripts you have and it works fine. You must have forgotton to include the js file?
  4. Okay I have found the problem. document.getElementsByName(id) returns a whole array, not a single value. If you put var idValue = document.getElementsByName(id)[0];, you will get a value
  5. Well I tried your script but using the id's instead of name's and it does give the value.. Also, your div had id="customerNameImg", but in your script you had document.getElementsByName(id + 'Img').innerHTML = '<img alt=/"/" src=/"/">';, which should be document.getElementById(... To get it to work I gave the input field an id customername and in your js I wrote var idValue = document.getElementById(id);.
  6. Well, say you have a div called 'Showme' that's hidden and a button to show it. here's the code so you can use it on many elements wth different id's: <script type='text/javascript'> function hideShow(div){ if(document.getElementById(div).style.visibility == 'hidden'){ document.getElementById(div).style.visibility = 'visible'; }else{ document.getElementById(div).style.visibility = 'hidden'; } } </script> <input type='button' onclick="hideShow('Showme');" /> <div id='Showme' style='visibility:hidden'>I am hidden untill you press the button above. I get hidden again after pressing it another time.</div>
  7. After dozens of problems gotten further and the whole timer problem has been resolved too. Also the problem where the same element would b e chosen twice after each other is resolved. I rewrote it all after finding a major bug in my randomnumber getter - sometimes it would get a value of 0 and the script would keep the element before as the active element, causing loads of same elements after each other. Heres the code: function count(){ var max=9; var min=1; var rand1 = Math.floor(Math.random() * (max-min) + min); var rand2 = Math.floor(Math.random() * (max-min) + min); cellid = 'r' + rand1 + 'c' + rand2; } function startGame(id){ if(id == 'start'){ document.getElementById('button').style.visibility='hidden'; allColor('red'); count(); document.getElementById('greenId').value=cellid; document.getElementById(cellid).bgColor='green'; var seconden = 3; startTimer(seconden); document.getElementById('level').innerHTML='1'; teller = '0'; }else{ var huidige = document.getElementById('greenId').value; if(document.getElementById(id).bgColor == 'yellow'){ }else if(id != huidige){ stopTimer(); alert('Fout!'); restartGame(); }else{ stopTimer(); do{count();}while(id == cellid); document.getElementById(id).bgColor='red'; document.getElementById(cellid).bgColor='green'; document.getElementById('greenId').value=cellid; var seconden = 3; if(teller >= 20){ seconden = 2; }else if(teller >= 40){ seconden=1; } startTimer(seconden); teller++; } } }
  8. Hya fellas! I've got quite a few problems with a script I have. I have 10 rows and ten columns in a table. Each table has a different id. I want to make a sort of game, that sets all the cells red except for one. you have to click it in a certain amount of time, or you fail and the 'game' gets reset. I have a function allColor(id) that changes all the cellcolors to the same color, this works. Here is the function that 'runs' the game: <script type='text/javascript'> function startGame(id){ if (id == 'start'){ document.getElementById('button').style.visibility='hidden'; allColor('red'); var rand1 = Math.floor(Math.random( )*11); var rand2 = Math.floor(Math.random( )*11); document.getElementById('r' + rand1 + 'c' + rand2).bgColor='green'; var timerDrie = setTimeout("alert('Te laat! Begin opnieuw.');restartGame();",3000); document.getElementById('greenId').value = 'r' + rand1 + 'c' + rand2; }else if(document.getElementById(id).bgColor=='yellow'){ }else{ var greenId = document.getElementById('greenId').value; if(id != greenId && greenId != '0'){ alert('Fout! Begin opnieuw.'); restartGame(); clearTimeout(timerDrie); } clearTimeout(timerDrie); allColor('red'); var rand1 = Math.floor(Math.random( )*11); var rand2 = Math.floor(Math.random( )*11); document.getElementById('r' + rand1 + 'c' + rand2).bgColor='green'; var timerDrie = setTimeout("alert('Te laat! Begin opnieuw.');restartGame();",3000); document.getElementById('greenId').value = 'r' + rand1 + 'c' + rand2; } } function restartGame(){ document.getElementById('button').style.visibility='visible'; allColor('yellow'); } </script> A short explanation: a function makes a random cell number (r$c$ with $ number between 1 and 10). This cell gets green, and a hidden field (greenId) gets the cell number for reference when the function is called again. Each cell has an onclick with it's own id in it. When it is clicked and the id doesn't match with the id from the hidden field, you get a popup and the game should restart. Now I've got tons of problems. For one: the timers do not get stopped. Never. Even if the game ends, timers keep popping up for a while. And so you can't play the game. Second, if a cell was green and the next cell randomly selected is the same one, the cell stays red and doesn't turn green. I get an error 'Cannot set property bgColor of null' Since this is only the base of my program I am sure there will be dozens of problems coming up after these are fixed, but you have to start somewhere! Thanks in advance! arbitter
  9. Great remark, I indeed want them to be able to edit it. So: Storage: mysql_real_escape_string(); Show when editable: htmlentities(); Show when not-editable: bbcode_format(htmlentities()); Like that? Or is there a chance that the htmlentities() can mess up the bbcodes and should it be done in the other order?
  10. I'm afraid you will have to use javascript, PHP can't do such things. I suggest that on the submit button you first run a javascript function that checks all your fields, including the captcha, and if necessary print an error.
  11. I don't quite see the problem, no flaws in your code and it should do the trick. Are you sure it isn't resized?
  12. So the data that'll be in the database will allready be html-ish? They will already be eg "<b>text</b>" instead of "text"? And I guess I'll have to do with that 99%, unless there's something I can do about it? I'll give the json_encode a try tomorrow, thanks a lot!
  13. Hi there, I've got this BBCode parser and I need to make sure NOTHING can go wrong by injection or anything, as it will affect a part of the main page of a site. I'm a little confused with what happens with code when it gets cleaned, so I'm not sure if it'll work like this. So there's a textarea, and the contents of that textarea should be put in a MySQL database. So I guess this will do: mysql_real_escape_string(htmlentities($string)) But how do 'enter's' get put in a database? Because the parser code is: <?php function bbcode_format($str){ $str = htmlentities($str); $format_search = array( '#\[b\](.*?)\[/b\]#is', // Bold ([b]text[/b] '#\[i\](.*?)\[/i\]#is', // Italics ([i]text[/i] '#\[u\](.*?)\[/u\]#is', // Underline ([u]text[/u]) '#\[color=\#?([A-F0-9]{3}|[A-F0-9]{6})\](.*?)\[/color\]#is', // Font color ([color=#00F]text[/color]) '#\[url=((?:ftp|https?)://.*?)\](.*?)\[/url\]#i', // Hyperlink with descriptive text ([url=http://url]text[/url]) '#\[img\](https?://.*?\.(?:jpg|jpeg|gif|png|bmp))\[/img\]#i', // Image ([img=http://url_to_image]) '#\[titel\](.*?)\[/titel\]#is',//titel '#\[inhoud\](.*?)\[/inhoud\]#is' ); $format_replace = array( '<strong>$1</strong>', '<em>$1</em>', '<span style="text-decoration: underline;">$1</span>', '<span style="color: #$1;">$2</span>', '<a href="$1">$2</a>', '<img src="$1" alt="" />', '<span class="mainheader">$1</span>', '<span class="inhoud">$1</span>' ); $str = preg_replace($format_search, $format_replace, $str); $str = nl2br($str); return $str; } ?> Also, is it safe to send all this information through ajax? How should it be 'cleaned' to pass through ajax and php without any trouble? Thanks in advance, arbitter
  14. Well, this script is in the beginning of my index page, when there is no output yet. The session gets set as logged in, and after that the content of the site gets loaded. This shouldn't be the problem should it? When a user isn't logged in and logs in, he is logged in right away, even though the page doesn't reload and the script <?php $_SESSION['loggedin'] = true; $_SESSION['loggedinnick'] = $row['nick']; $_SESSION['loggedinvoornaam'] = $row['voornaam']; $_SESSION['loggedinachternaam'] = $row['achternaam']; $_SESSION['loggedinid'] = $row['id']; $_SESSION['loggedintype'] = $row['type']; ?> So I don't see why this would be the problem...
  15. Oh delightful that you saw that! The thing I use to clean my variables is this: <?php function CleanMyDirtyData($dirtydata) { return mysql_real_escape_string(htmlentities($dirtydata, ENT_QUOTES,'UTF-8')); } ?> Would this change the hash in any way? I mean, does the regular hash and the cleaned hash be different and as a result un-matching, or not? I'm not that familiar with the real changing of the value due to these functions.
  16. - I'll give that a try - Since I never had any scripting lessons I don't quite know the right structure of these things, but either way the user gets the eg index.php, and for some parts of the site (for example where there is a possibility to login or to see your current username), I use: <?php if(isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true){ //code when user is logged in, eg to show the username and stuff }else{ //code that shows eg the login part of the page } ?> I'm guessing this isn't the best method, but it's what I'm currently using. - I guess this point isn't neccesary, but perhaps for future projects it might be more handy.
  17. Hello there, The problem is that my login system isn't consistent. There's an option of staying logged in, and if you check that a cookie gets created with a hash. When you visit the site again, you should be logged in automatically. But the thing is, that when you load the page, you aren't! But after a refresh you are logged in. So I'm guessing a problem in the order of things that get done... Here's the script: <?php session_start(); if(isset($_COOKIE['LoginCookie'])) { $hash = $_COOKIE['LoginCookie']; mysql_select_db('database'); $sql = "SELECT all the info of the people FROM people WHERE cookie_hash = '".$hash."'"; if($result = mysql_query($sql)) { $row = mysql_fetch_array($result); if(empty($row)) { setcookie('LoginCookie','',time()-3600); } if(mysql_num_rows($result) == 1) { $_SESSION['loggedin'] = true; $_SESSION['loggedinnick'] = $row['nick']; $_SESSION['loggedinvoornaam'] = $row['voornaam']; $_SESSION['loggedinachternaam'] = $row['achternaam']; $_SESSION['loggedinid'] = $row['id']; $_SESSION['loggedintype'] = $row['type']; } } } if(isset($_POST['login'])) { if(empty($_POST['username']) || empty($_POST['wachtwoord'])) { $_SESSION['melding'] = 'ERROR'; header('Location: index.php'); exit(); } $username = CleanMyDirtyData($_POST['username']); $wachtwoord = sha1(CleanMyDirtyData($_POST['wachtwoord'])); mysql_select_db('database'); $sqlmail = mysql_query("SELECT * FROM people WHERE email='$username' AND wachtwoord = '$wachtwoord'"); $sqlnaam = mysql_query("SELECT * FROM people WHERE nick='$username' AND wachtwoord = '$wachtwoord'"); if(mysql_num_rows($sqlmail) == 1 || mysql_num_rows($sqlnaam) == 1) { if(mysql_num_rows($sqlmail) == 1) { $row = mysql_fetch_array($sqlmail); } else { $row = mysql_fetch_array($sqlnaam); } if(isset($_POST['remember'])) { $hash = sha1($username . 'Some secret thingys for your safety'); setcookie('LoginCookie',$hash,time()+30000000); mysql_query("UPDATE leden SET cookie_hash='" . $hash . "' WHERE id='" . $row['id'] . "'")or die(mysql_error()); } $_SESSION['loggedin'] = true; $_SESSION['loggedinnick'] = $row['nick']; $_SESSION['loggedinvoornaam'] = $row['voornaam']; $_SESSION['loggedinachternaam'] = $row['achternaam']; $_SESSION['loggedinid'] = $row['id']; $_SESSION['loggedintype'] = $row['type']; $_SESSION['melding'] = 'You are logged in now.'; } else { $_SESSION['melding'] = 'ERROR'; header('Location: index.php'); exit(); } } So if the checkbox that you want to stay logged in, there is no cookie made but the $_SESSION['loggedin'] is set to true. Throughout the rest of the page, this parameter is used to show either content for guests of private content for people that are logged in. BUT the problem is that if it is checked on the first page load the $_SESSION['loggedin'] doesn't seem to get set even though the cookie is set. Another slight problem with my script is that when a user logs in on another pc, the hash get's changed in the database and the user gets logged out of the site on the previous page. What is the easiest way to do that? And do you guys think this script is safe? Or do you see some holes? Thanks in advance! arbitter
  18. Hi there, I have this table, generated with php: <?php mysql_select_db('database'); $query = mysql_query("SELECT * FROM activiteiten"); while($row = mysql_fetch_array($query,MYSQL_ASSOC)){ echo "<tr><td>" . $row['naamactiviteit'] . "</td><td>" . $row['begindag'] . "</td><td>" . $months[$row['beginmaand']] . "</td><td>" . $row['beginjaar'] . "</td><td>/</td><td>/</td><td>/</td><td><input type='button' value='verwijderen' onclick=\"ajax('delete','".$row['id']."');deleteRow(this.parentNode.parentNode.rowIndex)\" /><input type='hidden' value='".$row['naamactiviteit']."' id='naamactiviteit".$row['id']."' /></td></tr>"; } ?> So I already have a delete-button that deletes the contents from a database and that deletes the table row. What I want to implement now is an 'edit' button, so that the contents can be edited. Now, every date should be editable with a <select><option value='1'>1</option> and so on. I was wondering, what would be the best way of doing this? Give each cell a specific id containing the unique id of the content, and then on the click of a button hiding the current contents and showing the <select> things? Or is there a simpeler way? And on another note; can you hide or show all the elements of a page with the same class with javascript? Thanks in advance!
  19. Yes I am! But I want it without the [content] tags, though they should appear...
  20. Hi there, This isn't really a bbcode parser problem, but it kind of is. And I am awful at explaining things, as you have noticed. The problem is that I'd like to allow input for the main page of a site. But the part has this structure: <div class='mainheader'>TITLE</div> <div class='content'> The content of the webpage blabla</div> I'd like this whole page to be changeable, so also the title and the content. But how can I ensure that people use the content div after the mainheader div? I would like it if it were possible that they only needed to 'select' the header, how can I do this? Thanks in advance!
  21. Allright thanks a bunch! This is very handy
  22. Okay then, I'll use this then! It's just more complicated because of all the id's and names already flowing through my script, but I'm sure it'll be ok like this. Just more work than a simple added tag or so. Thanks for the help!
  23. I thought about that too, but I was hoping there would be a way without the browser changing the position it the page is... Is there no way of doing this?
  24. Hi there, I have a little problem. I have this big page with all small images, and when you click it it opens a new window with the image, but bigger. But then when you go back to the previous page, the page goes back to the top, i presume due to the href='#'. How can I fix this so that the original window doesn't go to the top? <a href='#' onclick=\"Popup=window.open('http://mydomain/picture.jpg','Picture')\"><img src='http://mydomain/picture.jpg' /></a>
  25. Second attempt: Shouldn't <?php while($info = mysql_fetch_array( $data )) { $email = $data['email']; $username = $data['username']; $firstname = $data['firstname']; $password = $data['password']; } ?> Be $email = $info['email']; ... and so on
×
×
  • 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.