Jump to content

gamblor01

Members
  • Posts

    73
  • Joined

  • Last visited

Everything posted by gamblor01

  1. Hi all, Does anyone know of a good way to track the events that get fired inside of a page? I am working on something at work and I'm not sure if I have discovered a bug in Chrome or not. The problem ONLY occurs in Chrome (and Chromium) on Linux -- when running Chrome in Windows it does not occur. We have an event handler and I am showing the events that we are receiving in a div. We are overriding the default right-click menu in the browser, so when you right-click you will not see the options "Back, Forward, Reload, etc." Instead you see our own context menu. The crazy thing is that in Linux, if you click near the top of the screen, the context menu will open BELOW the current location of the mouse pointer and the mouseup event fails to fire. If you click low enough on the screen such that the context menu must open above the mouse pointer, then mouseup fires correctly. Also, I have noticed that blur isn't always being called correctly, so in a special admin mode that we have, the context menu will open but never gets focus. Thus, the element BEHIND it (which was the element where the right-click was executed) is still in focus and you can drag it around the page. I think that ultimately I need to report this to Google as a bug but first I need: a) a simple example (since they obviously won't have access to our application) -- this is something I have to come up with on my own b) a simple way to show the events being fired in the browser (since my current example requires use of my application which again -- developers won't have access to) Is there an extension I can run or something in the dev tools that can show the events being processed? Thanks!
  2. Hmm...well I sort of got things working by using dojo. The following works to dynamically load the external .js file: function addJavaScriptFile(path) { dojo.io.script.get ( { url: gpsGateURL, load: function() { // signal that this has been loaded already gpsGateLoaded = true; } }); } However, it turns out my isReachableURL() function (which was previously commented out) doesn't work. Apparently this is due to the same-origin policy: http://stackoverflow.com/questions/5573360/test-url-availability-with-javascript This is a bit of a bummer because I'm not sure how to solve this yet. I can't let the server test for the existence of the URL because the whole point is that the URL is local to the client (i.e. localhost is the client system and *NOT* the server). GpsGate retrieves coordinates and then outputs that information to the "browser". This allows client systems to have an attached GPS and our system to show their coordinates. If the GPS were attached to the server then it would be pointless -- it would show the server's location and not the end-user's location. I was originally trying to test for the existence of the URL on the server side (in Java) until I realized that it was always returning false because GpsGate wasn't running on the server. I'm not sure how to solve this problem yet.
  3. Hi all, I have done some search on the net and found some solutions to dynamically load up JavaScript files. It looks pretty simple, just reference the HEAD element of the document via DOM and append a child. I only want to do this in the case that a particular JavaScript file is available, and I believe I have an AJAX solution do that. Here are the two functions that I wrote: function isReachableURL(url) { var request = false; if (window.XMLHttpRequest) { request = new XMLHttpRequest; } else if (window.ActiveXObject) { request = new ActiveXObject("Microsoft.XMLHttp"); } if (request) { request.open("GET", url); if (request.readyState == 4 && request.status == 200) return true; } return false; } function addJavaScriptFile(path) { var fileRef = document.createElement('script'); fileRef.setAttribute("type","text/javascript"); fileRef.setAttribute("src", path); fileRef.setAttribute("id", gpsGateDomId) document.getElementsByTagName("head")[0].appendChild(fileRef); } Armed with these two functions, I can test for the existence of .js file on an external server and reference it if it's reachable. The reason I am doing this is to facilitate some GPS functionality in the application that I work on. We are relying on a program called GpsGate to gather coordinates from a USB/bluetooth GPS device. GpsGate works by launching a small HTTP server that hosts some JavaScript files, and via cross scripting you can obtain your position, altitude, etc. More info can be found here: http://forum.gpsgate.com/topic.asp?TOPIC_ID=6102 Their server is ALWAYS at http://localhost:12175/javascript/GpsGate.js -- assuming that GpsGate is running of course! So my goal is to add a script tag to my page that references http://localhost:12175/javascript/GpsGate.js as the source. In fact, I did this and all of my code works fine. The problem is, for users that do not have GpsGate installed, the browser will output an error that it was unable to load that JavaScript file. For example, if you go into the developer tools in Chrome (CTRL+SHIFT+I) and look, there will be an error that says: GET http://localhost:12175/javascript/GpsGate.js undefined (undefined) Of course other developers are complaining about this and our users will no doubt complain eventually as well. So instead of placing this file into the HEAD tag of the page every time, I want to append it dynamically (only in the case that the user has chosen to do something which involves GPS). I am able to dynamically add the child element to HEAD -- I see it get added in Chrome's debugger if I inspect the children of document.getElementsByTagName("head")[0]. However, it still seems that the typeof(GpsGate) is undefined. If I'm understanding correctly, the SCRIPT tag seems to be getting appended under HEAD, but it's almost as if that script is never executed. Do I need to do something special for that script file to execute after appending it in the DOM tree? If it helps, here is the script file that I see when I hit http://localhost:12175/javascript/GpsGate.js in my browser. It's some strange anonymous function syntax that I'm not familiar with in JavaScript. Any body know what to do to get this function to execute in JavaScript after appending the SCRIPT tag in the DOM tree? I added an alert() in this script to see if it would print anything when I added it in the DOM tree and it did not -- reinforcing the idea that it's being appended in DOM but never executed. If I add the script manually into the HEAD tag then it does show my alert box. // // Copyright Franson Technology AB - GpsGate.com // franson.com - gpsgate.com // (function() { if (typeof(GpsGate) == 'undefined') { GpsGate = {}; } var _url = 'http://localhost:12175/gps'; var _scriptCounter = 0; function buildQueryString(params) { var strParams = ''; for (prop in params) { strParams += '&' + encodeURIComponent(prop) + '=' + encodeURIComponent(params[prop]); } return strParams; } function xssCall(methodName, params, callback) { var id = _scriptCounter++; var scriptNodeId = 'GpsGateXss_' + id; var poolName = methodName + '_' + id; GpsGate.Client._callback[poolName] = function(/*arguments*/) { var scriptNode = document.getElementById(scriptNodeId); scriptNode.parentNode.removeChild(scriptNode); delete GpsGate.Client._callback[poolName]; scriptNode = null; callback.apply(this, arguments); }; var callUrl = _url + '/' + methodName + '?jsonp=' + ('GpsGate.Client._callback.' + poolName) + buildQueryString(params); var script = document.createElement('script'); script.type = 'text/javascript'; script.id = scriptNodeId; // script.charset = 'utf-8'; // necessary? var noCache = '&noCache=' + ((new Date()).getTime().toString().substr(5) + id); script.src = callUrl + noCache; // todo: use this method on non-conforming browsers? (altough both IE6 and PC-Safari seems to work anyway) // document.write('<script src="' + src + '" type="text/javascript"><\/script>'); document.getElementsByTagName('head')[0].appendChild(script); script = null; } // API GpsGate.Client = { Copyright: 'Franson Technology AB - GpsGate', getGpsInfo: function(callback) { xssCall('getGpsInfo', {}, callback); }, getVersion: function(callback) { xssCall('getVersion', {}, callback); }, // ----- _callback: {} }; })();
  4. Putting the script in your crontab probably isn't working because the script was never marked as executable. You need to run the ls -l command on the file to see what the permissions are. If you don't know how to read the output then see these two entries: http://en.wikipedia.org/wiki/Ls http://en.wikipedia.org/wiki/File_system_permissions#Notation_of_traditional_Unix_permissions You'll probably need to run the chmod command to make it as executable (either for your user, or for everyone). The easiest way to do this is to simply run: chmod +x your_file_name You should also but the interpreter that you want to be used at the top of your script. For example, if you want it to be executed by Korn shell you should put something like: #!/bin/ksh For BASH it would be: #!/bin/bash In any case, if you get the cron job working with your script then it's going to constantly create those files but never delete them. Here's a little script that might help with that. First it will determine today's date, and then it will backup your database with the date in the filename. Finally it will look through the directory for files older than 7 days and delete them. Thus -- you always keeps the most recent week of files. If you want to keep 2 weeks worth of files, change the argument in find from -mtime 7 to mtime 14. #!/bin/bash -x backupDir=/home/myrefco/db # backup the database myDate=$(date '+%Y-%m-%d') dbName=db-$myDate.sql cd /tmp mysqldump -u root -ppassword database_name > $dbName gzip $dbName mv $dbName.gz $backupDir # delete anything older than 7 days find $backupDir -mtime +7 | xargs rm -rf I haven't thoroughly tested it so you should before using it. I'm pretty sure it will work but run it by hand and maybe even add the -x option (#!/bin/bash -x) so that you can see exactly what it's doing as it runs. Have fun.
  5. There are a few things you need to change. Not only do you need to change the name of the form from #form to submit, but you also need to invoke the AJAX code. He's using JQuery -- essentially a Javascript framework -- which (I don't think) is as straightforward as Javascript, but it's incredibly powerful with very little code. The basic idea behind AJAX is quite simple: - You create an XmlHttpRequest object - You submit the HTTP request via GET or POST - The server performs some processing and returns the result to the client - Your client does something with that response, which is generally to update the content of the page with information in the response In order for this to work however -- I think you need to do all of this through javascript. I think the reason that your page is redirecting is because you have defined the action of the form to redirect to "someautoresponderservice". Instead, what you need to do is get rid of that action there, and then update your function called by onSubmit to handle everything for you. The only bummer is that you will need to pass all of the values of the form as arguments which is a bit of a pain. It would look something like this: <form name="signup" id="signup" onSubmit="return checkSub(this.signup.action, this.signup.member, this.signup.auto, ..., this.signup.email)"> I can provide code if you want, but I think there is probably a better way to do this. Anyone else care to comment?
  6. I'm not sure if it's possible to reload an iframe or not. However, one thing you could probably do is to add a div tag to every iframe that you have. You might be able to put the ajax code in the "parent" page and then have it refresh the content inside of the div tag in the iframe. Of course, the ENTIRE content of the iframe would just need to be contained inside of that div tag. Try putting this javascript into your parent page: <script type="text/javascript"> var xmlhttp; function reloadIframe(page) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Sorry but your browser does not support AJAX or Javascript has been disabled"); return; } // append an random value to the page being called // to prevent browser caching var url = page + "?id=" + Math.random(); // execute the fully formed request xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("iframeContent").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } </script> In this example all you have to do is put a div tag with the id "iframeContent" in your iframe page (let's call it foo.php) like this: <?php echo "<div id=\"iframeContent\">\n"; // the page content goes here echo "</div>\n"; ?> Then your button should invoke the javascript function with the name of the target page. Something like: echo "<a href=\"javascript:reloadIframe('foo.php')\"><img src=...></a>\n"; Does that work? I dunno...I don't mess with iframes usually.
  7. Cool I didn't ever even think about checking if status==200 but that's a great idea! I learned something new! I was however, trying to make the code as simple as possible, just to illustrate the basic idea. That's cool -- switching between GET and POST is really pretty simple. I posted a thread on it a while back: http://www.phpfreaks.com/forums/index.php/topic,288125.0.html
  8. Hmm...what you are doing sounds a lot like something that I got working a while back. In my case I was specifically trying to get a table to reload without reloading the entire page, though reloading the entire page is certainly similar. What you need to do to is use the confirm() function in Javascript and save its return value in a variable. Then you can just test if the variable is true. If so then submit the form. You don't even need an else statement (which would just "do nothing" anyway). I have the code skeleton posted here: http://www.phpfreaks.com/forums/index.php/topic,287155.0.html In that post I actually do use an else statement to "do nothing" but that is only because the GET request is made outside of the entire if/else structure (so that I didn't have to repeat code inside of both the add and the delete sections). Are you sending a GET request or a POST request? If it's GET then you can essentially just copy my code and move things around so that it looks like this: <script type="text/javascript"> var xmlhttp; function deleteUser(user) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Sorry but your browser does not support AJAX or Javascript has been disabled"); return; } var doAction = confirm("Are you sure you want to delete id #"+user+"?"); if (doAction == true) { // we're deleting so append userID in the GET request var url = "deleteUser.php"; url = url + "?delete=" + user; // execute the fully formed request xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } } function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("myTable").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } </script> Then your backend script (in this case I have called it deleteUser.php) can simply check the value of $_POST['delete']. If it's not empty then delete the user from the DB and redirect to the page that displays the table of users.
  9. It's not really clear to me what you want to populate. I see the option in your form named chair but then you say it needs to populate the toto field and I don't even see that anywhere. I would suggest you start with the tutorial on w3schools here: http://www.w3schools.com/php/php_ajax_database.asp It demonstrates using AJAX to invoke a PHP script that returns data from a table in MySQL. It even matches up with what you are trying to do which is to change the output based off the selection of a downdown menu! Do you have something that is successfully returning value from PHP/MySQL already? If not, I suggest you get a simple example working. Then we can tweak it to do what you want.
  10. Hashing passwords is better than using them directly, but even better than that is to apply a salt and then hash. This way, 2 identical passwords will not be hashed to the same value (unless the users both have the same salt or there is a collision in your hash function, which is unlikely with good hashes such as md5 or sha1). I use a salt in my code: // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect against MySQL injection $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername'"; $result=mysql_query($sql); // mysql_num_row counts the number of rows returned $count=mysql_num_rows($result); // If result matched $myusername, table row must be 1 row // This means that the user exists in the database if($count==1) { // check the password $row = mysql_fetch_array($result); $storedPassword = $row['password']; $salt = $row['salt']; $encrypted_mypassword=md5($mypassword.$salt); if ($encrypted_mypassword == $storedPassword) { // do whatever you want first and then redirect to login_success.php header("location:login_success.php"); } } When a new user is created I simply generate a salt for them as a random number and then store that in the table with the rest of their information.
  11. Wow...indeed. I just read through it more thoroughly and realized there is a much simpler way to accomplish this than my script...as long as the ordering of the lines doesn't matter. Just use sed to delete the appropriate line from the file with a regular expression and then append the new line with a >> redirect. This makes for a much simpler 4 line solution. mv config.txt config.back sed -e '/^maxplayers/d' config.back > config.txt rm config.back echo "maxplayers $newPlayerCount" >> config.txt
  12. Sed is probably a great way to go. One thing you could do is to grep through the file for the attribute that you are looking for (for example, maxplayers) and then use cut or awk to get the value. If you're going to use cut then you might want to use "tr -s" first...just to compress all of the space characters into a single space. Taking your example you could use either one of the examples below: $ grep "maxplayers" config.txt | awk '{print $2}' 25 $ grep "maxplayers" config.txt | tr -s ' ' | cut -d ' ' -f 2 25 Now that you have that value, you can use it along with the name of the attribute to do a substitution (maybe even do it globally? Though I doubt that is necessary). You probably don't want to substitute just the value by itself, otherwise you might wind up changing other attributes that just happen to have the same value (which isn't what you want to do). Here is a quick shell script that works: #!/bin/bash confFile="config.txt" confBack="config.back" attribute=$1 newValue=$2 mv $confFile $confBack oldValue=$(grep "$attribute" $confBack | awk '{print $2}') oldString="$attribute $oldValue" newString="$attribute $newValue" sed -e "s/${oldString}/${newString}/" $confBack > $confFile # optional -- delete the backup file rm $confBack You can try it out for yourself: $ cat config.txt hostname Example port 7777 maxplayers 25 $ ./update.sh maxplayers 30 $ cat config.txt hostname Example port 7777 maxplayers 30 Perhaps not the most elegant solution but it definitely works!
  13. The easiest way to do this is going to take the combination of some javascript code, an additional div tag to your page, and a php script. You should start with some simply AJAX example. w3schools.com has a great tutorial for AJAX. I will give you a skeleton though. It should take the following changes below. You will need to fully implement getShipping.php however. 1. Start by defining the getShipping function in Javascript. This will probably reside in <script> tags in the <head> of your document: function getShipping(state, zip) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Sorry but your browser does not support AJAX or Javascript has been disabled"); return; } // we want to invoke getShipping.php var url = "getShipping.php"; // append the values from the form url = url + "?state=" + state; url = url + "&zip=" + zip; // execute the request xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("shippingCost").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } 2. Update your HTML so that it contains the div tag "shippingCost" and will therefore be updated once the AJAX request returns: <td align="right" width="148" bgcolor="#CACBCB"> <font color="#000000" face="Verdana" style="font-size: 8pt">S&H Subtotal:</font> </td> <td align="right" width="87" bgcolor="#CACBCB"> <font color="#000000" face="Verdana" style="font-size: 8pt"><b><div id="shippingCost"></div></b></font></td> <input type="hidden" name="shipping" value="0"> <td width="72" bgcolor="#CACBCB"> </td> 3. Update your form so that the "calculate" button calls the getShipping function: <br><br><input type='submit' value='Calculate' onClick="getShipping(this.form.tostate.value, this.form.tozip.value)"></td> 4. Finally, define the getShipping.php file that AJAX is calling. Here is a very simply example -- you should modify it to suit your needs and reflect a more real-world example: <?php $state = $_GET['state']; $zip = $_GET['zip']; if ($state == "HI" || $state == "AK") { return 8; } else if (substr($zip,0,3) == "787") // always ship free to Austin, TX { return 0; } else { return 5; } ?> Try it out and see if it all works. Let me know! It should work and populate the div tag with the shipping cost once you have selected a state/zip and pressed calculate. You will still need to retrieve this value and add it to the subtotal to update the total cost though. That is left as an exercise for the reader!
  14. I think the best way to accomplish this would be to perform an AJAX query (looks like you already knew that though). The easiest way to do this is to probably just modify the PHP code from earlier and just have it echo the total num rows that it finds ( "1" if the username exists, and "0" otherwise). I don't think you want to select count(*) and then call mysql_num_rows on that...otherwise you are ALWAYS going to get one row back -- the row that tells you how many rows are in the table. Anyway, let's assume you put this code into a file called checkUser.php: <?php // db connection info here // get the prefix and cusername out of the request $prefix = $_GET['prefix']; $cusername = $_GET['cusername']; $sql="select * from ".$prefix."users where username='$cusername'"; $result=mysql_query($sql, $db); $total=mysql_num_rows($result); echo "$total"; ?> Now just write a very simple function in AJAX (which can be copied into your existing Javascript code) to invoke that PHP page and retrieve the value: <script type="text/javascript"> var xmlhttp; function checkUser(prefix, cuser) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Sorry but your browser does not support AJAX or Javascript has been disabled"); return; } // call the checkUser.php script var url = "checkUser.php"; // append the prefix and cusername url = url + "?prefix=" + prefix; url = url + "&cusername=" + cuser; // execute the fully formed request xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged() { if (xmlhttp.readyState==4) { return xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } </script> Inside of your own Javascript code you can just do something like: var userExists = checkUser("foo", "bar"); if (var == 1) { // username already exists! } else { // allow the creation because the user doesn't exist yet } Something like that should work.
  15. Someone else just asked this very same question a few days ago: http://www.phpfreaks.com/forums/index.php/topic,292404.0.html You can look at that post and see my response or you can go directly to the thread that I started about this: http://www.phpfreaks.com/forums/index.php/topic,287155.0.html
  16. When these sorts of "mysterious" errors happen, it's almost always caused by some erroneous quote somewhere (or curly brace, etc.). What happens is that it causes the interpreter (or compiler -- depending on the language/case) to expect that one particular code construct has begun. It may be the case that it expects the construct to end on the next line of code, or 15 lines of code later. Who knows. Take a look at the second line in your if statement. You appear to have a random backtick at the very end of the line. There is a semicolon, then a space, and then a backtick: $update2 = mysql_query("update `users` set unread_mail='$mail' where `id`='$user->id'"); ` php is probably expecting you to close that backtick at some point in time later and that is why it complains about the seemingly unrelated line. Also, I'm not really sure why you have the backticks around users and id. I don't think they are necessary are they? You might want to change that line of code to this: $update2 = mysql_query("update users set unread_mail='$mail' where id='$user->id'");
  17. There are a few things you can do here. You could add a field to your table that defines "admin" users. This is exactly what I did with a simple application that I wrote: mysql> describe members; +----------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | username | varchar(32) | NO | UNI | NULL | | | password | varchar(64) | NO | | NULL | | | salt | int(11) | NO | | NULL | | | isadmin | tinyint(4) | YES | | NULL | | +----------+-------------+------+-----+---------+----------------+ Only admin users would have access to the page. Therefore, when someone attempts to view that page, you first check if they have a valid session (which you have already done by adding the code I previously told you to add to the top of the page). If so you pull out their username and then check the users table in your database to see if this user has admin access. If so, you display the page, otherwise you just ignore the request and redirect them back to the main login page or whatever you want. If you want to see exactly who has visited the page you could always write a log. Everytime someone hits the page you take their username and append it to a file. You could then employ the above logic to see whether or not you should display the form or redirect them elsewhere. This way you see who hit the page...whether they were supposed to or not. To make things even more difficult, when the form is submitted, you could check one last time to be sure that the user is valid and an admin. If so, allow the action to proceed -- otherwise do nothing and redirect: if ($action == "add" && $_SESSION['isadmin'] == 1) { ... } else if ($action == "delete" && $_SESSION['isadmin'] == 1) { ... }
  18. On the other hand a sledgehammer would do fine to. Hey it could be a valid solution...kratsg never posted what this application was going to be used for. Maybe it is something internal to his/her company, only to be accessed from the internal network. If that is the case then a firewall solution would work just fine. We do that sort of thing all the time (though to be fair, everything of value is password protected as well).
  19. There are a few things I can think of: 1. Run your HTTP server on a system that is behind a firewall (and port 80 is blocked) 2. The next best thing I can suggest is to use sessions in your PHP code and force a user to be logged in before being able to access the form. For example, you create a login page such as index.php. This redirects to another page (possibly the one with your form) upon successful login. In any case, any page you want to "protect" with this login feature (i.e. any page that is only supposed to be accessible after a successful login) should have the following code at the top: <?php session_start(); if(!isset($_SESSION['myusername'])) { header("location:index.php"); } If anyone attempts to view this page without a valid session they will be directed back to the login page named index.php. For an unauthorized user to view a page like this, they would need to either break into an account or spoof a session. 3. I'm not sure what type of request you perform in your AJAX code to send the form data to your backend PHP script. Is it a GET or a POST? If it's a GET then it is very simple to create the string and append the values at the end of it using ? and & like this: http://www.yourwebserver.com/foo.php?action=delete&target=all You can type in a string like this directly into the URL bar of a browser and it will execute the GET request. If you are using GET then you might consider changing it to a POST instead. It is a little more difficult to send POST parameters, particularly in a browser. You can pretty easily do it using examples on google and minimal knowledge of programming languages (Perl LWP comes to mind). Again however, if your backend PHP script requires a session then executing the POST will not work unless the person has learned credentials for a legitimate account or can spoof a session somehow.
  20. There is a function called from_unixtime() in MySQL. You can use this to convert a Unix timestamp to the 'date' datatype. Then just wrap that with a call to the month() function: mysql> select from_unixtime(1268837244) as date; +---------------------+ | date | +---------------------+ | 2010-03-17 09:47:24 | +---------------------+ 1 row in set (0.00 sec) mysql> select month(from_unixtime(1268837244)) as month; +-------+ | month | +-------+ | 3 | +-------+ 1 row in set (0.00 sec) Ignace's answer is almost exactly what you need. Just modify it to use the from_unixtime() function and it should work. Try something like this: select * from articles where month(now()) = month(from_unixtime(date));
  21. I started a thread that discussed exactly this scenario. Check it out here: http://www.phpfreaks.com/forums/index.php/topic,287155.0.html Basically is uses ajax to populate the contents of a div tag on the page. There are basically 3 actions: 1. add 2. delete 3. everything else (which just means to draw the table without adding or deleting anything from it) If you add a user, then it updates the MySQL table and then refreshes the table in the page (without refreshing the entire page). It's almost instant...you fill in the data, click add, and the HTML table gets updated. If you deleted, the same thing happens. All of the code is there for you in that post. Pay particular attention to my final post though...make sure to edit the javascript code and use & instead of ?...it will make parsing the input orders of magnitude easier.
  22. If your Windows computers cannot even create folders there then it's a permissions problem and has nothing to do with Linux (or samba). Go back to the shared drive, right-click and go to "Sharing and Security", and make sure that all of the users have full control (read/write). Get it working from other Windows systems first and then you can try diagnosing issues with samba connections (if necessary).
  23. oni-kun is right...you are going to have to flag the drive as bootable. The easiest way to do this is to just boot up using a live cd (Ubuntu, gparted, fedora, knoppix...any of them will do). You can see what drives the kernel knows about by using: # fdisk -l Use sudo fdisk -l if you're not root (i.e. an Ubuntu live CD). Let's say that your drive is /dev/sda. Then you would need to open it up with something like fdisk (or cfdisk, which is a bit more friendly) to flag it as bootable: cfdisk /dev/sda Even if you make it bootable however, I'm not sure that the program properly copied over your /boot/grub directory properly. If it did and menu.lst is intact, then simply flagging the drive as bootable should work. If not, you're going to have to reinstall grub which you can do by using the grub-install command, or you can go the long way: Put in the live CD and open a terminal. Then run these commands (as root): # grub > find /boot/grub/stage1 This should return something like (hd0,0). You will need this output for the next step. > root (hd0,0) [swap out (hd0,0) with whatever was returned in step 2] > setup (hd0) This will now install grub in your MBR. However, there is a very simple and free way to avoid having to do any of this. Ditch the Seagate DiscWizard program and just use the dd command in Linux. I would recommend doing something like this: 1. purchase a new hard drive (larger than the old one if desired) 2. power down your computer and attach the new drive 3. boot up the system using a Linux live cd 4. locate which drive is which using [sudo] fdisk -l. Let's just assume for this example that you only have one hard drive so /dev/sda is the original drive and /dev/sdb is the new one. 5. as root, copy from the source drive to the new drive: # dd if=/dev/sda of=/dev/sdb bs=32256 6. power down the computer, unplug the old drive, and plug in it's replacement in the appropriate place Now you should be able to boot up your system using the new drive, which is an exact clone of the previous drive. It will copy over the MBR, copy over the information about whether or not the drive is bootable...in essence it copies EVERYTHING. It does a bit-for-bit copy of every zero/one from the original drive to the new one. If the drive is larger then difference will be unpartitioned space. You can either create a new partition, or boot up using something like gparted and expand the size of the original partition to take advantage of that free space. ***WARNING*** By very, very careful about using the dd command. "if" stands for input file and "of" stands for output file. Before you press enter and kick off that command, be sure you have the appropriate drives in the appropriate places! I always read the sentence out-loud to myself: "data dump using input file of /dev/sda and output file of /dev/sdb with a block size of 32256" You can use the output of fdisk -l or a piece of paper to make sure you have the appropriate input and output files. If you swap the order of those (i.e. copy FROM the new drive TO the old one) then you are going to hose yourself and destroy all of the data on your original drive. "bs" is just the block size to use during the copy. 32256 is larger than default and will make the copy go faster. Hope this helps!
  24. Is crond running? I'm not very familiar with CentOS (never used it myself) but it's supposed to be built from the Redhat source code right? Verify that you have the appropriate rpm installed: $ rpm -qa | grep -i cron Apparently you need the vixie-cron package installed. Then make sure that crond is running: $ service crond start You can also check ps output or use service to see if crond is running. Also try running crontab -e and make sure that the commands you put in there are shown.
  25. I don't think it's going to be terribly inefficient just because it makes a few calls to the database, especially because it's all in the same PHP page. If you had multiple pages that kept calling each other then that would mean that you are constantly creating and destroying connections to the database -- which would make it considerably less efficient. However, the queries are all using the same connection and you only have 3 queries in a row. Databases index tables and optimize queries and so forth...I don't think you have anything to worry about. Why do you always append the number 2 though? Why not pick a pseudorandom number to append to the username -- that would be more likely to work without having to add a year or the Unix timestamp. Just do something like: if ($usercount != 0) { // If username exists $rand = rand(1, 4096); // append a 12-bit random number $UNToCheck = $usr_firstName .'_'.$usr_lastName.$rand; Have you tested this code however? I don't have any experience using an AS clause like you did. Instead, I call the mysql_query() function and then I use a call to mysql_num_rows(). For example: // Check for existing username and automatically append things on to the end until a free name is found. $UNToCheck = $usr_firstName .'_'.$usr_lastName; $UNCheck = mysql_query("SELECT COUNT (*) as usercount FROM core_users WHERE usr_username =" $UNToCheck ) or die ('UNCheck failed'.mysql_error()); $mycount = mysql_num_rows($UNCheck); if ($usercount != 0) { // If username exists Your implementation might work...I have just never tried your code so I didn't know it works. Pretty neat if it does though. One final thing you may want to consider is to call stripslashes() and mysql_real_escape_string() if you haven't already. Call that before your SELECT statements against the DB.
×
×
  • 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.