-
Posts
15,229 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
Have you looked around for PHP libraries that can read PDFs?
-
$prev = prev($comments); I can't tell what you're trying to do with this. $parent is a comment ID. Use $array2 to find the array key in $comments, then find the parent ID there. else { return find_parent_id_0($array2[$parent], $comments, $array2); }
-
Returns id=1 because that's the top comment at the hierarchy of replies? Before your foreach loop do another, separate foreach loop. Build an array of comment_id => array key (so it looks like 1=>0, 2=>1, 5=>2, etc). With that array built up ahead of time, you can be on item [4] with parent_id=2, look up [2] in that first array, get 1, grab the parent_id of [1] = 1, look up [1] in that first array, get 0, grab the parent_id of [0] = [0], and stop. You could do that with another loop for (starting with the current item; while the current item has a parent; move to the parent)(where "move to the parent" is a couple nested array references) or do it recursively in a separate function.
-
DateTime is nice and all but if all you want is the Unix timestamp I'd just go with mktime(). It should just be a matter of $unix = mktime($_POST["hour"], $_POST["minute"], $_POST["second"], $_POST["month"], $_POST["day"], $_POST["year"]);All those fields are numbers, right? Any errors? What does var_dump($_POST) produce? By the way, as with all user input you should validate it before trying to use it.
-
How to block access to certain domains?
requinix replied to yoursurrogategod's topic in Miscellaneous
Almost, except Bob doesn't have to do that himself. Say it's a Web app instead of a Desktop app - easier to demonstrate (and more common). Before anything else, 1. The developers of the Web app sign up for a "developer account" at Facebook. There they receive unique information such as a developer ID and an API key. Those two are used to contact facebook.com for pretty much everything it may want to do. They also tell Facebook where their Web app can be contacted - this is the most important point. With that setup either side can start communication with the other. 2. The Web app is set up to allow for a Facebook login. Bob comes to the Web app. 1. He chooses the "Log in with Facebook" (or whatever) option. 2. Behind the scenes the app tells facebook.com that it wants to let a user log in. facebook.com responds with a special URL, or maybe just a token to use in a URL. 3. The app sends Bob to that URL and he logs in. 4. facebook.com knows from the URL that the user was logging in from the Web app. Assuming all went well it contacts the app back (also behind the scenes) with some special key it can use to get more information about Bob later. 5. facebook.com sends Bob back to the Web app. 6. The App remembers Bob from the session, recalls the key it received moments before, and uses the facebook.com API to get whatever user information it wants/has access to. The three main steps are (1) the Client negotiates with the Server to get a location where it sends the Owner to authenticate, (2) the Server processes the login and sends a key to the Client that it can use to look up Owner's information (how it does so is irrelevant to this process), then as a common courtesy it (3) returns the Owner to the Client. I'm not sure how this gets translated to desktop apps because facebook.com can't communicate with them directly and that's a very important part of the security model. -
I can't imagine it being hard to find a database of airports (with codes) and their locations. Pair that up with a generic weather service of which I know there are many. IMO learning how to use a service/API is more useful than how to scrape an HTML page. To answer the question traversing the DOM is a smarter way of doing it than regular expressions, which aren't suited for stuff like HTML in the first place. Unless the HTML is horribly mangled, but it's almost never so bad that it can't be dealt with.
-
Their Terms of Use prohibits what you're trying to do. With added bolding, Fortunately they do have a developer center you can visit.
-
My first guess is that PHP doesn't think the function is defined. Very first debugging steps: make sure you have error_reporting = -1 display_errors = onin your php.ini, restart the web server if not (and after you add them), then try the page again. Now, what error(s) do you see?
-
In my rewrite I positioned in the blog thing to be before the $1.php rule you now have immediately before. Because the two conflict: Apache will try the REQUEST_FILENAME as "/blog/title/1", add an extension because that file doesn't exist, continue with "blog/title/1.php", and that doesn't match the actual /blog rule. So move them around. Rule of thumb for URL rewriting: most specific first, least specific last. 1. Skip first (which needs to skip three rules now) 2. Most specific: /blog 3. Less specific: try adding the .php extension 4. Least specific: route everything else through index.php [edit] I mean through index.php, not app.php
- 9 replies
-
- htaccess
- vanity url
-
(and 1 more)
Tagged with:
-
$this->set_safe($_POST['categoryname']) = stripslashes($this->get_safe($_POST['categoryname']));You can't assign a value to the result of a function. Rethink what you're trying to do.
-
That period I had in my post? That was an "end of sentence" period, not a "metacharacter that goes in the regex" period RewriteRule ^/?blog/([^/]+)/(\d+)$ blog.php?title=$1&id=$2 [L]
- 9 replies
-
- htaccess
- vanity url
-
(and 1 more)
Tagged with:
-
Stupid slashes. Try matching against ^/?blog/([^/]+)/(\d+)$.
- 9 replies
-
- htaccess
- vanity url
-
(and 1 more)
Tagged with:
-
How to block access to certain domains?
requinix replied to yoursurrogategod's topic in Miscellaneous
I can set a referrer of absolutely anything I want. Doesn't have to be a page I've been on. Doesn't even have to be a URL. But now it sounds like you're talking about things like OAuth: someone signs into another site (like microsoft.com or yahoo.com) and you receive information telling you about who the user is - not the credentials, but say username and real name and potentially other things. "Social login" is another term I've heard because nowadays it's most commonly used for Facebook or Twitter users. -
Follow the typical REQUEST_FILENAME !-f and !-d pattern, then match against the URL structure. Also, I can't help but clean up a little what you have there. Options +FollowSymlinks <IfModule mod_rewrite.c> RewriteEngine On # Remove the .php extension RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^([^.]+)$ $1.php [NC,L] # Blog articles RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^blog/([^/]+)/(\d+)$ blog.php?title=$1&id=$2 [L] #RewriteCond %{REQUEST_FILENAME} !-f #RewriteCond %{REQUEST_FILENAME} !-d #RewriteRule ^(.*)$ index.php?page=$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ app.php?tag=$1 [QSA,L] </IfModule> # ---------------------------------------------------------------------- # Custom 404 page # ---------------------------------------------------------------------- # You can add custom pages to handle 500 or 403 pretty easily, if you like. ErrorDocument 403 /error.php?type=403 ErrorDocument 404 /error.php?type=404 ErrorDocument 500 /error.php?type=500
- 9 replies
-
- htaccess
- vanity url
-
(and 1 more)
Tagged with:
-
You can only get what's in the RSS feed itself. Only has a summary? That's all you've got to work with. Trying to fetch the full content linked to from any feed is impossible; grabbing it from one particular feed will land you in legal trouble.
-
How to block access to certain domains?
requinix replied to yoursurrogategod's topic in Miscellaneous
Those are two different things. #1 is about checking the referrer: where the user was before they reached the site. This is not trustworthy and very much spoofable so don't use it for security. #2 is about a firewall configuration and only allowing access from certain IP addresses. This is okay. Keep in mind that many people may share the same address, such as in an office or college dorm. Spoofing IP addresses is possible but almost always a fruitless endeavor so it's fairly safe to use. -
Yes, it is. Since you put the whitespace there PHP assumed you wanted it, so it dutifully outputted it, and because of how HTTP works once output has started you can't add more header()s. You need to give full control for creating files to something at some point. The normal solution is to do it on the upload folder. You can change permissions if you have SSH or (in most cases) FTP access.
-
Well you do say "Copyight 2013 - " right there in the code so of course that's what it will output. So how about you output the " - YYYY" only if that year is above 2013?
-
You have whitespace before your opening <?php tag. Since there's output your header() won't work, and if you had error settings set up appropriately in your php.ini for a development environment error_reporting = -1 display_errors = onyou would have seen an error message telling you as much.
-
It's a lot simpler when you consider references. // starting with $array and $value, // go to the bottom of the array for ($subarray =& $array; is_array(current($subarray)); $subarray =& $subarray[current(array_keys($subarray))]); // that stuff with current+array_keys is because current() doesn't return by reference // we need a reference so we don't unset() the value from the array *copy* we'd otherwise have // find it in the values $foundkey = array_search($value, $subarray); if ($foundkey !== false) { unset($subarray[$foundkey]); } // don't let the reference persist past this point unset($subarray);
-
If you put random and most certainly invalid nonsense in the .htaccess, Apache throws a 500 if you try to do anything at all with your site?
-
It's a holdover from the days of PHP 4: if you have a method with the same name as the class then it will consider that to be the constructor. Rename the method or define a __construct() method (it can be empty, just matters that it exists).
-
Do you actually need every single column? Generally you'll only need a handful so you should be listing them out. But that has nothing to do with prepared statements. SELECT * FROM members WHERE userid = ? AND code = ?The parameters are only for actual values in the query, not names or syntax.
-
Here's a how-to for using a great resource to solve this kind of problem.