-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
What kind of error did you create? Some errors are not catchable via PHP code so a custom error handler for error logging would not trigger for them. This includes a Parse error for example, as if PHP cannot parse the file there is no way for it to run it in order to execute the error handler function.
-
Your code does not generate the BOM mark when I try it, and I see no reason why it should. I'd suspect you are somehow modifying the file after the fact, such as by opening it in an editor that automatically adds the BOM. on a side note, your loop in the reset method could be simplified into $t = str_repeat(chr(0), $this->bufferSize);
-
The rolling_curl function you showed above does not use the return value of the callback in any way, so a return true is unnecessary and adding it would have no effect on the outcome of the script. You said you were seeing "failed" for each of the requests. Given the code you showed, the only way that would appear is if the $info['http_code'] value was for some reason not equal to 200, which is why I suggested you check that. Assuming the dump you posted and the source of rolling_curl are accurate then the value is 200 and you should not be seeing a failed message cURL can process however many URLs you need, especially with the rolling method where only a certain number of urls are active at a given moment. The only factor is how long it takes to process them, which is pretty much completely dependent on - the network connection to the server - how many parallel requests the remote server allows/can handle - the time your processing function takes to complete. The first two items you have essentially no control over, you are just at their mercy. The last item you can look into and try to optimize as much as possible, for example, use a multi-row insert when adding the data to your DB rather than one query per data item. Each individual curl request should behave very similarly yes, but when you are trying to perform several requests all at once you may run into issues caused by either network issues or the servers. For example the server may be setup to only allow a certain number of concurrent connections per IP (or in general) which means if you exceed that number then you'll be waiting for one to process before starting downloading the next item.
-
Your rolling_curl function is checking for a 200 status code, while your other function is not. To start debugging, I'd suggest dumping the $info variable in your rolling_curl variable to see what sort of data it contains. Perhaps the server is sending back some other status code with the work orders that is causing it to fail.
-
How do I limit my ctype_alnum validation
kicken replied to IlaminiAyebatonyeDagogo's topic in PHP Coding Help
Then what characters do you want them to use? You know alpha-numeric covers A-Z and 0-9 right? So if you disallow it you restrict people to international or symbol characters. I'm going to run on the assumption you mean you want users to only use alpha-numeric characters, in which case you'd do: if (!ctype_alnum($_POST['username'])){ echo "You may only use alpha-numeric characters"; $staff=false; } If you want the same restriction on the password, you'd do the same check. If you don't want the restriction then do nothing. Right now your only restriction on the password is that it is not empty. -
In order for the message to be parsed as HTML, you need to set it's Content-type header to text/html. You can do this using the fourth parameter of the mail function. As a rule of thumb, you should also send a plain-text copy of your emails if you send a HTML message. That way people who cannot or choose not to receive HTML based email still see a readable message rather than a bunch of HTML garbage. In order to do this though you need to generate a proper MIME message with the correct headers and body structure. If you ever want to add attachments you'll need MIME as well. It's better to just use a mailing library rather than try and handle all this stuff (and more) yourself. A couple popular libraries for PHP are Swiftmailer and PHPMailer. Check those out, see which one you prefer and use it. Or as you mentioned, just use a third-party to do your mailing, which may open up more features such as tracking.
-
mysqli_connect doesn't use the include file. You just define your credentials in the include file as either variables or constants and then use those in your mysqli_connect line, eg: dbconnect.inc.php <?php //Note that you need the opening PHP tag in your include files. $db_user='someuser'; $db_pass='theirPass'; $db_database='theDatabase'; $db_host='localhost'; otherFile.php <?php include 'dbconnect.inc.php'; $dbc = mysqli_connect($db_host, $db_user, $db_pass, $db_database); You could include the mysqli_connect line within your dbconnect.inc.php file so that you only have to include the file, not call mysqli_connect as well. If the extension is .php, then the only way a user would see your credentials is if a) You somehow output them (echo, var_dump, etc) or b) The server is not configured properly and does not parse .php file If the file was given a .inc extension, and the server was not configured to parse .inc as PHP (which is typical) then any request to the file would just result in the file either being displayed or offered for download, either of which reveals your credentials. The best thing to do is store your include file containing the credentials outside of the document root so that it is impossible for anyone to even try to request it via the webserver. Some hosts allow this kind of setup, some don't. You'd have to ask your host for the details. If you have to store the file within the webroot, it's best to use a .php extension so that if it is requested, the user will likely just get a blank page. You can message me if you wish. You should try posting to the forum first though, as someone else may be able to help you before I see the message.
-
It's better to use var_dump to check what the values of your variables are, incase there is any implicit conversion going on when echoing that is making them appear to match when they don't. It'll also help you detect things like extra spaces/characters at the start/end of a string. Before your if add var_dump($str , $time_now , $row->register , $auto_close_reg);so you can see the true values of each of the variables in your condition.
-
If the app is something which should only be accessible from within the office, then you could just setup your server to only listen to LAN addresses and not any public addresses. Then the app would only load for someone who is on the local LAN at the office. If you are not getting the IP you expect from the code above, then you are accessing the server indirectly in someway, either via a proxy, ssh tunnel, vpn, etc. Depending on what is inbetween, you may or may not be able to get the original IP address.
-
Adding a query parameter is enough. What you need to change is the URL used to reference the file so that it appears as a different URL to the browser, forcing the browser to re-download it. Changing the actual file name is not required. Expires is the name of the actual header used in the HTTP response to indicate when the resource expires. ExpiresByType is a configuration directive for apache that you use to define what the Expires header should be for files of a given type.
-
Your second condition is using $row->register, not $post->register. Not sure if that is intentional or not, but guessing not since you never mention $row->register anywhere else.
-
You can either use the ternary operator to do an in-line condition, or just split the return across two branches of a normal if/else. if ($a > $b){ return 'a is bigger than b'; } else { return 'a is less than or equal to b'; } or return ($a > $b)?'a is bigger than b':'a is less than or equal to b';
-
What you should be doing instead is have a separate table with one row per delagate. eg: create table delegates ( delegateId int not null primary key auto_increment , name varchar(50) , email varchar(50) , position varchar(50) -- any other columns relevant to individual delegates ) You would then link the delegates to whatever table they are currently stored in by that row's ID number. You can do this either with a simple ID column in the above delegates table, or via another table to link the two together. Which you choose would depend on if you want to share the delegates among several items or not. With the above layout, you could get such a count by simply using the COUNT() function and GROUP BY clause in your query. Eg: SELECT OriginalID , COUNT(delegateId) as numberOfDelegates FROM original_table LEFT JOIN delegates ON delegates.originalId = original_table.originalId GROUP BY original_table.OriginalId
-
You don't need a separate document ready handler, you just need to limit what happens in your setInterval callback. You only want the setInterval to load messages, so that is the only bit of code that should be in that function. Your form submit handler would go outside of the interval function. $(function(){ ///shortcut for $(document).ready(function(){ setInterval(function(){ //Load messages. This is the only bit which belongs here. $("#messageContainer").load('chat_process.php?a=load'); }, 3000); //The submit handler goes here, outside of the interval function (but inside the ready event) $("#formsubmit").submit(function() { $.post('chat_process.php?a=post', $('#formsubmit').serialize(), function (data){ document.getElementById('Message').value ="Message"; }); return false; }); });
-
I'm not familiar with this plugin but just as a wild guess based on the code you posted: slide: function(e,ui) { $('#currentval').html(emotions[ui.value-1]); }
-
Use var_dump to try and track down where the filename becomes zero at. Nothing in what you posted is jumping out at me as the problem. You can start by dumping the $_FILES array to ensure the original name is intact there, then var_dump the $imageDirectory and $images variables just prior to your move_uploaded_file function call. If the value is 0 there, then go up to the previous place where $image changes and dump it again. Repeat until you've identified the problem line.
-
you should be using urlencode on your source variable, not urldecode. That will turn the second ? (and other bad characters) into it's percent-encoded form, thus preventing problems.
-
Storing your database credentials (and/or connection code) in a separate file is not so much for security but rather convenience. If you ever need to change them you only have one place to do it rather than in every page. If you do separate them out, your include files should also have a .php extension, however you may include .inc as an extra extension in the form of file.inc.php. That way if someone tried to request your include file directly they would get a blank response rather than seeing your PHP code in plain text.
-
Off hand I would say you'd probably want to first load all your data for the tables into an array, either multi-dimensional (row/column) or serial. Once you have that array you can loop through it checking for empty elements and handle them accordingly. Searching for consecutive empty cells would be relatively easy, when you find an empty cell just keep checking the next until you find a non-empty one. If you want to check other surrounding empty cells (above, below, diagonal) that would increase the difficulty some. If you could post some examples of the table you have and how you'd like it to appear instead that may help in devising a solution.
-
Best way to test my PHP code for inefficiency?
kicken replied to njdubois's topic in PHP Coding Help
An index is something you set on certain columns to help the database search those columns for information. Your primary keys are one index, but depending on your data usage you may want to add more. For example in a blog system you would want to add an index on the date that an entry is published. Having this index allows the database to quickly filter or sort records based on the date. For the most part, and fields that you use often in either a WHERE condition or in a join's ON condition should be indexed. If you have some pages that are noticeably slow consistently then you could use those pages to start learning out what to look for. One quick-n-dirty way to figure out what part of the code is being slow is to call microtime before and after a block of code, then subtract the two values to get the time taken to run. Once you figure out which part of the code is taking the longest to run, look over it and try to figure out why. You can post the code here for people to review if you want. If the code involves and DB queries, posting the relevant table structures would help as well. This is a function I wrote a while back to help make timing code easier: function markTime($lbl=null, $finish=false){ static $points=array(); static $collecting=false; if ($finish && $collecting && count($points) > 0){ $collecting=false; if ($lbl == null){ $lbl = count($points); } $points[] = array($lbl, microtime(1)); $firstPoint = reset($points); $lastPoint = end($points); ob_start(); printf("<div class=\"timerBlock\">\r\n"); printf("\t<p>Total Time: %0.3f seconds; Points: %d</p>", $lastPoint[1]-$firstPoint[1], count($points)); printf("\t<p>Points:</p>\r\n<ol>\r\n"); $previousPoint=null; foreach ($points as $p){ printf("\t<li>%s\r\n\t<ul>\r\n", $p[0]); printf("\t\t<li title=\"Since Start\">%0.3fs</li>\r\n\t\t<li title=\"Since previous\">%0.3fs</li>\r\n", $p[1] - $firstPoint[1], ($previousPoint)?$p[1] - $previousPoint[1]:'-' ); printf("\t</ul>\r\n\t</li>\r\n"); $previousPoint=$p; } printf("</ol></div>"); $content = ob_get_contents(); ob_end_flush(); } else if (!$finish){ if ($lbl == null){ $lbl = count($points); } $points[] = array($lbl, microtime(1)); if (!$collecting){ $collecting=true; register_shutdown_function(create_function('', 'MarkTime("Finish", true);')); } } } You can just call the function at various points in the script. At the end of the script it will output a list of each point and the time difference. For example: MarkTime('Start of loop A'); for ($i=0; $i<1000; $i++){ $x = new DateTime(); } MarkTime('End of Loop A'); for ($i=0; $i<2000; $i++){ $y = new stdClass(); } MarkTime('End of loop B', true); -
Best way to test my PHP code for inefficiency?
kicken replied to njdubois's topic in PHP Coding Help
Yes, there are various levels of working code. As mentioned above, one of the biggest issues new coders have is running queries in loops. Depending on how much data one is dealing with correcting this to use a proper JOIN setup could barely have any effect, or cut a process that takes minutes down to seconds. Creating proper indexes on your tables and using the proper datatypes for your columns can also have a noticeable impact on your run time. If you were say querying a large table for rows falling between two dates, but have the date column un-indexed such a query could take minutes to complete. Adding an index onto that date column could result in the same query taking only seconds. Without seeing any of your code we can't really give you any specific thing to go and do, only recommendations as to what to watch out for. One of the tools that would help you identify issue would be to setup your site with something like the XDebug Profiler and browse the site, then check the profiler output. This will help you identify which areas of your code are taking the longest to run, then you can look at those areas and try to figure out why they are taking a long time. -
You need to give the parent <a> tag position: relative so that it becomes a new positioning context. Then you can give the number position: absolute and set it's position as desired.
-
That is incorrect. A VARCHAR field will only use n + y bytes of space, with n being the length of the actual data being stored, and y being between 1 and 2 extra bytes to store the length. The value you pass into the column definition controls the maximum length of the field, and how many extra bytes are used. The CHAR type on the other hand is fixed size, and will always use the declared number of bytes regardless of the length of the actual value being stored.
-
How to make AJAX requests while a PHP script is running
kicken replied to CrimpJiggler's topic in Javascript Help
You have to break this up into separate scripts. One that will do the downloading and one that will do the status updates. -
var should not be used, it's a PHP4 convention and has been obsolete since PHP5 was released. It's mapped as an alias to public and still works only for backwards compatibility reasons. New code should use either public, private, or protected to declare the variables, which ever is appropriate for that variable. class Klass { public $aPublicVar; protected $aProtectedVar; private $aPrivateVar; }
- 4 replies
-
- subclass
- privacy modifier
-
(and 2 more)
Tagged with: