-
Posts
15,229 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
Next time, please just put the code in your post. Attachments are awkward. <!DOCTYPE html> <html lang="en"> <head> <title> For Loops </title> </head> <body> <!-- EXAMPLE 1 --> <!-- Below is the example that we used for the while loop code, and now we are going to write for loop code that will do the exact same thing that the while loop accomplishes --> <!-- while loop --> <p> While Loop </p> <?php $count = 0; while ($count <= 10) { //while count is less than or equal to 10, execute the below statement echo $count . ", "; // Echo out the variable count with the string ", " $count++; //increment by 1 } ?> <br /> <p> For Loop </p> <!-- For loop --> <!-- General Format for the for loops for (initial; test; each) { statement; } --> <?php for ($count = 0; $count <= 10; $count++) { /* Initialize $count to 0 check the test condition that $count must be less than or equal to 10 At the end of each loop, that is after executing the code in each loop, add 1 to $count */ echo $count . ", "; } ?> <br /> <br /> <!-- EXAMPLE 2 --> <!-- The following code identifies numbers as being either even or odd --> <?php for ($count = 20; $count > 0; $count--) { if ($count % 2 == 0) { echo "{$count} is even. <br />"; } else { echo "{$count} is odd. <br />"; } } /* Explanation of above code. Initialize $count to value of 20. As long as $count is greater than 0 then the for loop code should execute. Once the for loop code has executed, substract 1 from $count In the for loop: If the $count, when divided by 2, gives a remainder of 0, then the number is even. Otherwise, the number is odd. */ ?> </body> </html>It looks fine. How is it not working? What do you see when you do a View Source of the page?
-
Check your mail settings in PHP, check your sendmail client's error logs... There is something out there that is wrong and I can't tell you what it is because I can't see your computer.
-
Have you checked your error log? It probably has an error message describing why mail() failed.
-
No regular expressions. Stop it. Regex is for cases when you don't have better tools, and here you do: Use parse_url to break the URL string into components, parse_str to break the query string into key/value pairs, make your modification to the array with a simple assignment, then rebuild the URL using http_build_query to reassemble the query string.
-
= is for assignment, == is for comparison.
-
Missing a period for the extension.
-
You're using the lookahead correctly - it's your regular expression that's wrong. You're currently saying that the query string consists of one single character from that set and that is not followed by any of those three extensions. The extension comes before the query string, right? So what you want is a negative lookbehind and in a different location. Which can't be variable length so you actually need two (maybe three) of them.
-
PHP will look in the current namespace for the class. If you need it from somewhere else then either (a) use use utilities\hello; // (no leading backslash because it is always absolute) $class = new hello; // or use utilities\hello as helloUtility; $class = new helloUtility;or (b) use the fully-qualified name $class = new \utilities\hello; // (leading backslash because it is otherwise relative)
-
forward-compatibility link (mod_rewrite)
requinix replied to web_master's topic in Apache HTTP Server
It's called URL rewriting, if you want to search around for information on that (of which there is a lot). You're using Apache I presume? -
If you use namespaces then everything (well, almost everything) should be namespaced. Personally I keep utility-type functions not namespaced, but only functions. Controller classes could be under Framework\Controllers, models under Framework\Models, etc.
-
By executing code. If you don't want to explain what you're talking about then you'll have to wait until somebody else here explains it for you.
-
Regular expressions. Search around, there's a lot around about what expression to use. Then preg_replace_callback, which lets you put a function in to create the replacement string. In that function you do the "remove the query" work, eventually returning what you want the replacement string to be (be that the original and unmodified URL or an edited one).
-
Use parse_url to get the pieces of the URL, parse_str to get the different values in the query string, unset() the ones you don't want, and put the URL back together using http_build_query to get the new query string. [edit] Unless the query string can contain multiple values for the same key, like key=value1&key=value2&key=value3.
-
The point of namespacing is that you can use multiple namespaces. And unless you have a very small project, you'll find yourself using more than one - even if they all have the same root.
-
The browser refreshes the moment the change happens? Look into WebSockets. It takes a bit to set up on the server end. Or within a few seconds? AJAX polling.
-
public function __construct($db,$ip,$url){ $this->_db = $db; $this->_ip = ip2long($_SERVER["REMOTE_ADDR"]); $this->_url = $_SERVER['HTTP_REFERER']; }You accept an $ip and $url but don't use them. If you want them as defaults that's one thing, public function __construct($db,$ip=null,$url=null){ $this->_db = $db; $this->_ip = ip2long($ip ?: $_SERVER["REMOTE_ADDR"]); $this->_url = ($url ?: $_SERVER['HTTP_REFERER']); }but if not then don't have them at all. function getIp(){ if($this->_ip){ if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $this->_ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $this->_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } return $this->_ip; } }Think you got your logic a bit messed up. Plus you're setting $_ip in the constructor so most of this is irrelevant, or even better should be moved into the constructor instead. function insertInfo($this->_ip, $pageID, $browser, $version){"$this->_ip" doesn't belong in there. (Didn't look at the rest of the code in there.) A point about objects: initialize everything you can in the constructor, and pass in as arguments whatever information is needed to do that. Here that would be the database connection at a minimum, and IP address and URL are optional (as I mentioned earlier).
-
Alright... Unless the other server explicitly allows it, you can't use AJAX to access anything on a different domain name or port. So a page on localhost can't access localhost:8888. Which means the PHP thing I mentioned. Put a page on localhost that proxies localhost:8888 - using cURL, most likely. Which may mean you can move a lot of the Javascript data (username, password, etc) into the PHP page instead, making things a little safer.
-
You're sending requests to yourself? It sounded like you were going to some completely different web site/service. If you can do anything to the server running on localhost:8888 then that's easiest: you'd add a Access-Control-Allow-Origin header like the error message suggests and everything will work again. Once you deploy it to the internet you'll need to tweak it again (for the new domain name) but it would still work.
-
You need basic tutorials on PHP and databases first. Don't jump into the deep end until you can at least tread water.
-
You keep throwing the word "reliable" around without explaining what you mean by that. How were the hosts unreliable? What are you looking for?
-
Probably. The browser's console/error log might give you more information. If it is the cross-domain issue you can "work around" it by doing the request in PHP code and having your AJAX pull from that instead.
-
Searching specifically for year in date field
requinix replied to davidcriniti's topic in PHP Coding Help
I've wondered about this for a while but never had the chance to test it: Would a BETWEEN be more efficient? ...race_date BETWEEN '$race_year-01-01' AND '$race_year-12-31' ...race_date BETWEEN '$race_year-01-01 00:00:00' AND '$race_year-12-31 23:59:59'Or is MySQL smart enough to do that optimization (or something else) by itself? -
1. Not checking if the "a" and "b" POST values are present 2. Defining a class in a file alongside (I think?) regular code 3. Using variable names that have no intrinsic meaning 4. Random indentation style 5. Not sanitizing/validating the form input and/or the a and b values 6. Putting output inside a method when it should be returning success or failure 7. Not actually calling any of the insert() code 8. Using mysql extension instead of PDO or mysqli or something else
-
Yes. Let's stifle this discussion right now because there is nothing earth-shattering to speak of. There is no point to talking about this because Jacques is not interested and he is a representative sample of a good 95% of the community. Honestly, only nerds care about things like ASTs and there are no nerds on this site. What we should be talking about instead is how everybody in the world is using horribly insecure password practices. That doesn't get enough attention around here.
-
Seemed to me that the #1 reason they (the PHP devs) named the next version now (was a very heated debate of 6 vs 7) was so that they could stop referring to it as "PHP.next" and "PHP 6/7" and finally settle the issue. On a related note, phpng has a week of voting left but looks like it'll form the basis for PHP 7. Can't remember if they were going to rename it as "Zend Engine 3".