Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Doh004 posted:

As a PHP newbie, may I ask why you're working on an large project?

I'm not sure how that's relevant, but it's my own project in my own time, I'm doing it to learn - is that okay?

Adbot
ADBOT LOVES YOU

McGlockenshire
Dec 16, 2005

GOLLOCKS!

Gnack posted:

are you saying that "All ORMs suck" therefore you shouldn't use one? Or "All ORMs suck" but it's a necessary evil so pick the best of the crappy offerings?

Both interpretations are valid.

ORMs introduce a level of complexity. When you're already going to be deeply involved in a highly complex project, you should not ever, ever consider introducing an ORM to that project unless every single other maintainer has signed on and vetted the ORM.

If you're doing this as an educational thing, do it without an ORM first, then wedge an ORM in afterwards. Same thing really goes for MVC frameworks. Unless you understand the pain first, you won't appreciate the benefits of improved tools... and will resent their drawbacks more.

McGlockenshire fucked around with this message at 04:00 on Aug 22, 2012

Alliterate Addict
Jul 10, 2012

dreaming of that face again

it's bright and blue and shimmering

grinning wide and comforting me with it's three warm and wild eyes

Doh004 posted:

As a PHP newbie, may I ask why you're working on an large project?

You ask in SH/SC like it's a real question. :yotj:

Fake edit:

Gnack posted:

I'm not sure how that's relevant, but it's my own project in my own time, I'm doing it to learn - is that okay?

Oh, I figured you were just pulled in as the sole developer on a project while getting horribly underpaid and saddled with IT work to boot. it's usually a safe bet

IT Guy
Jan 12, 2010

You people drink like you don't want to live!

Ursine Asylum posted:


Oh, I figured you were just pulled in as the sole developer on a project while getting horribly underpaid and saddled with IT work to boot. it's usually a safe bet

Holy poo poo, it's me!

Doh004
Apr 22, 2007

Mmmmm Donuts...

Gnack posted:

I'm not sure how that's relevant, but it's my own project in my own time, I'm doing it to learn - is that okay?

No it's not okay! (of course it is).

I would just suggest keep it simple and straight forward to get familiar with PHP, then move on from there!

Ursine Asylum posted:

You ask in SH/SC like it's a real question. :yotj:

I didn't know what that smilie was so I had to saencyclopedia it. 2011 was a good year for jobs!

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.

McGlockenshire posted:

All ORMs suck. It's just a matter of where you want the suck to live.

A major problem with ActiveRecord is that it violates SOLID and separation of concerns, and requires a great deal of additional work in order to perform automated testing.

Not true... SQLAlchemy is a brilliant ORM that lets you build your queries as you would write your SQL.

Unfortunately, it's python. If there was an SQL alchemy for PHP, life would be grand.

Seriously, though, PHP ORMs, PHP Frameworks, etc. are all pretty horrible, because they're trying to solve the wrong problems with PHP (or because they think all problems can be simplified to fit their solution).

stoops
Jun 11, 2001
I think I have an easy problem, but I'm just not sure which function could do it.

I have a list of titles

title-24a
title-25b
title-26c
title-26Q
title-33


In variable terms, it's

$title - $number - $letter (letter could be null)

What I'd like to do is if the title does not have an end letter, then default it to 'A', so title-33 would be title-33A


Any help or point to the right direction is appreciated.

Sab669
Sep 24, 2009

Pass the last character in each name to this. If it returns false, then just add an A to it.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Doh004 posted:

No it's not okay! (of course it is).

I would just suggest keep it simple and straight forward to get familiar with PHP, then move on from there!

Probably a more accurate way to put it is that I'm familiar with PHP, but new to large projects.

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:

stoops posted:

I think I have an easy problem, but I'm just not sure which function could do it.

I have a list of titles

title-24a
title-25b
title-26c
title-26Q
title-33


In variable terms, it's

$title - $number - $letter (letter could be null)

What I'd like to do is if the title does not have an end letter, then default it to 'A', so title-33 would be title-33A


Any help or point to the right direction is appreciated.

I'd probably just do

php:
<?
if(preg_match('/[0-9]$/',$string)) $string.='A';
?>

Sab669
Sep 24, 2009

Blatant disregard for security aside, is there something 'wrong' with the logic in this?

PHP code:
function LogUserIn($email, $password)
{
global $db;
$stmt = $db->prepare("SELECT * FROM users WHERE email=:email AND password=:password");
$stmt->bindParam(':email', $email);
$stmt->bindParam(':password', $password);
	
$stmt->execute();

$result = $stmt->fetch();

$user = new user($result['username'], $result['firstname'], $result['lastname'],
 $result['email'], $result['phone'], $result['address1'],
 $result['address2'], $result['zipCode'], $result['isLock'],
 $result['dateCreated'],$result['dateLastLocked'],$result['lastLogin'],
 $result['lastPasswordChanged'],$result['failedPWCount'],$result['failedPWDate'],
 $result['complaintCount'],$result['avgRating'],$result['pictureLocation']);

return $user;
}
Despite passing valid credentials to the method, my $user's values are all null when I try to display them back to the user and I can't seem to figure out why.

If I just throw in a var_dump($result) in that function, I get "bool(false)" as my output? What the heck does that even mean? And print_r yields noting.

Sab669 fucked around with this message at 00:14 on Aug 30, 2012

Video Nasty
Jun 17, 2003

Sab669 posted:

Blatant disregard for security aside, is there something 'wrong' with the logic in this?

PHP code:
function LogUserIn($email, $password)
Do you know what fetch mode you are using for the $user results?

Have you tried using fetchAll() ?

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Sab669 posted:

If I just throw in a var_dump($result) in that function, I get "bool(false)" as my output? What the heck does that even mean? And print_r yields noting.

If you're not getting an error in the query then it means your query hasn't returned any rows (fetch() returns bool(false) on failure). Try dumping the values of $email and $password immediately before they're used to check that they have been set correctly.

IT Guy
Jan 12, 2010

You people drink like you don't want to live!
This is mine and it works with fetch()

php:
<?
function userLookup($username, $password)
{
    include $_SERVER['DOCUMENT_ROOT'] . '/inc/db.inc.php';

    try
    {
        $sql = "SELECT COUNT(*) FROM `users` WHERE `username` = :username AND `password` = :password";
        $q = $pdo->prepare($sql);
        $q->bindValue(':username', $username);
        $q->bindValue(':password', $password);
        $q->execute();
    }
    catch (PDOException $e)
    {
        $error = '<strong>SQL Error</strong>: ' . $e->getMessage();
        include $_SERVER['DOCUMENT_ROOT'] . '/inc/error.html.php';
        exit();
    }

    $row = $q->fetch();

    if ($row[0] == 1)
    {
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}
?>

Sab669
Sep 24, 2009

Well this is baffling. I passed the file off to my fellow group mate and it worked just fine for him. Baffled, I tried using a different row to log in as from the database and it works now?

But I know the credentials I was typing in before were valid :psyduck:
I copy and pasted them right out of PHP MyAdmin

IT Guy
Jan 12, 2010

You people drink like you don't want to live!

Sab669 posted:

Well this is baffling. I passed the file off to my fellow group mate and it worked just fine for him. Baffled, I tried using a different row to log in as from the database and it works now?

But I know the credentials I was typing in before were valid :psyduck:
I copy and pasted them right out of PHP MyAdmin

Did you copy/paste an already hashed password and then rehashing it?

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

IT Guy posted:

Did you copy/paste an already hashed password and then rehashing it?

I'll put money on this. And I don't mean that in a cruel way, I mean that in a "I've made this same mistake myself" way.

Alternatively, if you copy-pasted is it possible a trailing space was picked up somewhere along the way?

Sab669
Sep 24, 2009

I know that's not the case because we haven't implemented any security yet :v:

biochemist
Jun 2, 2005

Who says we don't have backbone?

Sab669 posted:

I know that's not the case because we haven't implemented any security yet :v:

When designing systems, is this common practice, or do people generally go back and fill in security once the main flow is figured out? I personally go back, just to try and work on one issue at a time, but I'm curious what some of the more seasoned programmers do.

Sab669
Sep 24, 2009

Haha, I'm far from seasoned. This is a school project. None of us are good with PHP at all, so I'm just starting off super simple and then if time permits (it won't) we'll add the bells and whistles. Core functionality first, though.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
Got a bit of a tricky one - I'm working on a personal project that is game-like and I'm wanting to include some sort of achievement system. The achievements can be user-activated (ie. the user performs an action and that action results in them getting an achievement) or they may be passive (ie. a change is made in the database - scores being calculated for example - that results in the user getting an achievement). There will be data coming in from an external source that could result in some users receiving achievements.

I'm wondering what is the best way to approach this? I could obviously have a general "check for achievements" function that gets run as a cronjob every 10 minutes or so and checks whether there are any achievements to award, but this won't provide a very immediate result. It's like I need something that can sit passively and "wait" for certain conditions to be met and then award the appropriate achievements.

Am I making any sense at all here?

putin is a cunt fucked around with this message at 04:15 on Aug 30, 2012

McGlockenshire
Dec 16, 2005

GOLLOCKS!
You're looking for a job queue.

There are lots of options, but I'm a fan of Gearman + Supervisor. You'd think I'm on their freaking PR team from how much I find myself recommending them...

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

McGlockenshire posted:

You're looking for a job queue.

There are lots of options, but I'm a fan of Gearman + Supervisor. You'd think I'm on their freaking PR team from how much I find myself recommending them...

That looks along the right lines, but having not done this before it seems complicated as heck. It'll take a bit of reading but I think you've nailed the right solution for me, thanks!

Edit: I don't suppose you have any resources that might help me get started in this?

putin is a cunt fucked around with this message at 07:29 on Aug 30, 2012

McGlockenshire
Dec 16, 2005

GOLLOCKS!

Gnack posted:

That looks along the right lines, but having not done this before it seems complicated as heck. It'll take a bit of reading but I think you've nailed the right solution for me, thanks!

Edit: I don't suppose you have any resources that might help me get started in this?

The other year, there was some group doing some sort of PHP advent calendar thing, and it was awesome and useful and it had hands down the best intro to using the two together ever. I also forgot to bookmark it and can't find it now. Sigh.

Thankfully Google is a thing.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

McGlockenshire posted:

The other year, there was some group doing some sort of PHP advent calendar thing, and it was awesome and useful and it had hands down the best intro to using the two together ever. I also forgot to bookmark it and can't find it now. Sigh.

Thankfully Google is a thing.

Thanks for that - searching phpadvent and Gearman I was able to find a few decent articles, this one sounds like it may be the one you were talking about? http://phpadvent.org/2009/daemonize-your-php-by-sean-coates

McGlockenshire
Dec 16, 2005

GOLLOCKS!

Gnack posted:

Thanks for that - searching phpadvent and Gearman I was able to find a few decent articles, this one sounds like it may be the one you were talking about? http://phpadvent.org/2009/daemonize-your-php-by-sean-coates

That's the one.

It's not quite as awesome as I remembered.

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.
I recently built a system that handles warehouse data processing using a job queue. I built it using a PHP fork of Resque (a Ruby queue built on top of Redis). I have Resque monitored by God (http://godrb.com/).

It's worked amazingly well. 100% uptime, no lost data, and a million times better than that previous cronjobs that were being used.

Check it out - https://github.com/chrisboulton/php-resque

Pile Of Garbage
May 28, 2007



Ok so it's been quite some time since I've messed around with PHP so apologies if this is a stupid question: what is the easiest way to grab all of the values from an indexed array and output them as a comma-separated string. For example:
pre:
Array ( [0] => test1 [1] => test2 [2] => test3 )

becomes:

string(17) "test1,test2,test3"
At the moment I am doing this with the following function:
PHP code:
<?
function array_to_csv($array) {
	$array = array_values($array);
	foreach ($array as $key => $value) {
		$return_string .= $value;
		if ($key != (count($array) -1)) {
			$return_string .= ',';
		}
	}
	return $return_string;
}
?>
I don't really want to re-invent the wheel so is there a built-in function that will do this for me (I've looked through all the array functions and can't find anything useful). Or, alternatively, is there an easier way to do this?

Mister Chief
Jun 6, 2011

PHP code:
<?
	$test = Array ( 'test1', 'test2', 'test3' );
	
	echo implode(',', $test);
?>
Output:

test1,test2,test3

Pile Of Garbage
May 28, 2007



Ah I thought it would be something simple. I should have taken a closer look at string functions instead of just array functions.

Thanks mate!

v1nce
Sep 19, 2004

Plant your brassicas in may and cover them in mulch.
While this probably isn't what you're after, I noticed your function was called "array_to_csv" and want to point out that the function fputcsv exists for creating CSV files.

You can also capture the output of fputcsv, so you don't go through a physical file, with the following snippet (stolen from the docs comments):
php:
<?php
// output up to 5MB is kept in memory, if it becomes bigger it will automatically be written to a temporary file
$csv fopen('php://temp/maxmemory:'. (5*1024*1024), 'r+');

fputcsv($csv, array('blah','blah'));

rewind($csv);

// put it all in a variable
$output stream_get_contents($csv);
fclose($csv);
?>

This might be useful to you if you find yourself needing to escape commas, quotes or new lines.

IT Guy
Jan 12, 2010

You people drink like you don't want to live!
Anyone know of any good books that focus on single page web application design using PHP and JS?

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

IT Guy posted:

Anyone know of any good books that focus on single page web application design using PHP and JS?

I would also be keenly interested in this!

Happiness Commando
Feb 1, 2002
$$ joy at gunpoint $$

I got an idea for a program that I want to write which involves scraping a website that logs in via my Google account - some kind of OAuth implementation it seems.

I tried copying in a cURL snippet to pass the cookie using the cookiejar. I used the cookie from the website instead of the google cookie which of course didn't work (assuming I got the cURL code right). Logging into google once loads 20 different cookies, and I can't tell which has the auth data.

I dont know what the gently caress to do.

I have no knowledge of PHP. At all. This complexity has rapidly exceeded the level where copying and pasting code snippets works. Can someone recommend a book / resource or several that would get me from 0 knowledge to implementing a Google Oauth system in a php scraper?

McGlockenshire
Dec 16, 2005

GOLLOCKS!
What kind of data are you trying to retrieve? Google has APIs for most of their stuff, and most of those APIs are going to have at least two PHP libraries to access them. Especially the authentication stuff.

You really, really don't want to have to make OAuth your introductory experience to PHP unless you already know OAuth and have implemented it somewhere else. Especially 3-legged.

Happiness Commando
Feb 1, 2002
$$ joy at gunpoint $$

There is an online writing tool at 750words.com. The goal is to write 750 words per day, which the site kindly tracks for you. Visiting the 'stats about yourself' page, the first bit of text is "[user] has written a total of [number] words and completed [number] days."

I am currently only interested in the total number of words I have written on the site. A regex which I found a snippet for should handle that quite easily, but getting past the login is the sticking point.

I checked in the IRC channel and there were some suggestions to use a browser macro, which I am playing with and have gotten incrementally farther with.

McGlockenshire
Dec 16, 2005

GOLLOCKS!
Oh, sorry, I thought you were talking about a Google service, not a third-party site that just happens to use Google to sign on.

Yeah, something browser based is going to be easier for you. I feel kind of weird suggesting it, but look into an Internet Explorer 8/9 thing called a "web slice." It lets you basically widgetize a section of a web page. It's that weird icon that shows up by default whenever you select some text.

Mindisgone
May 18, 2011

Yeah, well you know...
That's just like, your opinion man.
When using mssql_connect() and a separate MS SQL server from the IIS server, is the $server variable supposed to be the FQDN or just the server name? Also does the username take the format <domain>\<username> or just the username. I tried looking this up but I couldn't find any article that was real clear about this.

Quote-Unquote
Oct 22, 2002



Mindisgone posted:

When using mssql_connect() and a separate MS SQL server from the IIS server, is the $server variable supposed to be the FQDN or just the server name? Also does the username take the format <domain>\<username> or just the username. I tried looking this up but I couldn't find any article that was real clear about this.

Not sure if you're aware and just working with an old version of PHP, but the mssql extension is no longer supported (as of 5.3, I think). Instead you should be using sqlsrv extension, which you can get from here

But to answer your question, I had to use the name of the server and the sql server instance name, e.g.: "SERVERNAME\SQLEXPRESS" to get it to work.

As for the username, yep, domain\user should work. (Or if this is for a company intranet or such you might consider just leaving the username and password blank and setting "mssql.secure_connection" in php.ini, coupled with NT Authentication in IIS. Again, sorry if you already know all this!)

Adbot
ADBOT LOVES YOU

IT Guy
Jan 12, 2010

You people drink like you don't want to live!

Mindisgone posted:

When using mssql_connect() and a separate MS SQL server from the IIS server, is the $server variable supposed to be the FQDN or just the server name? Also does the username take the format <domain>\<username> or just the username. I tried looking this up but I couldn't find any article that was real clear about this.

It should be in the format <hostname>\<instance> and you user names should be <domain>\<username> when using Windows authentication or just <username> when using SA. If your server doesn't have an instance name then just use <hostname>.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply