Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. You can't have a user that doesn't have a particular privilege grant itself that missing privilege. You need to use a user which has that ability and the ability to grant privileges in order to grant it. Typically this means you have to use the root user. I'm not that familiar with cpanel but if you can't grant it through there, and don't have direct access to the mysql root user then your host probably doesn't allow that privilege. If you are infact trying to grant a privilege across users rather than the same user (as your code reads), then make sure the source user has all the necessary privileges and the ability to grant.
  2. The anchors go outside of the brackets. Putting them inside makes them additional valid characters rather than anchors. Within the brackets you just add the ranges/characters you want, keeping in mind the comments above. After the brackets you need a repeater in order to allow multiple instances of the characters. + means one-or-more and works well. for example: /^[a-z]+$/ Now just extend that to cover all your characters.
  3. Mine would read as: if (HTTP_HOST matches /(www.)?example.com/ AND (HTTPS=off OR HTTP_HOST does not match /www.example.com/)) redirect The first line limits the rules to only requests for www.example.com or example.com.The second line tests if SSL is not enabled The third line tests if the host is something other than www.example.com (which due to the first condition, could only be example.com) Because the second and third lines are joined with an [OR] tag, if either of them is true (ssl is not enabled OR the host is not www.example.com) it will redirect to www.example.com
  4. When dealing with javascript mixed with PHP, it's best to load up your pages in the browser and then use the browsers view-source function to see what your PHP script generated and make sure the source is output correctly. Also use your browsers javascript console to check for any javascript errors. So load up your page and view-source. Make sure both your script tag importing the js file and the button's onclick attribute calling the function are there. If that checks out, click the button and then check your browsers javascript console for any error messages.
  5. The second argument for RewriteCond is a regular expression, so you just make the www. part optional with a ? quantifier. RewriteCond %{HTTP_HOST} (www.)?domain.com There is a way to join the conditions as an OR however, by specifying the [OR] flag after the condition. With that you can take care of both your ssl requirement and you hostname requirement. RewriteCond %{HTTP_HOST} (www.)?example.com RewriteCond %{HTTPS} =off [OR] RewriteCond %{HTTP_HOST} !www.example.com RewriteRule (.*) https://www.example.com$1 [R=301,QSA,L]
  6. You need a ; after the function definition. An anonymous function declaration is a statement, and just like any other statement, needs to be terminated by a semi-colon. $mo_diagram = function ($matches) { // SOME CODE }; $bbcode = preg_replace_callback($pattern,$mo_diagram,$bbcode);
  7. Change your database structure so you store each number as a separate row, then you can just do a simple select with a group by to find the top numbers. For example, have a table such as: create table draw_numbers ( drawId int , position tinyint , number int ) drawId would link to another drawings table which has a row for each draw. position would be the number position in the draw, eg 1-7 (with 7 being the bonus) and number would be the number drawn With that structure, to get the top bonus number you'd do: select number, count(*) as totalDraws from draw_numbers where position=7 group by number order by totalDraws limit 1 On a side note, I've moved your thread to the PHP Coding help section. You originally posted in the Regex forum but the question has nothing to do with Regex.
  8. Parsing the query text is easy and barely takes any time at all. Executing the query and fetching the requested data is where all the time is spent when running a query. The fewer fields you interact with, the better job the database can do in optimizing the query for execution and data fetching. Say for example you had a table like this: create table blog_posts ( postId int auto_increment primary key , postDate datetime , title varchar(1000) , postContent text , authorId int , index (postDate, title) ) And then on a page you query the table like so: select * from blog_posts where postDate between '2013-1-1' and '2013-2-1' order by postDate And say the page only lists out the titles and dates of the post with a link to each, meaning all you need is the title, postId, and postDate fields By using *, mysql will have to not only pull the needed fields, but also the extra postContent and author fields. Now the author field is probably not a big deal, it's just an int stored with the rest of the data in the row. The postContent field however could be a very large amount of text, and is not stored along side the main row data which means mysql would have to do some extra seeking and jumping around to read out that field, wasting time. All that extra data is then transferred to your app taking up bandwidth and more time, just to be completely ignored. So, lets rewrite the query with only what we need select postId, title, postDate from blog_posts where postDate between '2013-1-1' and '2013-2-1' order by postDate Now mysql will only fetch those three items, not wasting time and resources looking up postContent data. As an added bonus, because the necessary fields are part of an index, mysql can just pull their values directly from the index as it searches for the posts rather than having to refer back to the data table after it has found the required posts. Sending the results back to your app will go much quicker as there is a lot less data to be transferred, and your app will use up less memory not having to read in unnecessary result data.
  9. You should be listing out your columns anyway and not using * at all. For a few reasons, namely: 1) The less data you select the better. The DB may be able to better optimize the query or spend less time gathering results if it has less columns to fetch. Also less time/memory is wasted transferring the result back to the application. Select only what you need 2) Listing the columns means you know just by looking at the query what columns are available in the results and what their names are. By using * you have to either memorize that or always refer back to the table structures. The ` are not necessary unless you are attempting to use a reserved word. If you are, I would recommend you change the column name rather than work around it with backticks. Not having to constantly quote everything makes it much nicer when writing queries out.
  10. If you have stuff in a directory that you do not want to allow the general public to access, then you should just deny access to the whole directory, or better yet store that stuff outside the webroot so it's not accessible via apache at all. If you have a certain selection of uses that may need to access stuff within that directory, then you create a gateway script in PHP which will verify the user and then serve up the data. That way someone can't just bypass your PHP script and access a file directly should they know the URL.
  11. At the end of the script. Either that or move your connection opening so that it is inside the processing of each request. Right now you are opening a connection to your DB server once before starting up your HTTP server, but you're trying to close the connection to the DB server after each request. 1 open + many closes doesn't match up. I've not used node.JS so I can't really tell you which method of fixing the problem is better, connecting per request or not disconnecting til the end. I'd suspect not disconnecting would work ok, however you will need to make sure you account for the fact that the connection to your server may die between requests and handle that gracefully (eg by attempting a re-connect or spitting out an error page).
  12. Map looks fine to me if I stick your code into a jsfiddle. Going to have to be more descriptive of your problem, and make sure you are giving us the proper code to reproduce the problem.
  13. Did you join one of the three defined rooms, or try and join something else? The server is setup so that only the pre-defined rooms are available. Trying to join any other room will result in the banned message.
  14. Have you tried downloading these URL's without apache or PHP in the picture? Use the cURL command line client or wget to download them from the command line. If those tools also fail, then you maybe a looking at some kind of IP block or routing issue. If they work however, then you have an issue either in your code or in your PHP/Apache setup.
  15. Yes, player B will be able to load all their settings. Just because a program has a connection open to the database does not mean the database is inaccessible to anyone else. In order to make a table inaccessible to others, you have to acquire a LOCK on the table, which is unnecessary for read-only operations like a SELECT statement. Unless you intentionally code your program to acquire a lock in such an instance, none would be acquired and thus not block anyone else from that table. Now, a write statement such as the UPDATE statement to change their scores will acquire a lock on that table (or row, depending on table type) which would prevent anyone else from accessing that table. However, the lock is only active for the duration of the UPDATE statement, which should be just a few milliseconds so at worst if two people tried to update at the same time, one of them would just have to wait for a few milliseconds before their update goes though. There are ways to manually control table locking however unless you know exactly what you are doing and why, you should just let the database handle the locking implicitly as it processes your normal SQL statements. Failing to handle locking properly can result in exactly the situation you are concerned about where a user would not be able to access the DB while another person is using it. What you have is the proper way of accessing the column's value. Make sure you have everything spelled properly and the case is correct. An aliased column is accessed the same way as any other column, you just use the alias name as the column's name.
  16. It depends on what your needs are. A single interface can have multiple IP's assigned to it, however they must all be part of the same network, eg: 192.168.0.10, 192.168.0.11, 192.168.0.12, etc. If you need IP's on different networks then the need to have to separate interfaces, one connected to network A, the other to network B. Whether you even need multiple IP's also depends on you are doing. For web hosting you generally do not need a separate IP for each site, you just use one IP and name-based virtual hosting.
  17. Just pre-fill the name and email fields when you print the comment form rather than trying to figure out how to replace the variables. If you want to prevent a logged in user from modifying their name/email then just remove those fields when they are logged in and only show a comment field, then when you post the comment check if they are logged in and if so, use their name/email
  18. No, use json_encode when outputting information to javascript. Change the getWord function so that rather than searching a prefix, it search a substring. To do this you need to use the string.indexOf method.
  19. while ( $byte=fread($fh,1) && $byte!=";") That condition is being evaluated as: $byte = (fread($fh,1) && $byte != ";"), in other words $byte is being assigned the result of the && operation, which is a boolean true/false. This is because && has a higher precedence = and is evaluated first. You need to change the precedence using parenthesis so that the assignment happens first: while (($byte=fread($fh,1)) && $byte != ";")
  20. Most likely because your servers have different PHP version. Accessing an array element directly from a function return value is a new syntax that requires 5.4 or newer. //Requires PHP 5.4 $issue = $get_issue_info->fetch()['issue']; //For older versions $issue = $get_issue_info->fetch(); $issue = $issue['issue'];
  21. I didn't say it'd have better performance, I said it'd probably be just as good (though it may be better). In any event the performance difference between your messy binary system and a plain text system is probably so minor that it's not even worth mentioning. A plain text system would be far easier to code however and much more readable. You could make things even simpler by letting PHP do a lot of the work and just used a stored array and include(). I've done this for a number of small lists or configuration files: function checkIP($ip){ $ipList = include('ips.php'); return in_array($ip, $ipList); } function addIP($ip){ if (checkIP($ip)) return; $ipList = include('ips.php'); $ipList[] = $ip; file_put_contents('ips.php', '<?php return '.var_export($ipList, true).';'); } See how much simpler that code is?
  22. Sounds like a mod_security problem, check around your tools to see if you can disable it at all.
  23. Are you talking about the BOM mark being the corruption, or the fact that all your null characters disappear? I may have mis-understood your initial post. fwiw, the comments over on devshed about this being a fairly dumb thing to do just to store a list if IPs are accurate. With your fairly limited list of IP's you could just store them one per line or similar and be done with it without having to futz around with all this binary reading/writing/seeking etc. Your code would be drastically simplified and perform just as well.
  24. Yes, you should. You need to define it as a parameter when declaring the function (as you did with function show_users($connection){) and you need to actually pass in the value at the time you call the function (as you showed). The errors you posted are caused by you forgetting to actually pass in the value when calling the function.
  25. They probably have some kind of torrent downloading application running which they can programatically add torrents to, such as the transmission-cli torrent app. Their PHP scripts would just take the .torrent file and queue it up into transmission by running the appropiate command using exec. They could track the status of the download by issuing other status/information commands and parsing their outputs.
×
×
  • 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.