Jump to content

GoodVibe

Members
  • Posts

    26
  • Joined

  • Last visited

    Never

Everything posted by GoodVibe

  1. Do you mind explaining what that one does? How does it sanitize the data?
  2. I have the following code: /Sanitize the username var tagBody = '(?:[^"\'>]|"[^"]*"|\'[^\']*\')*'; var tagOrComment = new RegExp( '<(?:' // Comment body. + '!--(??[^->])*--+|-?)' // Special "raw text" elements whose content should be elided. + '|script\\b' + tagBody + '>[\\s\\S]*?</script\\s*' + '|style\\b' + tagBody + '>[\\s\\S]*?</style\\s*' // Regular name + '|/?[a-z]' + tagBody + ')>', 'gi'); function removeTags(html) { var oldHtml; do { oldHtml = html; html = html.replace(tagOrComment, ''); } while (html !== oldHtml); return html.replace(/</g, '<'); } var userNames = new Array("temp","curseword","Temp"); $('#userid').blur(function(){ var userId = $('#userid').val(); var safeId = removeTags(userId); if (safeId.length < 6){ $('#nameCheck').html('The username must be at least 6 characters'); } else if (safeId.length == userId.legth){ $('#nameCheck').html('Please only use alphanumerical characters'); } else if(userId.length >= 6){ var unique = true; for (i=0; i<userNames.length; i++){ if (userId == userNames[i]){ unique = false; } } if (unique == false){ $('#nameCheck').html('The username ' + safeId + ' is taken, please try another one'); } } else { $('#nameCheck').html('The username is correct and you can use it'); } }); Now, the problem I am having is that what i want it to do is that when someone tries to input something that isnt alphanumerical its supposed to tell them so, but so far it does not change the display. Checking for length and such works fine, its just the sanitation part that is giving me troubles. Any ideas?
  3. Ok, so i narrowed it down to either one of these lines: userId = userId.replace(/<[^>]*>?/g, ''); $(this).attr('value', userId); As to the change: $(this).attr('value', userId); to $(this).val(userId); will that also change the value? I am trying to make it so that when the user types a character that is not valid it removes and keeps the valid username. Thanks for the help so far
  4. Hi, no, I haven't been using the addons, completely forgot about them. As for the file paths, I know that the ../ means to go one folder up in the tree correct? The file paths are correct, and after a little bit more searching I have found out that my problem lies in: var userId = $(this).val(); alert (userId); userId = userId.replace(/<[^>]*>?/g, ''); $(this).attr('value', userId); I was trying to use this to sanitize my input, but it seems to be crashing the program. ANy suggestions on that? Also, I had a quick question. I have seen people add the line <script type='text/javascript' src="js/register.js"></script> In the header of the page. The tutorials I have been following tell me to do so at the end of the body. What is the difference? Thanks
  5. To grab the value of the currently selected item on your dropdown list: var list_value = $('#YourListID').val(); Is that what you are looking for?
  6. I am trying to make a basic form for registering, and trying to validate it. For some reason, it will not call the js at all. I have even reated an alert to popup when the page loads and i am getting nothing. Maybe Im missing something simple, so any help would be appreciated. Here is my main file: <html lang="en"> <head> </head> <body> <form action="#"> <b>User Name</b> <input type="text" id="userid" /> <span id="nameCheck"></span> <br/><br/> <b>Password</b> <input type="password" id="password" /> <span id="passCheck"></span> <br/><br/> <b>Re-enter Password</b><input type="password" id="password2" /> <span id="pass2Check"></span> <br/><br/> <b>E-mail</b><input type="text" id="email" /> <span id="mailCheck"></span> <br/><br/> <b>Re-enter Email</b><input type="text" id="email2" /> <span id="mail2Check"></span> </form> <script type='text/javascript' src="js/jquery.js"></script> <script type='text/javascript' src="js/register.js"></script> </body> </html> And here is my js: $(function(){ alert ('We have JS'); }); var userNames = new Array("temp","curseword","Temp"); $('#userid').blur(function(){ var userId = $(this).val(); alert (userId); userId = userId.replace(/<[^>]*>?/g, ''); $(this).attr('value', userId); if (userId.length < 6){ $('#nameCheck').html('The username must be at least 6 characters'); } else if(userId.length >= 6){ var unique = true; for (i=0; i<userNames.length; i++){ if (userId == userNames[i]){ unique = false; } } if (unique == false){ $('#nameCheck').html('The username is taken, please try another one'); } } else { $('#nameCheck').html('The username is correct and you can use it'); } });
  7. The reason I suggested that is for re usability. He is echoing the variable twice, and in my personal taste, it is easier to define the variables that way any changes in the future are easy to made. As far as wasting processing power I did want to ask what is the difference between storing the variable and calling the htmlentities function twice for every echo?
  8. From what I am seeing, the easiest way to do this is to use double quotes, since it will allow you to echo your php variables. Also, I would suggest that you store the variables before your echo statement Try this: while($row = mysql_fetch_array($result)) { $vendorId = $row['vendor_id']; echo "<option value='$vendorId'>" . $vendorId. '</option>'; }
  9. I do not know enough math or PHP to try to write one myself I did not know of the existence of mt_rand(), but when i was researching random number generators I did notice that the one it uses is one of the faster and more "accurate" methods out there. Thank you for the help.
  10. Hello everybody, I just have a quick question. I am trying to develop a webpage for dice rolling (to use for myself when i play dnd) Now, I know a lot of the random functions is computer languages are not truly random, and thus have some areas that the value will be the result more than others. What would be a good way to try to make it as "random" as possible, or am I just over-thinking it?
  11. Ended up using: $mxr = dns_get_record($sub, DNS_MX); So thank you very much Muddy for the suggestion and everyone for the help.
  12. The thing that confuses me is that i see that mxhosts is the array that will give me the mxhosts, but then the return value says that it only does true/false. So I am a little confused as to how call that array with the values if I am just passing it as a parameter. To Muddy: The list of hosts I have should not have more than one mx record, and if they do, I only care to see the first one, so that method that you posted might work.
  13. I currently have a list of host addresses. I need to get the mx records for them. I was looking at the documentation, and found the getmxrr(). Would that send back the mx record, or just true if it has one?
  14. I found the error, and it ended up being that i had not authorized that user to access the database. Thank you for your help.
  15. Ok. running that gives me the error: No database selected. If I go to my connection file, this is the code: <?php //Connect to DB $con = mysql_connect("localhost","thegoo20_user","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("thegoo20_wordgame", $con); ?> When i run this file by itself, it does not give me any sql errors, so I thought that it was working fine. Maybe I am missing something?
  16. Hows it going guys. I am currently having a problem. I had a program that worked. I migrated the website and now the program is broken. Any time i try to run it, i get this error: Here is the code at that point: function changeword(){ $result = mysql_query("Select words from CurrentWords"); $totalwords = array(); while ($row = mysql_fetch_array($result)){ $totalwords[] = $row["words"]; } $_SESSION['word'] = $totalwords[rand(0, count($totalwords)-1)]; $_SESSION['scrambled'] = str_shuffle($_SESSION['word']); } where line 31 is the while statement. Any help would be appreciated. Thanks
  17. Thank you, I will now kindly take the solution and facepalm myself.
  18. when I add the php tags, i get this error: if I look at my file, line 4 is: $arr = array(); and i cant figure out why it tells me that
  19. Ok. So I.m trying to learn the language. I have this program: <?php require_once("fillarray.inc"); ?> <html> <head> <title>PHP Class Lesson 2 - AJ</title> </head> <body> <h1>The Circumference of a Circle</h1> <br> <table border="1"> <thead> <tr> Circle Number:</tr> <tr> Diamater</tr> <tr> Circumference</tr> <tr> radius</tr> <tr> Area</tr> </thead> <?php foreach($arr as $diameter){ echo ("<td>"); echo("<tr align=\"center\"> 1 </tr>"); echo ("<tr> $diamater </tr>"); $circumference = $diameter * M_PI; echo ("<tr> $circumference </tr>"); $radius = $diameter/2; echo ("<tr> $radius </tr>"); $area = pow($radius,2)*M_PI; echo ("<tr> $area </tr>"); echo ("</td>"); } ?> </table> </body> </html> and in fillarray.inc I have: $totalnum = rand(0,25); $arr = array(); for($i=0;i<$totalnum;i++){ $arr[$i] = rand(1,100); } But when I run it, this is the display i get: Any help on whats going on?
  20. Hows it going guys. Well, I'm trying to create an app tat deals with the barracuda API. Unfortunately it uses all XML for its methods, so I had to come up with this: <?php include ("xmlrpc.inc"); $y = new xmlrpcval ( array ("child_type" => new xmlrpcval("domain", "string"), "path" => new xmlrpcval("", "string"),"type" => new xmlrpcval("global", "string")) , "struct"); $m = new xmlrpcmsg ('config.list'); $m ->addParam($y); $c= new xmlrpc_client("http://barracudaaddress/cgi-mod/index.cgi?password=mypassword"); $c->setDebug(2); $r = $c ->send($m); if (!$r->faultcode()) { $v= $r->value(); print $r->serialize(); } else { print "Fault <br/>"; print "Code: ". htmlentities($r->faultcode()) . "<br/>" . "reason: '" . htmlentities($r->faultString()) . "'<br/>"; } ?> the problem is that when I run this, i get the following error: XML error: XML_ERR_NAME_REQUIRED at line 2, column 61Fault Code: 2 reason: 'Invalid return payload: enable debugging to examine incoming payload (XML error: XML_ERR_NAME_REQUIRED at line 2, column 61)' but when i look at my php code, line 2 is technically: include ("xmlrpc.inc"); Does this mean my error is coming from that file? Because as far as I can tell, the XML output is working well, since this is what is getting sent to the server: <?xml version="1.0"?> <methodCall> <methodName>config.list</methodName> <params> <param> <value><struct> <member><name>child_type</name> <value><string>domain</string></value> </member> <member><name>path</name> <value><string></string></value> </member> <member><name>type</name> <value><string>global</string></value> </member> </struct></value> </param> </params> </methodCall> Which is what is required for this method. I've racked my brain and can't figure it out, any help would be appreciated.
  21. Well thats good to know. Removed that, but my problem is still there. the variables aren't passing on. I've put echo statements throughout and even though the procedures are being called correctly, since the variables are empty, it never does a good comparison
  22. I thought that by adding it as the action it didnt occur until it was clicked?
  23. Unfortunately, though that is a mistake that would've popped up in the future. Right now I still have the issue where even though im storing the variables as a session, when I call them (specially the scrambled) in order to be displayed later in the form, it still just appears blank.
  24. Yes, I have a session start at the beginning. Thank you for the point about my array count. And here, i will post my program that way it will be easier to check <?php error_reporting(E_ALL ^ E_NOTICE); session_start(); echo "starting program <br/>"; require_once ("dbconn.php"); $correct = "Your Answer was wrong "; $try = false; $me = $_SERVER['PHP_SELF']; $guess = $_POST['userChoice']; echo '<br/>' . $guess; if (isset($_POST['userChoice'])) { $_SESSION['guess'] = $_POST['userChoice']; $try = check_word($_SESSION['guess']); echo ("<br/>We are into the loop"); } else { echo ("<br/>about to call change word"); changeword(); echo ("<br/> we called the changeword"); } function changeword(){ echo "<br/>starting to change word"; $result = mysql_query("Select words from CurrentWords"); $totalwords = array(); while ($row = mysql_fetch_array($result)){ $totalwords[] = $row["words"]; } $_SESSION['$word'] = $totalwords[rand(0, count($totalwords)-1)]; echo '<br/>'.$_SESSION['$word']; $_SESSION['scrambled'] = str_shuffle($_SESSION['$word']); echo '<br/>'.$_SESSION['scrambled']; echo "<br/>finished changing words"; } function check_word ($guessword){ return strtolower($guessword) == strtolower($_SESSION['word']); } if ($try){ $previous = $word; changeword(); $correct = "Your Previous guess of ". $_POST['userChoice']. " Was Correct For the word ". $previous; } ?> <html> <head> </head> <body> <form name="wordguess" action="Index.php" method="POST"> <table> <tbody> <tr> Try to guess what the following word is: <?=$_SESSION['scrambled']?> <br/> </tr> <tr> Your Guess: <input type="text" name="userChoice" id="userChoice" size="20" /> <br/> </tr> <tr> <td> <input type="submit" name="submit" id="submit" value="Submit"> </td> </tr> <tr> <?=$correct?> </tr> </tbody> <tbody> <form> <input type="button" name="resetpage" onclick="<?php session_destroy(); ?>" /> </form> </tbody> </table> </form> </body> </html>
  25. Thank you. i thought the ID part was taking care of that. I am fairly new to PHP, and Im trying to set this game up as a way to learn the concepts. I'm having an issue that once again I can't really figure out how to fix. I have this code: if (isset($_POST['userChoice'])) { $_SESSION['guess'] = $_POST['userChoice']; $try = check_word($_SESSION['guess']); echo ("<br/>We are into the loop"); } else { echo ("<br/>about to call change word"); changeword(); echo ("<br/> we called the changeword"); } I set the variables here: function changeword(){ echo "<br/>starting to change word"; $result = mysql_query("Select words from CurrentWords"); $totalwords = array(); while ($row = mysql_fetch_array($result)){ $totalwords[] = $row["words"]; } $_SESSION['$word'] = $totalwords[rand(0, count($totalwords))]; echo '<br/>'.$_SESSION['$word']; $_SESSION['scrambled'] = str_shuffle($_SESSION['$word']); echo '<br/>'.$_SESSION['scrambled']; echo "<br/>finished changing words"; } based on that, I have this: function check_word ($guessword){ return strtolower($guessword) == strtolower($_SESSION['word']); } The form is the same. Now, when i click submit and the page reloads, even though I've set the variables as a session. They still dissapear when I go to check the word, so I'm always getting a false. How can I fix this? Thanks, GoodVibe
×
×
  • 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.