-
Posts
15,229 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
Accessing webpage from local network, from outside
requinix replied to realWasabi's topic in PHP Coding Help
Set up Apache (or whatever) to reverse proxy the sites: 1. NAT your proxy box 2. Install VirtualHosts for each site 3. Configure each to reverse proxy requests to the relevant machines It should support HTTP authentication too. -
So if there are 123 comments it shows 3.png? Technically speaking it's ((123 - 1) % 10) + 1 = 3, which seems like overkill but with 120 comments it's ((120 - 1) % 10) + 1 = 10. $comments = $db->get_comments($comment_post_ID);You have the list of comments there and $has_comments = (count($comments) > 0);have already count()ed them to see if there are comments. Use that same count to figure out which image to show. $image = ($has_comments ? (((count($comments) - 1) % 10) + 1) . ".png" : "default image or something if there aren't comments");And there's your filename.
-
Deleting XML entries after certain amount of time
requinix replied to Texan78's topic in PHP Coding Help
How often is the XML updated? Can you modify whatever reads it? Because you might be able to make the reader skip over old entries when displaying the contents, then make whatever updates it also remove old entries. No cron required. -
Where is the image supposed to go? Is it the blabla.png? What happens when there's more than 10 comments? Is it possible the images aren't even necessary (what do they look like)?
-
strspn(base_convert(bin2hex(inet_pton("255.255.0.0")), 16, 2), "1")I'm sure there's a better solution.
-
You have to write an extension to PHP for it. Using C/C++ code. PHP code alone is not enough.
-
The same way you get any PHP variable into MySQL.
-
Yes, but 2. You don't need to change permissions to upload files. The 7 in 0755 will apply to Apache/PHP since it owns the folder, so it can do whatever it wants without needing any changes. I said 0777 just in case you manually (ie, not using code) wanted to move the existing files into their new home. 3. No. And you put the files that already exist there. You know, the ones in the directory from #0 that you had to move. Those files, you put them back into the new directory. This is just a one-time thing. Once you move the files around and have the directory as 0755 you don't have to do anything else for the upload besides the actual move_uploaded_file(). No permission changes.
-
If they're behind a proxy then REMOTE_ADDR will be just the proxy. Sometimes it's nice enough to pass along the original IP too though: if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; } else { $ip = $_SERVER["REMOTE_ADDR"]; }I think there's a third one to test for too but I've never seen it in the wild so I don't remember.
-
There are a few but the easiest way is to make Apache/PHP own the directory you're uploading into. Then you can keep it as 0755. Downside is that you as a regular user (like with SSH or FTP) can't add or remove files yourself - you'd have to make PHP do it. (Or sudo.) 0. Move the current upload folder somewhere 1. chmod 0777 the parent directory (the one where the upload folder itself lives) 2. Have PHP mkdir() the new upload folder as 0777 3. Move the uploads yourself into that folder, or make PHP/sudo do it (in which case #2 and #4 aren't needed) 4. Have PHP chmod it back to 0755
-
Explain more.
-
How about you add more detail? First you were talking about links that "read" skills, now there's something about displaying a user ID? Surely it's more complicated than just http://myDomain.com/links.php?id=17&sk[]=Web+Design&sk[]=Graphic+Design&sk[]=SEO+Marketing echo "User ", $_GET["id"];
-
This? You'd have to write a PHP extension for it - PHP code alone won't be enough.
-
Make the code work like color = first color do { print using that color color = (color == first color ? second color : first color) } while(...)If you don't like the ternary operator there are plenty of other ways of expressing that kind of toggling logic.
-
CSS doesn't have "nesting" like that but you can #something h1 { } #other h1 { }for the same effect.
-
Nope. Still works for me. Do you have display_errors=on and error_reporting=-1 in your php.ini? Try with those and see if there are any error messages.
-
Read how? Do you know what you're talking about?
-
For a lot of expressions all you need to do is add delimiters. Most anything will do but / and # are most common. /&page=[0-9]+/For eregi methods use the /i flag like /&page=[0-9]+/i.
-
Best way to approach missing image in database
requinix replied to justin7410's topic in PHP Coding Help
You got it right there.- 11 replies
-
Best way to approach missing image in database
requinix replied to justin7410's topic in PHP Coding Help
Yeah, an if statement, that's about it. You can make code look prettier to some degree but it all comes down to an "if it's empty then do this instead".- 11 replies
-
$str = '<?xml version="1.0" encoding="UTF-8"?><entrys></entrys>'; $xml = simplexml_load_string($str);That's the part where $xml starts from scratch. It should first try to find a test2.xml file and use that, and only if that's not possible should it use the empty XML string. $xml->reports = "";That will (presumably) clear out the node. Don't do that. If you need it, which you do, then it should be declared in that initial XML as <?xml version="1.0" encoding="UTF-8"?><entrys><reports /></entrys>Also, "entries". Have you considered what will happen if two people submit data at the same time? One of them will lose their changes.
-
I don't see anything in there that tries to read in an existing file and append to it...
-
After fixing the smart quotes, your code works fine for me. Although it outputs as ... which is unusual (but not invalid) markup.
-
You have to session_start() first.
-
Arrays. http://myDomain.com/links.php?id=17&sk[]=Web+Design&sk[]=Graphic+Design&sk[]=SEO+Marketing print_r($_GET["sk"]); Array ( [0] => Web Design [1] => Graphic Design [2] => SEO Marketing )Don't forget to validate the array before trying to use it.