« first day (156 days earlier)      last day (4795 days later) » 

3:10 AM
Yo, everybody.
 
Tek
3:36 AM
hi
 
4:08 AM
posted on March 21, 2011 by Jason E. Sweat

One of the things I love about Twitter is it enables me to stay in contact with the PHP community, and in particular the group of speaker I have come to know through PHP conferences. My friend Chris Shiflett tweeted about the “Ideas of March” calling for a revival of the blog as a form [...]

 
Why we use plugin on joomla only reason??
 
Hello?
Aww...no one is here.
 
4:23 AM
@NeXXeuS I am.
 
Any body to answer for joomla
 
I have never used Joomla, so no, I couldn't answer it.
 
Although, seriously considering.
 
@tanner can you please tell me function _process(); what this single underscore works?
 
4:27 AM
Whether that would work? A function with an underscore in the start?
 
Let me experiment ...
It works for me.
 
Tek
@PushparajJoshi Yes, functions can be named with an underscore first. See codepad.org/Mu4ndndO also see: php.net/manual/en/functions.user-defined.php
"Function names follow the same rules as other labels in PHP. A valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*."
 
And my version is 5.2.17.
@Tek I knew I had seen this, and because of the __construct method of classes, but I tested anyway. Couldn't hurt.
 
4:34 AM
thanks
 
No prob.
I was wondering if the structure of this class is any good for the developing: ge.tt/5ZQNnM2/class.txt
Wait a sec, I uploaded the wrong one ...
Ok, now the right one is up.
 
yea nice one
i am clear now
 
Tek
@TannerOttinger Is the class supposed to do anything else other than output text? I don't see the need for unnecessary bits of code. In my opinion anyway.
 
The idea is that you wouldn't be able to specify different text after the class instance has been made.
And then you could turn that into a singleton.
Well, me.
 
Tek
Err...
I'm not sure I can help there, as far as I know singletons are looked down upon.
 
4:49 AM
Well, this is just for my own knowledge of OOP. I have just recently discovered classes.
 
Tek
I've been pointed to the following articles by some very knowledgeable PHP developers: misko.hevery.com/code-reviewers-guide/…
Maybe you should read into that
 
Actually, I have already read both of those.
But the idea is that the text for output is locked in, whether it's a singleton or not.
 
Tek
Maybe you were around as well when they got linked, I remember a loooooong discussion about them
Oh ok.
 
Heh, I might have, but I found them on google.
Although, with my class, you could just make a new instance. The class will be with included code, from an outside source, when I use this. So, I need a singleton to make sure that included code cannot use the class.
 
Tek
In that case it looks fine. Too bad I can't give you a more in-depth opinion considering I'm somewhat new to classes as well :P
 
4:59 AM
Yeah. They seem much easier to use, compared to global functions, which I used to use.
 
Tek
Not to mention you'll probably get yelled at for using global functions... <_<
 
Nah, i'm just a kid anyway, so none of the stuff I make is ever really shown to anybody.
 
Hello
 
Howdy!
 
Tek
Doesn't matter if you show it to anyone or not, you have to properly write PHP!
 
5:02 AM
If i get Host '192.168.0.167' is not allowed to connect to this MySQL server in /var/www/test.php
do i have to install any program to do that?
1
A: how to connect to mysql on host on another computer on network

Col. Shrapnelit's not about "how to connect". connecting would be all the same. it's about how to setup remote server to allow connections from your IP. do you have root privileges on the db server on 192.168.0.235? if so, you have to run appropriate GRANT PRIVILEGES query on it. If not - ask a db admin to do...

 
@Tek global functions in PHP are improper?
 
Tek
Err... my bad. I thought you meant using globals inside php functions.
<writing an MVC application for a project I have for work. My attention isn't completely on this chat, sorry :)
 
@Tek That does happen. I have some functions to measure execution time, and they use global vars.
 
Tek
In that case
 
Aside from that, do you like my avatar?
It was an animated gif, but gravatar just got the first frame.
 
Tek
5:06 AM
Check the answer by @Gordon Shows a really good example / explanation.
 
Heh, yes using globals can definitely be self-destructive.
 
Tek
How long have you been using PHP?
 
Eh, about a year and a half.
 
Tek
Hah, same. sorta.
 
I was 11 when I took a look at the magic happening behind the scenes of my localhost ...
 
Tek
5:14 AM
When I was 11 I was looking at the magic happening in the hardware rather than software
(mostly because my computer was messing up... a lot so I opened it to see what was going on, hehe)
 
Well, my brother and dad have always known a lot about hardware.
 
Hi, any ideas on my question guys, should i install any third party plugin?
 
So they told me a lot.
 
Tek
Ah, that's good.
 
@experimentX I really have no idea, man.
 
5:17 AM
:(
 
Tek
If you give us more detail as to what you're trying to do then maybe we can help, but that error is vague and can be many things.
Your MySQL permissions might only let you connect from a certain IP range and or other things that we might keep guessing all day if you aren't more specific @experimentX
 
okay
I am on Ubuntu 10.10
and the other guy is using window7
and i can access his phpmyadmin and xampp from my computer
if i type 192.168.0.235/phpmyadmin then i get his php myadmin and he doesn't have root password
 
Tek
Where is the MySQL server hosted?
His computer?
 
yes
 
Tek
Or your computer?
 
5:20 AM
i have in mine too
 
Tek
Ok 192.168.0.235 is an "Private" or "Internal" IP address
 
but i want to use his database in his server from my localserver
 
Tek
Meaning you're connecting to a computer that doesn't exist in your network
That IP only works inside his network
 
it exists
we are connected in LAN so i can access his webserver
 
Tek
Oh I see, I didn't know that.
 
5:22 AM
for eg. if i hit 192.168.0.235 on my browser then i get his php myadmin
 
Tek
Ok I see
 
192.168.0.235/phpmyadmin
 
Tek
So where are you getting that connect error?
 
yes, from my localhost
 
Tek
Is phpmyadmin giving you that error?
 
5:23 AM
192.168.0.168 is my IP
no, that exists in his localserver
i mean i can access his webserver, so his database through his localserver
but not through mine
 
Tek
Right, but what I'm asking is where are you seeing the connect error? phpmyadmin? a database script? mysql command line?
 
ysql_connect() [function.mysql-connect]: Host '192.168.0.167' is not allowed
and 192.168.0.167 is my ip
on my browser
 
Tek
on your browser, on phpmyadmin, correct?
 
well i have a script on http://localhost/test.php
when i run this on my browser i get this error
 
Tek
Have you double checked the user, password and database name?
on test.php?
 
5:26 AM
and phpmyadmin is on 192.168.0.235 not on my browser
yes
`$conn = mysql_connect("192.168.0.235", "root", "") or
die("Could not connect: " . mysql_error());`
 
Tek
Root has no password?
 
yes
 
Maybe you should make one, and try that, just as a test.
 
okay
I also tried to connect from terminal but i cannot
mysql -h 192.168.0.235 -u root -p
Enter password:
ERROR 1130 (HY000): Host '192.168.0.167' is not allowed to connect to this MySQL server
 
And you didn't type anything, correct?
 
Tek
5:30 AM
You seem to have a permission problem
Mysql isn't allowing root to log in from an external computer only 192.168.0.235
 
i guess, mysql cannot open port ... or something like that to connect to remote server
 
Tek
You need to tell mysql to let you log in through an external IP
 
yes!!! i guess that is the problem
i think my question was too vague
@Tek how?
 
Tek
GRANT ALL ON * TO 'root'@'%' IDENTIFIED BY '';

Run that in phpmyadmin
 
and idea?
 
Tek
5:31 AM
under the tab SQL at the top
 
on phpmyadmin
can id do it on terminal?
 
@experimentX I have never been able to use my terminal, but I would think that would work.
 
Tek
you can do it on the terminal, yes
Do it on his computer though, not yours since you can't connect from your computer's terminal
 
yes
i was about to ask the same question lol
thanks guys
 
Does it work?
 
5:36 AM
i am using his database from my terminal
 
Tek
Nice.
 
It does
 
Tek
0
Q: how to connect to mysql on host on another computer on network

experimentXFor $conn = mysql_connect("192.168.0.235", "root", "") or die("Could not connect: " . mysql_error()); mysql_select_db("crossdomaintest"); $result = mysql_query("SELECT * FROM testing"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { echo $row[1].$row[2].$row[3]."<br/>"; ...

Click accept^
 
if it does on terminal, then sure it would on my webserver
 
Tek
On Col. Shrapnel's answer.
 
5:37 AM
yup i would
and i did
 
Tek
Glad we could help =)
 
my confusion was that i had the root username an password, and why would i still need to do that
but i see it now
thanks @Tek @TannerOttinger
 
Tek
yep
 
i hope i can connect to remote database of some host i.e. IP also
i mean database of my site
 
Heh, I really didn't do anything. I haven't ever used MySQL. Or SQL at all, really.
 
Tek
5:38 AM
Man, I should get more rep... But I hate answering questions when there's people that know so much more than I do with way better answers
@TannerOttinger Gasp!
 
well thanks anyway
 
@Tek Hey, I never liked SQL from the start!
 
@Tek i guess i know much less than you
 
Tek
We all know things in different areas, so who knows.
@TannerOttinger Neither did I. Until I learned it.
Now I love databases =)
 
@Tek Who would have guessed? :)
 
Tek
5:41 AM
It's good for you, you need MySQL for almost everything since it's all about data collecting / storage
 
I have used files, which aren't half bad.
 
Tek
@TannerOttinger Of course, for small things it's fine I guess. But there's a point where using files are just messy.
Plus retrieving lots of data will make your hard drive cry if you don't use mysql.
 
guys, can how to mysqldump db table instead of database
 
Tek
=P
in phpmyadmin you can click on the table
then click export at the top
@TannerOttinger If you ever want to get into MySQL php.net/manual/en/book.pdo.php Don't use the regular mysql_* PHP functions they're old and have a lot of security holes
 
well, from command line
or from php
 
5:43 AM
@Tek That would still require learning SQL...
 
@TannerOttinger well i learned basic sql from ms-access
 
Tek
It's easy, all you need to learn is SELECT * from TABLE, or Select COLUMN from TABLE
to retrieve data
 
but still not a pro
 
Tek
Yup it's only 2 commands to do basic things
retrieve data anyway
 
Yeah, but that's only for getting the data. I don't really know structure. And from the looks of it, it's kinda complicated.
 
Tek
5:46 AM
you should get phpmyadmin and check it out that way, it shows a graphic display of the data
and if you click on something and you want to know how to do it in php, there's a button in phpmyadmin
and turns the query into PHP
=)
 
@Tek Yes, I have done that. But still, looks hungry for a coupla months of frustration.
 
Tek
What do you mean?
 
Ah, just the idea of the structure. I really have nowhere to start.
 
Tek
Structure? In what way?
It's only tables, and inside those tables you can have even just 1 column
and work with that, very simple
 
One column would be pretty very hard to work with, when storing lots of data.
 
Tek
5:49 AM
Then make more than one column =)
 
You would need to store multiple parts...
 
Tek
then you can do Select column_1, column_2 FROM newtable;
and returns column_1 and column_2 easy
all the data of course
 
Sheesh, didn't know this stuff was this simple ...
 
Tek
yup!
 
I think I may have en ebook on this, too.
But I don't know where it's at.
I'll find it, though.
 
Tek
5:51 AM
I have something better for you
 
Tek
one sec
@TannerOttinger For example, you can use this class:
<?php

$hostname = 'localhost';
$username = 'user';
$password = 'pw';
$databasename = 'dbname';

$db = new PDO("mysql:host=$hostname;dbname=$databasename", $username, $password);


?>
then you can do
$playernameresults = $db -> query( ' SELECT column_1 FROM `players`; ' );

foreach( $playernameresults as $key => $value)
{
echo $playernameresults['column_1'];
}
 
is PDO more efficient than mysql?
 
Tek
Yes.
Plus it prevents mysql injections
Among other things
 
MySQL is pre-installed on more servers. But ... that seems easier and easier by the second.
 
5:56 AM
@Tek will it escape special chrs like ' and "
 
Tek
Yup, to retrieve the information is just 1 line.
@experimentX Yes.
You don't need to filter the input
You can do $_GET['userinput'] and use the query that way
 
No, i was getting error SQL syntax error because i had ' and " in my post data
if use PDO then will it solve my problem
 
Tek
$playernamesearch = $_GET['playernamesearch '];

$stmt = $db -> prepare ( ' SELECT name FROM `players` WHERE playername = :name ; ' );

$stmt -> bindParam(':name',$playernamesearch ,PDO::PARAM_STR);

$stmt -> execute ( ) ;

$playernameresultsquery = $stmt -> fetchAll ( PDO::FETCH_ASSOC );
$playernameresultsquery is an array with the result of your search
$db -> query() is for MySQL queries that require no $_GET or $_POST input.

$db -> prepare() is for MySQL queries that require user input.
prepare() makes a prepared MySQL and escapes quotes
automatically
so you don't need to escape or filter the user input, like I've said before
@TannerOttinger The last example is for when your application accepts user input. $db -> query() is only one line and you should practice making simple queries to retrieve information without user input.
 
Yep. Reading something on SQL just now.
 
Tek
@TannerOttinger PHP's mysql_query(), mysql_ETC are all unsafe and old and soooo sooooo messy
I'm glad I learned about PDO because it's way awesomer.
 
6:06 AM
What are the main differences?
 
 
2 hours later…
8:08 AM
posted on March 21, 2011 by Stuart Herbert

In my Beyond Frameworks talk, I explained how a component-based architecture can help answer some of the important (i.e. expensive!) questions you might face when creating long-lived apps that rely on a PHP framework. In this series of blog posts, I’m going to look at how to go about creating and working with components. phix is a small command-line tool for PHP applications. I created it to

 
8:33 AM
read it but cant see what it's good for
 
Tek
Morning @Gordon
 
morning
 
Tek
8:45 AM
I've yet to sleep. Coding is such a fun, addicting activity...
 
yo whazzup
 
Tek
Just coding my sleep away :D
 
thats the way to go
makes you more mentally stable
what are you coding?
 
Tek
A small MVC application for a family member that's starting his own computer repair business. To keep track of repairs, clients, miscellaneous records and such.
He asked me to help him out since he can't be at two places at the same time some days I agreed but he's taking in the clients information on printed pages and boxes... I was like uhhh I'm not doing this on paper. Which is why I'm doing this project... mostly for myself to be honest
 
figures
 
Tek
8:57 AM
haha
 
id think though that there's something open-source out there?
 
Tek
Maybe. But I'm building this from scratch since I'm getting acquainted with the MVC structure. So it's mostly for practice.
I'm enjoying it a lot, OOP really shines with MVC. I'm pretty new to OOP and I also wanted to get my feet wet with making an MVC application. :)
Regarding MVC I'm wondering. When requesting user input, should the get/post information be extracted in the Controller section then passed as an argument to the Model? Or should I just extract the user input once the Model function is called?
 
posted on March 21, 2011 by Henri Bergius

Today on HN there was a thread on how to get the Facebook share counts for a URL. Turns out that with Facebook, just like with most social web services this is quite easy. And actually I've been doing this since 2007 to calculate news item relevance on Maemo News. Of course the social web landscape has changed quite a bit since the 2007 launch of our "social news" service, and many of the ori

 
wow dude, no idea, wish i could be more helpful. Never done anything like that
 
Tek
What kind of projects have you done?
 
9:10 AM
The Controller handles the incoming Request and delegates to the appropriate Model, which usually means you are only forwarding those parts of the Request the Model needs to fulfill the Request. In other words, if there is POST data in the Request and that needs to be processed by the Model, then pass the POST data to the model.
Dont pass in the entire Request though
 
Tek
Thanks, that makes sense.
Though I'm not clear as to what you mean by "don't pass the entire Request"
 
An HttpRequest object usually contains much more information than the model needs
 
I'm doing stores mostly, did lots of NLP stuff too (it sucked)
 
A Request contains status headers, information about the http verb used, blablabla.. if your model just want to process the data in the POST body, it doesnt need that other stuff, hence dont pass in the request, but just what the model needs
 
Tek
@Gordon Oh why of course. Heh.
 
9:17 AM
Same for Get Params
basically, same for any object params
 
Tek
Speaking of $_POST. I've always wondered if every developer hand types every single form field into a variable. I used to until recently... Ex:

$field1 = $_POST['field1'];
...etc for 20 other field names... -_-
 
ah, good question
i usually do, but I never had 20 vars
i think you can come up with a pattern
 
Tek
It's a lot easier than that.
 
or iterate through post
enlighten me
 
Tek
$fields = array_filter ( $_POST );
=)
$fields will be an array with all the existing fields and values submitted by the form.
 
9:23 AM
still have to go through them manually?
it simply places them in another array?
or am i missing something here?
 
Tek
Oh yes
extract ( $fields ) ;
that will turn $_POST['field1']; into $field1
automatically
 
you should use that with caution
 
Tek
I know
That is why!!!!!!
$postfields = array_filter(array_intersect_key($_POST, array_flip($postwhitelist)));
 
test
 
Tek
=)
 
9:25 AM
@salathe works
 
Tek
Then I can just choose what fields I want to extract. Such as

$postwhitelist = array ('name','address','zipcode');

$postfields = array_filter(array_intersect_key($_POST, array_flip($postwhitelist)));

extract ( $postfields );
 
3
Q: How to demonstrate an exploit of extract($_POST)?

Marco MarianiI am not a PHP developer but I'm assessing the security of a PHP5 application. The author relied on extract($_POST) and extract($_GET) in some places, outside of functions. My suggestion is to call extract($_POST, EXTR_PREFIX_ALL, 'form') and change the code accordingly, but his stance is that ...

the easiest way to prevent overwriting is to enable the prefixing in the method
but tbh, i dont see much need for extract anyways
 
Tek
Does that mean you manually type all the input fields? =O
 
why would I have to have them in single variables at all?
 
Tek
To make different types of queries with different form fields?
 
9:31 AM
and why cant you use $array['foo']?
 
Tek
you mean $_POST['foo']?
 
doesnt matter if it's $_POST or any other array
 
Tek
I'm talking about user input in particular here
 
and?
 
Tek
But I see your point
 
9:34 AM
:D
 
since you said you like OOP, I'd even ask: why use $_POST at all
 
Tek
There's other ways of requesting data from the user besides $_GET and $_POST?...
 
the only requesting part is the user. your app is just receiving
and yes, there is more methods in HTTP than just GET and POST
 
Tek
Well that is just new to me then. What other way could my MVC application get form data?
 
for most practical purposes GET and POST is fine
 
Tek
9:42 AM
That sounds like you're countering what you just said about "why use $_POST at all"
lol.
 
no, im not countering it. i just realized that i would have to write a lot now about OOP and HTTP that for most simple apps not that necessary to know
my main argument for not using $_POST would be that your application then expects it to exist in the first place.
which is true for most PHP installations
but if you say you like OOP, then it would make sense not to rely to on that but have a Request Object
 
Tek
I'd like to learn about that.
 
and that would be initialized like this github.com/thePHPcc/bankaccount/blob/master/htdocs/index.php
and the controller would then not access $_POST but the Request object: github.com/thePHPcc/bankaccount/blob/master/src/controller/…
and this in turn can much more easily be tested then github.com/thePHPcc/bankaccount/blob/master/tests/unit/…
its about decoupling and making dependencies explicit and interchangeable
 
Tek
Man, that sure is fancy. (For lack of a better word)
Too bad I'm somewhat new to OOP so it looks just a tad over my head. Maybe just the exception parts... I have difficulty knowing when they should be used or not used
 
you dont have to do it this way. its basically a matter of how much coupling you can get away with
if you only have a small app, then there is no need to put in abstraction layer after abstraction layer
but once your application grows, doing so makes the whole thing easier to maintain and change or refactor. And test.
Re Exceptions: they are used for exceptional situations
Regarding the other HTTP verbs, there is also HEAD, PUT and DELETE and some others and while not all of them are used to send Form data, those are all valid request methods. You will find those in REST architectures.
 
Tek
10:00 AM
hmm
very interesting
 
but again, for your regular app, probably overkill
 
Tek
hehe
Do you recommend implementing a Request Object in a regular app for me to practice / become familiarized with it?
 
cant hurt
 
Tek
Not sure what you consider a simple project, the model & controller sections are around 400+ lines of PHP managing 10+ pages of request and forms
 
though i probably would rather try to find a pet project to practise on
and not something that needs to work
 
Tek
10:05 AM
This is a pet project lol
 
then go for it
 
anyone for joomla
 
Tek
@PushparajJoshi Not that we're not here, but if no one answers it probably means no one uses it... Did you try asking your question in www.stackoverflow.com yet?
 
I guess "simple" is what you can easily handle. If I had to put that in general measurable terms, I'd say if it takes more than ten sentences to describe what your app does in plain english, then it's too complicated
 
posted on March 21, 2011 by Qafoo - PHP

This blog post will give you a detailed introduction into the development of custom PHPMD rules. PHPMD is static code analysis tool that helps to improve the quality of PHP software projects. Therefore it processes the project's source code and searches for known error patterns, design flaws, overcomplicated expressions and unused/dead code. You would like to use like PHPMD to improve the quali

 
10:09 AM
ok
 
Tek
@Gordon Would you care to explain or recommend some OOP terms that I'm not 100% familiar with? I've heard decoupling a few times, not too sure what explicit dependencies exactly means...
I could know but maybe not know the jargon?
 
might be too advanced to fully grasp but contains a lot of the essentials
 
Tek
Thanks.
How long did it take you to understand all of it? (Assuming that you do)
 
Years and I still dont fully grasp all of these I guess :)
but thats okay. you dont have to fully understand all of that stuff to create a working app
 
Tek
Oh, of course. Out of curiosity though, which ones do you not grasp completely yet?
 
10:21 AM
cant pinpoint. i think i have a good understanding of what they mean, but when it comes down to all the nittygritty details … blah, you get the idea :)
 
Tek
haha I see :P
@Gordon I should probably get some rest. I think I'm at my limit when I can't seem to store processed information from my brain. (I can read it but it's just passing right through me :] )
Good talking to ya, thanks for all the help and pointers. (Bookmarked for later) See you around =)
 
np. cya
 
11:21 AM
Morning
 
@ircmaxell Hi
 
Sup
 
good morning :)
 
Morning
ok, off to work
 
11:57 AM
1
Q: PHPUnit: How to save an arguments passed to stub method

DarksideMethod setValue() In class SomeClass accepts arguments and no way to get this arguments back for make assertion. Can I create a stub for method setValue() that allows save an arguments passed to this method? class SomeClass { public function setValue($name, $value) { // do some stuff ...

@Gordon yes no maybe? Should be better than testing privates?
 

« first day (156 days earlier)      last day (4795 days later) »