« first day (336 days earlier)      last day (4836 days later) » 

00:01
thats what i want! a fake madagascar cockroach!
Now if it were a tarantula, I could even cuddle next to it during cold winters. :P
But not that thing.
btw ,how the hell you ended up with this topic ?!?
@tereško Someone was saying 'hi'...
@tereško Could you do me a tiny little favour? I'm rewriting some code and thought could write a function of mine in a future-proof and consistent manner. It's just 20 lines of code. :) Pretty please? (on the bright side, the code already works)
well .. show me what it is
its kinda 3am .. maybe i will have the urge to do something about it , maybe not
00:10
3
A: Replace PHP's realpath()

Christian SciberrasThanks to Sven Arduwie's code (pointed out by Pekka) and some modification, I've built a (hopefully) better implementation: /** * This function is to replace PHP's extremely buggy realpath(). * @param string The original path, can be relative etc. * @return string The resolved path, it might ...

oh my
@tereško tehe. go get some sleep first :)
Come on, I know you eat these kind of problems for breakfast!
@ChristianSciberras it does not looke like you can actually do anything about it
@tereško /me is doomed
maybe only refactor it , and extract subrutines
00:14
@tereško hmm, point noted.
is there a header one can send that tells the browser not to display this page in an iframe?
@DevinGRhode Yes
yeah, don't code an iframe..
@DevinGRhode header('X-Frame-Options: SAMEORIGIN',true);
no , but you can cause iframe to "break out"
00:15
ugh I need to sepate styles lol
Either i can send an ajax call for the html of a page, and insert it into a div, or use an iframe
That tells the browser the page can only be in a frame whose parent is the same website.
inserting a page into a div causes any styles to get screwed up with the holding page
Other option is DENY, which causes it to disable everywhere.
and iframes break
115
Q: Frame Buster Buster ... buster code needed

Jeff AtwoodLet's say you don't want other sites to "frame" your site in an <iframe>: <iframe src="http://yourwebsite.com"></iframe> So you insert anti-framing, frame busting JavaScript into all your pages: /* break us out of any containing iframes */ if (top != self) { top.location.rep...

00:17
disabled="disabled" with what?
I also endorse @tereško's option, but know that it's a bit harder to discriminate with your own pages.
@DevinGRhode Uhuh? It's not an element attribute, it's an HTTP header.
nvm misread it
holy cow.. 7:15 till my food shows up? wtf is that about...
6:22 thats almost an hour...
Say, @tereško do you know if it's possible to load a PHP file into a namespace (or at least in the current namespace)?
iirc no it is not
00:27
And it's not possible to have variable namespaces either :/
namespace $name { } // doesn't make sense anyway, it can't work in define time, no?
00:41
@tereško Let's say I'm adopting namespacing in my framework in a way that I require each file related to the framework to have a namspace xyz; at the start.
I also have an auto-loading functionality.
My question is, since I have control over the files being loaded, does it make sense to check if the file is inside the framework directory and if it is, show a warning if it doesn't have that namespace line?
01:14
@ChristianSciberras I'd opt for just editing the file and adding the namespace line instead of throwing a warning \o/
02:00
@Raynos Uhm, the warning would show up only if you didn't do that.
But it's kind of a stupid check, someone might want to avoid doing this for a specific reason.
Bet @Gordon wouldn't like this. I had a similar issue in the past (I think it concerned throwing a warning when function parameters were not as expected.
I'm suggesting the auto loader opens the file, writes the line then saves & closes the file
then loads the PHP file again
I.e. it does the editing programatically for you
02:25
@Raynos (delayed response i know), that's an extra step that isn't needed especially for a file thats not in the framework. So if he's going to require each file related to the framework to have the namespace, then to me it would make sense to throw a warning and hault the program if a file inside the framework folders doesn't have it
02:59
You have a point actually
Its better to do that namespace manually
otherwise we have black magic pseudo globals everywhere
yep
plus i just thought of something else, if the auto loader opens the file and writes the line then saves and closes the file... you have to introduce the check to see if its already there to begin with ;)
 
6 hours later…
09:00
@Justin lol
09:12
Good morning
09:48
Morning :-)
Anyone has an idea of group chat?
10:19
@ManjotSingh Huh?
10:37
Hi Guys, I have got interesting query about htaccess... Is this a right place to put it.. ?
> Discussion for all things PHP - Don't ask whether someone is here or can help. Just ask us. If anybody can and wants to help, they will. But no one can know before you actually ask your question.
Thanks
which doesnt mean you may not ask the question. it just means that it is unlikely youll get an answer
I want to to rewrite using htaccess; Here is the situation. All requests coming to server example.com should be checked for existense at example.com/files and if the file doesnt exist then it should be rewrited to /index.php
Means, for example, if I request an image www.example.com/image-1.jpg it should first lookup at www.example.com/files/image-1.jpg and if the file doesnt exist in the "/files/" directory it should be rewritten to "/index.php?query=$1"
Tom
Tom
What you need is inside that snippet
(third comment from top)
10:49
Yes, this is fine if I check for the file from the Root
"RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]"
But I need it to be checked inside a directory
Tom
Tom
then add /files to the path ._.
@Artefacto: Could you give me some feedback on the difference between ENT_SUBSTITUATE and ENT_DISALLOWED? As far as I see both replace invalid multibyte sequences, but in different context.
Tom, do you mean like this
RewriteCond /file%{REQUEST_FILENAME} !-f
Tom
Tom
@Shoaib yeah I'm not sure about an additional slash between the "e" and the "%" but play around a little.
@Gordon
10:54
@Tom needs 3k+ rep
@Tom Let me try then..
Tom
Tom
@Gordon :( discrimination
@Gordon Closed
I tried a couple of things, ended up in 500 error !
@NikiC thanks
10:56
Back Again :-)
Tom
Tom
@Shoaib turn on error logging in your apache config and check out what's wrong.
@Gordon that user had 448 exp and 3 gold badges :S that's weird.
@Artefacto: Ah, nevermind, found it out myself. ENT_SUBSTITUTE if for invalid multibyte sequences and ENT_DISALLOWED for characters invalid in the target document type.
Tom
Tom
@Gordon oh.
@hakre get_headers will do a GET request, so unless you change the stream wrapper to use method HEAD, you are downloading the whole file. apart from that: duplicate = dont answer it.
Tom
Tom
11:28
@Gordon do you have experience with NoSQL?
@Tom no
Tom
Tom
@Gordon :) ok
11:41
@Artefacto: Another question: What are the HTML_ENTITIES and HTML_SPECIALCHARS constants for (I mean the PHP visible ones, not the C ones)? I couldn't find out where they are used.
@phant0m Thanks.
@NikiC no problem
That reminds me that get_html_translation_table and htmlspecialchars_decode need to be updated too
@NikiC "updated", how?
11:47
@phant0m Docs are missing new 5.4 flags ;)
I just added them to htmlspecialchars and htmlentities but forgot those two functions
I see
@NikiC so you're a PHP dev?
11:59
@phant0m No, no. I'm only adding documentation, not writing the code ;)
One of the most important job NikiC. Everyone loves good documentation.
12:21
Morning
Afternoon @ircmaxell
Good, trying to "invent" doc theme.
And you?
12:34
Hi @KamilTomšík
hey, @Robik :)
-1
A: How to get Open Graph Protocol of a webpage by php?

zerkmsHow about: preg_match_all('~<meta\s+property="(og:[^"]+)"\s+content="([^"]*)~', $str, $matches); So, yes, grab the page with any way you can and parse with regex

hey, do you think too that regex is not a good idea to parse html? ;-)
@zerkms yes
@KamilTomšík: reason?
@zerkms I consider xpath queries more readable for this kind of stuff
12:40
@KamilTomšík: can you write a sample that will not throw warnings on that imdb page?
@zerkms The reason is simple. Regular expressions can parse regular languages. html is an irregular language => not a regular language. Therefore, regular expressions cannot safely parse html. QED
@Zirak: but is there a solution that doesn't throw warnings?
see the edited part
12:42
regexes for me is MUCH better than 100 warnings
none of the dvs on that page are justified. neither for the regex solution, nor for the xpath solution
C:\Users\User>php -a
Interactive mode enabled

<?php

error_reporting(-1);
$html = file_get_contents("http://www.imdb.com/title/tt0120737/");

$doc = new DomDocument();
@$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$query = '//*/meta[starts-with(@property, \'og:\')]';
$metas = $xpath->query($query);
foreach ($metas as $meta) {
    $property = $meta->getAttribute('property');
    $content = $meta->getAttribute('content');
    $rmetas[$property] = $content;
}
var_dump($rmetas);

^Z
array(5) {
@ is not a solution
it is not fix of warning
it is pretending that there is no issues
aaah, I was curious why no warnings were raised
@zerkms The first answer is
12:45
@Zirak: ?
How often do I have to write that? libxml_use_internal_errors(true); $dom->loadHtmlFile($url); libxml_clear_errors();
@Olli have you tried using RewriteBase ?
might help on some setups
@romaninsh how could i use ti
it*
@zerkms and yes, suppressing the errors (just not with @) is absolutely okay when you dont have control over the generated markup
12:46
@Gordon yes, just googled name of that :-D
RewriteBase /path/to/location
@Gordon: it is never okay
ok
@Zirak Your logic is wrong. Regular expressions (as in PCRE) can parse not only regular grammars but also context-free and context-sensitive grammars:
also try more broader match and dump GET to see whats in there
12:47
@romaninsh so I just change "RewriteRule" to "RewriteBase"
13
A: Match a^n b^n c^n (e.g. "aaabbbccc") using regular expressions (PCRE)

NikiCInspired by NullUserExceptions answer (which he already deleted as it failed for one case) I think I have found a solution myself: $magic = '~^(?=(a(?1)?b)c)a+(b(?2)?c)$~'; var_dump(preg_match($magic, 'aabbcc')); // 1 var_dump(preg_match($magic, 'aaabbbccc')); // 1 var_dump(preg_match($magic...

no leave rules
1
Q: htaccess RewriteBase

ChristopherI have two directories in my root: /dev and /live. All content inside these directories have relative paths such as /css/style.css or /js/home.js. I want to be able change the root directory using htaccess so that the relative paths would become /live/css/style.css etc or /dev/css/style.css dep...

@zerkms then what is the OP to do? Run the code through tidy first? Contact the page author and ask them to fix the broken markup? Fact is: 95% of the web is invalid HTML.
C:\Users\User>php -a
Interactive mode enabled

<?php

error_reporting(-1);
$html = file_get_contents("http://www.imdb.com/title/tt0120737/");

libxml_use_internal_errors(true);
$doc = new DomDocument();
$doc->loadHTML($html);
libxml_clear_errors();
$xpath = new DOMXPath($doc);
$query = '//*/meta[starts-with(@property, \'og:\')]';
$metas = $xpath->query($query);
foreach ($metas as $meta) {
    $property = $meta->getAttribute('property');
    $content = $meta->getAttribute('content');
    $rmetas[$property] = $content;
This does not mean that you can parse HTML, but your way of proving it isn't stringent.
12:48
@zerkms works fine (as @Gordon already pointed out)
@Gordon: @$doc->loadHTML($non_existent_variable);
@ will supress notice on non_existent variable
so @ is not okay here
@zerkms you didnt pay attention :)
@Olli try rewrite (.*) var=$1 and dump it
@KamilTomšík: yes, that is a solution, indeed
@Gordon: ?
@zerkms @Gordon means he already told you (what I've just shown)
12:49
3 mins ago, by Gordon
How often do I have to write that? libxml_use_internal_errors(true); $dom->loadHtmlFile($url); libxml_clear_errors();
@Gordon: I've seen it
3 mins ago, by Gordon
@zerkms and yes, suppressing the errors (just not with @) is absolutely okay when you dont have control over the generated markup
and I agree it is a solution
@
it is not okay, because it supresses another issues
not only parsing ones
> @zerkms and yes, suppressing the errors (just not with @) is absolutely okay when you dont have control over the generated markup
@$doc->loadHTML($gordon_hey);
oh
12:50
@romaninsh i tried the other
but didnt worked
yes, i didn't pay attention
i mean i put whole path
in RewriteBase
but still seems not to work
@Gordon that happens pretty often to you :-D
12:51
hmm i didnt noticed this try rewrite (.*) var=$1 and dump it
how should I actually do it
ill post answer
ok
it´s easier for me :P
actually, did someone verify that get_meta_tags doesnt get those meta tags as the OP claims?
of course no
don't check - answer sooner
(the first SO rule)
ah. wait.
> Only meta tags with name attributes will be parsed.
manual says its true
one cannot but wonder about some functions in PHP
12:55
$html = file_get_contents('http://www.imdb.com/title/tt0120737/');
var_dump(get_meta_tags($html));
for me it returns something terrible
@romaninsh now var_dump returns string(40) "tuote.php/1-Some-text"
so what i´m doing wrong
i think it should return tuote.php?data=1-Some-text
@Olli and how does your URL look like?
sometimes i just wanna retag questions with stackoverflow.com/questions/7454904/next-key-in-array
i did var_dump for $_GET and got this:
array(1) {
["data"]=>
string(40) "tuote.php/1-Some-text"
}
13:01
@Gordon: I wouldn't be terribly wrong if I said that about 50% of SO questions are covered greatly in manuals
@zerkms yes, but some of them, like that one above, is just 101 knowledge
@zerkms Exactly.
@Olli yeah, there is something going on in there, which converts "route" into "route.php", do you have any other rules in that file?
The worst thing is that SO actually encourages answering such questions as you are likely going to get at least five votes if your answer it quick and short.
it expects knowledge of at least 3 functions and control structure. It is not that easy for newbies ;-)
13:03
@romaninsh no i dont have any otehr rules in that file but in parent directory i have other htaccess, did you see it in my question ?
@NikiC: need to create rtfm.stackexchange.com
@NikiC: how do you know that current in question really means that he moved array pointer?
RewriteRule ^(.*)$ $1.php [L,QSA]
this probably interferes.
ok
if he knew that there is array pointers - he would answer his question himself
@zerkms Yeah, just noticed that too ;)
13:04
could i some way
exclude it from running in some directories
and run in all other directorie
@Olli well you could do this: RewriteRule ^tuote\.php/([^/]+) tuote.php?data=$1 [L]
than the other where it is not allowed to run
well, boooooooring
@romaninsh yes it worked now thanks, but could i do it not-so-complex
@Olli how to exclude the parent one would be the other question.
13:06
yes
how can i exclude it
could you answer to it
@Olli I don't know. [L] should do it i think, i'd suggest to look into other options.
@zerkms The question reminded me of that more interesting one:
9
Q: Picking the nearest value from an array reflecting ranges

PekkaI have an array that reflects rebate percentages depending on the number of items ordered: $rebates = array( 1 => 0, 3 => 10, 5 => 25, 10 => 35) meaning that for one or two items, you get no rebate; for 3+ items you get 10%, for 5+ items 20%, for 10+ 35% and so on. Is t...

@Gordon ooooooh, those answers are gems :-D
@romaninsh what you mean by "other options"? and how i could use L to exclude it
@NikiC: it is classic "issue about backpack" (at least that is how such tasks are called in russian)
13:08
@romaninsh
http://stackoverflow.com/questions/1848500/htaccess-mod-rewrite-how-to-exclude-directory-from-rewrite-rule
found that
how could i embed it to my code ?
or another name "the change issue" (the change here is the term about money you get back for 100$ in a shop)
@Olli dunno. keep trying.
@zerkms :P
@NikiC: oops, nope, I got the question wrong
@romaninsh ok
13:12
well, it is easier than "backpack issue"
thank you for helpoing
your solution is now accepted!
@NikiC: and even there I don't see any reason of avoiding loops ;-)
O(N) in case of 10 elements is pretty performant solution
@zerkms Yeah, that's why I added my loop answer even though it wasn't the question ;)
we could remember there is a binary search and reduce it to O(logN) but it doesn't really worth it
and I wonder if Salathe would use that oneliner in production ))
@zerkms Building a binary search tree would cost more cycles than doing a linear search ;)
13:15
How so?
count($arr) is O(1)
$middle = ceil($cnt / 2)
is O(1)
@zerkms Well, obviously depends on how many items you need to do this for ;)
for any amount of items logN is less or equal than linear
@zerkms But you need to balance the number of bought items, not the number of available discounts, don't you?
by definition
probably I don't understand the task then
@zerkms Nevermind ;)
13:16
for 7 - should we just get 25?
yes
you know, if it weren't you, who was so upset about my range example I wouldn't said a work, but... what if there were 1000 steps between percents? :-P
such a waste of resources...
@KamilTomšík :D
@KamilTomšík That's exactly the reason why I said I would use the trivial (easily understandable) loop instead of any hack ;)
@NikiC you must confess I have a point there, you should reconsider what you've said or I'll downvote your answer :-P
@NikiC I'd probably think about foldl - could be readable, effective and short
@KamilTomšík You would do an array_reduce instead of a simple loop?
13:20
@NikiC dunno depending on how it would look like - it's iteration resulting in one value, why not reduce?
array_reduce and array_map sometimes is slower than just a foreach
@KamilTomšík But you do have a point, you should downvote it.
@NikiC was kidding, not going to do that :)
@zerkms Not sometimes, but always ;)
@KamilTomšík I know :P
@zerkms oh no... another performance guru? :-D
13:21
I wasn't sure - that's why I left some possibilities to step back ;-)
Nope
As long as we all have chosen php - it is too late to calculate microseconds
3
+1
(+1)
and now it is a good time for Gordon to come and say that we are just wrong
13:24
...
how do you call that usually (or always?) orange round thing that is thrown to water when some person has fallen from a boat?
my dictionary tips that it is "ring-buoy" but it sounds unnaturally :-S
no, jacket is what is worn on a person
@zerkms Yeah, that's how you call it ;)
A lifebuoy, ring buoy, lifering, lifesaver, life preserver or lifebelt, also known as a "kisby ring" or "perry buoy", is a life saving buoy designed to be thrown to a person in the water, to provide buoyancy, to prevent drowning. Some modern lifebuoys are fitted with a seawater-activated light, or lights, to aid rescue at night. The lifebuoy usually is ring-shaped or horseshoe-shaped and has a connecting line allowing the casualty to be pulled to the rescuer. They are carried by ships and are also located beside bodies of water that have the depth or potential to drown someone. They are...
:-S
13:30
oh, that's a Life belt methinks.
which is more common - to change sshd port from 22 to something < 1024, or > 1024?
became boring of fail2ban bans from ssh bruteforcers
@zerkms in that case you'd better choose nonstandard port :-P
yes, and is chosing something below 1024 considered to be safe for well OS functioning?
well, let's move to > 1024 then
because once I've chosen 37 and got my ntp broken
i got it on 2031
Sep 18 00:38:40 homepage init: ssh main process (4441) terminated with status 255
omg
13:43
Hi zerkms. I'm trying to call <?php session_start()
but always get user notic
error
what is the reason and trying to solve but failing
@gordon: Yeah, I've seen it. Currently digging into streams to do this via HEAD request and taking redirects into account.
may you advice me plz
@IndianGirl what exactly is said in that notice ?
@IndianGirl Whitespaces before <?php ?
<?php session_start() ?>
Notice: cannot send session header
13:46
... headers already sent?
it means that you have already began sending some text to the browser
but my code is like <?php session_start() ?>
Anything before that?
I have included the session.php file below a HTML page
but nothing written in the session.php file
13:48
But in HTML page
that is the cause
Hello Everyone!
why, there i havenot written anything in the session.php file
you must execute session_start() before you send any output to the user
that includes the html
<!DOCTYPE html>
<html>
</html>
<?php
   include 'session.php';
?>
this will definitely cause an error
also I'm not able to redirect a person using header("location: logsuccess.php"); after successful
user680786
13:50
stupid phrase about PHP and microseconds, zerkms
<?php
   include 'session.php';
?>
<!DOCTYPE html>
<html>
</html>
this, however , might not show any errors
ok I'm trying your advice
user680786
I hate sites which generate their answer in 2 or more seconds.
but what to do insted of header("location: logsuccess.php"); after successful login?
13:52
@OZ There is a small but significant different between seconds and microseconds. Uhm, well, not so small actually: six orders of magnitude...
is there any other way to do it
I have been trying to fix a weird bug. The issue was that the code runs on my machine(PHP 5.3.x) just fine but breaks when I deployed on client machine(PHP 5.2.x). I had no idea why, until now
@Gaurish Error message?
When @OZ says that something is stupid, it is.
:)
@IndianGirl, can you pastebin your code , because it is hard to give and suggestions if we do not know what you are talking about
user680786
13:53
@NikiC if you will never care about performance, it will be seconds. If you will think about optimization from begin - it will be microseconds
file_get_contents(
    'http://www.example.com/',
    false,
    stream_context_create(array(
            'http' => array(
            'method' => 'HEAD',
            'ignore_errors' => false
        )
    )
)); @hakre
user680786
@Robik joke, repeated twice it's already not joke
NikiC, I was making request to remote API server which would return some XML. And the error I got was "Error creating SimpleXMLElement => String could not be parsed as XML"
@OZ Seems like you never heard about "Premature optimization is the root of all evil" ;)
user680786
:1489310 I saw your arguing with Gordon about GLOBALS and I know that some of your ideas is more than "questionable"
user680786
13:54
@NikiC seems like you never read context of that phrase
@Gaurish perhaps it's not returning XML
@OZ_ Yes, that's true
@OZ When did I argue with Gordon about globals? I would never question that globals are a bad thing. Could you maybe point me towards where I said something different?
user680786
@NikiC yes, wait a second
user680786
@Gordon that link, thanks
@ircmaxell Here is the weird part -- it works on my dev server just fine. Only fails on client machine :P
@Gaurish check what's being returned from the http request...
Valid XML
perhaps the http stream wrapper is disabled
13:57
And I have managed to fix the issue
@Gaurish on the client server?
@Gordon Oh, yeah, but that's old. In computer science things change at supersonic speed, so me arguing with you serveral month ago doesn't mean much ;)
@ircmaxell Yes, had to set CURLOPT_FOLLOWLOCATION to FALSE. now its works on my dev box & also my client's machine. And I have no idea why it works or stopped working.
ah ok
13:59
Any theories on why it worked on my dev box with CURLOPT_FOLLOWLOCATION = TRUE but failed on client's machine
And why setting CURLOPT_FOLLOWLOCATION = FALSE makes it works on both placed
@OZ If you are serious about your microseconds thing I would really suggest you to learn C. Because by using PHP you already gave up the microseconds ;)
@Gaurish Don't use curl.
@hakre and to get the headers you'd do print_r($http_response_header); after the call to file_get_contents

« first day (336 days earlier)      last day (4836 days later) »