logs archiveIRC Archive / Freenode / #php / 2015 / September / 6 / 1
TBotNik
TML: PB at: http://pastebin.com/XTdJQKGa
TML: My code, using substring in the foreach loop kills the first 200 lines, but want to eliminate them is the "while" loop!
fritz4fun
looks like that you can write through a socket connection with fwrite() or socket_write().
What's the diff?
TML
TBotNik: echo bin2hex($row[1]);
firie: socket_write() requires a socket resource and fwrite() requires a file resource
TBotNik
TML: Will try it!
TML
TBotNik: pastebin one of the values that is failing to be seen as is_numeric
fritz4fun
Can it be that in old phpversion fwrite() was used on sockets as well?
Lightsword
Im trying to do a single page 2FA login but want to hide the 2FA entry box unless the account actually has it enabled, Im thinking I need to do an ajax call when the user moves their cursor from the username field to the password field to check if that account has the 2FA feature enabled, I have a php function that can check 2FA status based on username, any info or guides on how I would actually do this?
TBotNik
TML: bin2hex did not work! Posting out put on PB!
TML
Lightsword: Which part do you need help with?
         

Lightsword
TML, basically how to do the whole thing, Im not really familiar with how to do an ajax call like this with php
or if there is a better way to do something like this
TML
Lightsword: You don't make an AJAX call with PHP - you make it with JavaScript
Lightsword: JavaScript calls your PHP page - that request looks to PHP just like any other request that ever comes in
Lightsword
TML, yeah I know that, does ajax just make a post request to php?
TML
You don't strictly need a POST, GET would do - but sure
AJAX just looks like an HTTP request to PHP
Lightsword
and would I do all of that within my login page?
TBotNik
TML: OK results out there. Thinking that I should use substring($val,0,str_len) since that started working in the foreach loop.
TML
it doesn't treat them any differently
Lightsword: sure
TBotNik: out where?
TBotNik
TML: Bottom of the same PB!
TML
TBotNik: Where did you put the bin2hex?
TBotNik: You should do that instead of: echo "I=> $ival <br>\n";
I mean, get rid of the ival assignment operation entirely and replace the 'echo "I=> $ival <br>\n";' with 'echo bin2hex($row[1]);', then pastebin the result
TBotNik
TML: Refreshing the code now!
hen3ry
Want to explore a php skinny framework (e.g. silex)  esp. OO ops  locally, running on Mac 10.10s Apache. Suggestions for visibility, esp. php debugger
TBotNik
TML: Updated code in the PB. Really not understanding anything now, since the echo "I=> $ival <br>\n"; from line #16 is only giving string values, yet I'm still getting the numeric vals in the array output! ????
TML
TBotNik: I don't see where you pasted the results of bin2hex
TBotNik
TML: Got it fixed new code updated! Thanks 4 your help!
Lightsword
TML, so I currently do the check like this when there is a login error https://gist.github.com/jameshilliard/ccd7f3d2bf2570cded35#file-login-php-L10 how would you recommend I modify the check for use with AJAX?
Kirito
"Key element cannot be a reference" ;_;
edoardo
Hi!
Kirito
I guess it would be better to just create a new array anyways
edoardo
I have multiple classes using the postgresql (PDO) to do some queries
Is it better to have a connection for each query
Share an unique connection
Or what?
Kirito
Ideally it would be better to share connections
         

kkspy
edoardo: use one PDO instance in all classes
edoardo
Ok, how would i share the instance?
right now i make a connection in the script itself
and then pass it to the classes like: new myClass($db)
Kirito
Singleton might be the obvious answer, I've never worked with PDO directly though
edoardo
wow
i can make a class that handles the db
and make it "Singleton"
how does it work, though? if i try to istance it again i get a clone of the first istance?
Kirito
Yes, Singleton's are generally regarded as something to be avoided though, for the record. But I think they're pretty much a necessary evil
edoardo
hmm... why should they be avoided?
i can understand it in multithreaded environments
but on php i can't see anything bad
whoever
hi all, can a single file , and a single ajax file, echo<script></script> and return data , or does it still need to be two seperate calls
Kirito
http://stackoverflow.com/questions/137975/what-is-so-bad-about-singletons Like I said I think they're a necessary evil for some things. Logging and database classes are probably two examples of when they are appropriate
edoardo
hmm ok, i'll see if they work for me :)
hen3ry
discuss php debuggers/debugging  here? If not, where?
edoardo
Kirito
Yeah, a singleton factory would be a good idea to
In general I think that's how most database ORM's work
whoever
Kirito: is the singleton for me ? or someone else
Kirito
whoever, that was at edoardo, I'm not entirely sure what you're asking. You'll need to explain it a little bit better and provide some code to show what you're trying to do
edoardo
well, it's simple
i have multiple classes that need to use the database
and i need them to have only one connection
Kirito
I was saying whoever needs to explain better, not you @__@
whoever
Kirito: ajax echos out data to return but i would also like to alert from php information as well, can this be done in a single php file or do i need two seperate ajax calls to do this still
edoardo
oh
whoever
Kirito: does that make since
P
?=
Kirito
Can you provide some example code to show what you're trying to do?
whoever
Kirito: just the php or the js too ?
Kirito
Both
whoever
pastebin or is there an actual site i can use for ajax
the problem is whe php if that helps any
daniman
ok i have a core php knowledge but i hear at some places frameworks, what are php frameworks, whats the outcomes of using if them?
edoardo
i can't understand how singletons work, am i stupid? :\
Kirito
https://bpaste.net/ should be fine
daniman, Frameworks take care of basic / common everyday tasks for you, so you can focus on building your application instead of needing to reinvent the wheel for everything yourself
daniman
Kirito: are they commonly used?
hen3ry
daniman: Im collecting skinny php frameworks, trying to understand how they work, and hopefully they can help with some nagging issues, e.g., the crummy login system I have now.
Kirito
Yes, most people who care about their time use some kind of framework for serious projects
Laravel is a very popular example, and is my personal go-to PHP framework, http://laravel.com/
whoever
Kirito: https://bpaste.net/show/7467de067326
daniman
hen3ry: Kirito: what about for learning?
whoever
the eprob is that they both are returning and the script should stop executing if the alert is triggerd
Kirito
For learning it's generally better to follow some type of online course all the way through, instead of trying to jump into programming anything yourself in a framework
CryptoExploiter
TOPIC : ##hack.me ELITEZ BLOG http://elitez.blog.com , EXPLOIT AND PATCH http://packetstormsecurity.com , HACKER TEST http://hack.me and United Nations http://webtv.un.org ... . , come to ##hack.me
Kirito
If you're just working on projects to learn and you're new to programming in general, it would be best to avoid frameworks until you're sure you've got the basics down
whoever
Kirito: so what i am looking for is an exceptable form of die /stop
hen3ry
kirito: I figure if I can find a VERY skinny framework I can observe basic OO php in action.
krambal
how do you add with a foreach loop ?
deveras
krambal: what are you trying to add?
krambal
i am naming hidden divs and i need to gout through the divs by thier count to show them then hide them then move onto the next div
deveras
krambal: foreach (array_expression as $key => $value) helps?
« prev 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 next »