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

fuf posted:

I'm looping through wordpress posts and want a new line after every three posts.

Right now I have

code:
if( $postcount == 4 or $postcount == 7 ): 
//new line
How do I extend this for any number of posts? Is there a way to check if a number is one more than a multiple of 3?

Normally you would handle presentation issues like this in CSS, is there a functional reason for needing to place a linebreak on every third post or is it purely for looks? If it's purely for looks, use CSS instead.

Adbot
ADBOT LOVES YOU

Fleur Bleu
Nov 26, 2006

by Ralp
Worked on my code some more and got it working.
It was working fine, adding users like it should, but when I came back an hour later it suddenly didn't work anymore :psyduck:
I've doublechecked and restarted everything, but I can't figure out what's going on.
Whitespace doesn't matter, does it?

edit: Found it, crypt() was loving things up.


php:
<?php 

    $mysqli = new mysqli("localhost""""""");

    if (mysqli_connect_errno()) {
            printf("Connect failed: %s\n"mysqli_connect_error());
            exit();
    }

    $business_n $mysqli->real_escape_string($_POST['business_n']);
    $contact_n $mysqli->real_escape_string($_POST['contact_n']);
    $industry $mysqli->real_escape_string($_POST['industry']);
    $email_address $mysqli->real_escape_string($_POST['email_address']);
    $email_address2 $mysqli->real_escape_string($_POST['email_address2']);
    $mailing_address $mysqli->real_escape_string($_POST['mailing_address']);
    $city $mysqli->real_escape_string($_POST['city']);
    $postcode $mysqli->real_escape_string($_POST['postcode']);
    $phone_nr $mysqli->real_escape_string($_POST['phone_nr']);
    $abn $mysqli->real_escape_string($_POST['abn']);
    $password $mysqli->real_escape_string($_POST['password']);
    $password2 $mysqli->real_escape_string($_POST['password2']);
    $secret $mysqli->real_escape_string($_POST['secret']);
    $answer $mysqli->real_escape_string($_POST['answer']);
    $terms $_POST['terms'];

if(empty($email_address)) {
    echo "Email required.";
  }
  elseif (empty($email_address2)) {
      echo "Email required.";
    }
  elseif (empty($password)) {
      echo "Password required.";
    }
  elseif (empty($password2)) {
      echo "Password required.";
    }
  elseif (empty($secret)) {
      echo "Secret question required.";
    }
  elseif (empty($answer)) {
      echo "Secret answer required.";
    }
  elseif (empty($terms)) {
      echo "You have to agree to the terms and conditions.";
    }
  elseif (($email_address != $email_address2)) {
      echo "Email doesn't match.";
    }
  elseif (($password != $password2)) {
      echo "Passwords don't match.";
    }

      else 
    {


    $mysqli->query("INSERT INTO members VALUES (NULL, '$business_n', '$contact_n', '$industry', 
'$email_address', '$mailing_address', '$city', '$postcode', '$phone_nr', '$abn', crypt('$password'), 
CURRENT_TIMESTAMP, '0', crypt('$secret'), crypt('$answer'))"); 

    }


$mysqli->kill($thread_id);
$mysqli->close();


?>

Fleur Bleu fucked around with this message at 08:36 on Oct 22, 2012

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

Fleur Bleu posted:

php:
<?
$mysqli->kill($thread_id);
$mysqli->close();
?>

Why are you calling kill? I have never seen this and it seems like a bad idea. This is killing the thread, I assume that means that close never actually gets called on it since the process is already dead. If it worked that way you would end up with a hanging open connection every time the script runs.

Also, you should consider generating your own salt for crypt as weird things could happen if you move your script to a different server. Crypt does different things depending on how the OS is configured.

Impotence
Nov 8, 2010
Lipstick Apathy
Why are you not using PDO and parameterised queries? :smith:

The Gripper
Sep 14, 2004
i am winner
Also would doing crypt() on a real_escape_string()'d string cause problems? If anything was escaped/required to be escaped your crypt would be on a string with extra slashes and poo poo and not the original. Or maybe not, I've never bothered checking.

The Gripper fucked around with this message at 14:00 on Oct 22, 2012

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

The Gripper posted:

Also would doing crypt() on a real_escape_string()'d string cause problems? If anything was escaped/required to be escaped your crypt would be on a string with extra slashes and poo poo and not the original. Or maybe not, I've never bothered checking.

Yes, it would cause problems if special characters were used in the password. It should be ran through crypt then escaped. Otherwise you will always need to run a password through real_escape_string() first, before checking running crypt on it and checking the value against the db value.

fuf
Sep 12, 2004

haha

Gnack posted:

Normally you would handle presentation issues like this in CSS, is there a functional reason for needing to place a linebreak on every third post or is it purely for looks? If it's purely for looks, use CSS instead.

Yeah it's purely for looks, but I don't know how I would do it with just CSS. I need PHP to tell me whether a post should be on the start of a new row so I know when to close the last row and start a new one. I guess I could have written the CSS better so that each row didn't have its own container, but that's the way it's laid out...

Impotence
Nov 8, 2010
Lipstick Apathy

fuf posted:

Yeah it's purely for looks, but I don't know how I would do it with just CSS. I need PHP to tell me whether a post should be on the start of a new row so I know when to close the last row and start a new one. I guess I could have written the CSS better so that each row didn't have its own container, but that's the way it's laid out...

div:nth-child(Xn+Y) {} or something?

Viggen
Sep 10, 2010

by XyloJW

Gnack posted:

Normally you would handle presentation issues like this in CSS, is there a functional reason for needing to place a linebreak on every third post or is it purely for looks? If it's purely for looks, use CSS instead.

This should be done in CSS.

Also, you're making a lot of extra work for yourself. I don't use WP, so this is a 'logically works, but will be untested':

code:
<?php

wp_list_comments('type=comment&callback=mystupid_comment&mystupidindex=1');

function mystupid_comment($comment, $args, $depth) {
		$GLOBALS['comment'] = $comment;
		[..]
		//not sure if this function is re-entrant as a callback with $args?  You'll have to check to see if it keeps getting trounced.
                $myStupidIndex = (is_numeric($args["myStupidIndex"]) && !isset($myStupidIndex)) ? $args["myStupidIndex"] : "0";
		comment_text();
		$myStupidIndex++;
		echo ($myStupidIndex % 3 == 0) ? "<br />" : ""; //Divisible by 3?
		[..]
}
?>

Viggen fucked around with this message at 20:48 on Oct 22, 2012

oRenj9
Aug 3, 2004

Who loves oRenj soda?!?
College Slice
Does anybody have any experience with HipHop? Are there any gotchas (besides the lack of eval) to look out for? Does it work pretty well for CLI PHP applications?

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.

oRenj9 posted:

Does anybody have any experience with HipHop? Are there any gotchas (besides the lack of eval) to look out for? Does it work pretty well for CLI PHP applications?

I think the first question anyone would ask is why are you using it?

oRenj9
Aug 3, 2004

Who loves oRenj soda?!?
College Slice

musclecoder posted:

I think the first question anyone would ask is why are you using it?

Haha, I had three paragraphs written about that, but decided to delete it. Suffice to say that distributing the software I'm currently working on as a pre-compiled binary would dramatically cut down on the amount of system administration work that I have to perform. My desire is to make it sufficiently difficult for anybody with access to the machine to modify our source code and have it redirect the data we collect somewhere else.

Viggen
Sep 10, 2010

by XyloJW

oRenj9 posted:

My desire is to make it sufficiently difficult for anybody with access to the machine to modify our source code and have it redirect the data we collect somewhere else.

How often do you push code? You're going to lose all of the benefits of PHP and end up with a slower runtime and people without the ability to decode a lot of the issues which occur..

Facebook uses this. Look at how stable Facebook is.

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.

oRenj9 posted:

Haha, I had three paragraphs written about that, but decided to delete it. Suffice to say that distributing the software I'm currently working on as a pre-compiled binary would dramatically cut down on the amount of system administration work that I have to perform. My desire is to make it sufficiently difficult for anybody with access to the machine to modify our source code and have it redirect the data we collect somewhere else.

Got it. That makes more sense, just ensuring you weren't going to say because you had scalability issues in line with Facebook's. :)

That said, I only played around with it when it was first released. It was easy enough to get set up (aside from originally reporting a bug https://github.com/facebook/hiphop-php/issues/2 it was easy after that). But that was 3 years ago, compiling it should be pretty simple now.

And I remember they got it working with Wordpress, so if they can do that, I imagine that your CLI app would be easier to get set up with it.

McGlockenshire
Dec 16, 2005

GOLLOCKS!

oRenj9 posted:

My desire is to make it sufficiently difficult for anybody with access to the machine to modify our source code and have it redirect the data we collect somewhere else.

Well, you can ease source code distribution by using PHARs, but source and data protection is going to be difficult to pull off. If you don't control the server, there is nothing -- nothing -- that you can do that a dedicated pirate can't undo. Your best protection against intellectual property theft isn't technological, it's legal.

Don't forget that the binaries that HipHop produces are huge. It's almost certainly not the solution you're looking for here.

Fleur Bleu
Nov 26, 2006

by Ralp

Begby posted:

Why are you calling kill?

I was browsing the mysqli function list, wondered what kill did, skimmed it's article, saw "kill process" and I thought "Thats sounds good, let's put that in.". Looking at it again, the examples use it the same way I do.
But your explanation makes sense, so I'll just scrap it.

Biowarfare posted:

Why are you not using PDO and parameterised queries? :smith:

I'm just looking things up as I go along, so I started with mysqli. If I have enough time I'll try and do everything in PDO instead. The manual has a lot of options, which is good, but I lack the knowledge to make the right choices.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Fleur Bleu posted:

I'm just looking things up as I go along, so I started with mysqli. If I have enough time I'll try and do everything in PDO instead. The manual has a lot of options, which is good, but I lack the knowledge to make the right choices.

Mysqli also supports parameterized queries (although I prefer PDO's syntax). You're better off using those instead of escaping all the input and building the raw statement in code.

The Gripper
Sep 14, 2004
i am winner
There's one thing about mysqli_stmt_bind_param() that can just gently caress right off: the first paramater being $types.

Other than for blobs, what's the goddamn use? A statement like:
PHP code:
$string = 12345;
$double = "5.6897";
$int = "111";
mysqli_stmt_bind_param($stmt, "sdi", $string, $double, $int);

mysqli_stmt_execute($stmt);
works even where none of the provided bind parameters actually match the typestring, and if you substitute that typestring for "ssi" so it doesn't match the schema, AND still provide param2 as a double anyway, it doesn't warn or do anything to stop the query.

I am angry because every time I use this goddamn thing I forget the typestring because literally no other implementation in any language requires it, and requiring it here and not even using it is literally hitler.

MySQL doesn't care e.g.
code:
mysql> SHOW CREATE TABLE dongs;
...
  `one` varchar(10) DEFAULT NULL,
  `two` double DEFAULT NULL,
  `three` smallint(6) DEFAULT NULL

mysql> INSERT INTO dongs VALUES(12345,"5.678","12345");
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM dongs;
+-------+--------+-------+
| one   | two    | three |
+-------+--------+-------+
| 12345 |  5.678 | 12345 |
+-------+--------+-------+
4 rows in set (0.00 sec)
so why should PHP?

The Gripper fucked around with this message at 22:08 on Oct 23, 2012

Mister Chief
Jun 6, 2011

Use PDO.

The Gripper
Sep 14, 2004
i am winner
I'm a MacGyver-esque coder that swoops in to patchwork fix broken things so my only contact with mysqli is in situations where it'd be rude to just replace it, from a maintenance standpoint at least. If I ever have a situation where I'm going to be jiggering an entire system and not just a small part then I'll be using PDO.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

The Gripper posted:

There's one thing about mysqli_stmt_bind_param() that can just gently caress right off: the first paramater being $types.

YES. I've used a wrapper around Mysqli that treats every parameter like a string, and I don't think there's even one example of the conversion causing different results. It's a completely worthless interface wart.

Zamujasa
Oct 27, 2010



Bread Liar

Fleur Bleu posted:

I was browsing the mysqli function list, wondered what kill did, skimmed it's article, saw "kill process" and I thought "Thats sounds good, let's put that in.". Looking at it again, the examples use it the same way I do.

The big problem I can imagine is if you're doing something big that the script isn't blocking over (e.g., running "UPDATE bigasstable SET x = y") you can kill the thread halfway into doing something. I only kill threads when something's gone completely off the rails and is locking tables and causing huge traffic jams.


My boss did the same thing with mysql_free_result() and just started copy-pasting it after every mysql_query() (even ones that mysql_free_result() makes no sense for, like INSERT or UPDATE). Please don't be my boss.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

The Gripper posted:

You can probably just stick with the original gpg, it's still being maintained.

From glancing at the list of improvements in gpg2 they mostly seem like desktop-application oriented features (S/MIME signing and smartcard support), so I'm pretty confident in tossing this problem into the "if it ain't broke, don't fix it" category.

I guess you could alias gpg2 to gpg2 --passphrase-fd 0 or replace the gpg2 binary with a script that does that, so you can supply the passphrase in STDIN (which should work like gpg does). No guarantees!

PS, thanks for this, I've got it working when run manually, need to do some security stuff to get it working through the Apache/PHP user but it works in concept at least. Thanks!

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.
So I'm having trouble fixing up a function I wrote for a homework assignment. Here's what I have so far:

E: Solved

The goal of the function is to handle a folder. If it's a folder it should call itself, but if its a .htm or .html file it should call the "Process file" function. My problem is that when it gets to a folder inside a folder, it prints "Inside the while loop with said folder" but then just stops and doesn't step through that folder.

Thanks in advance. I made it an image so I could take it down when I'm done.

Good Will Hrunting fucked around with this message at 20:17 on Oct 25, 2012

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!

Good Will Hrunting posted:

So I'm having trouble fixing up a function I wrote for a homework assignment. Here's what I have so far:

http://i.imgur.com/PwzaH.png

The goal of the function is to handle a folder. If it's a folder it should call itself, but if its a .htm or .html file it should call the "Process file" function. My problem is that when it gets to a folder inside a folder, it prints "Inside the while loop with said folder" but then just stops and doesn't step through that folder.

Thanks in advance. I made it an image so I could take it down when I'm done.

PM me the code and I'll take a look, I've got some time to kill.

Pile Of Garbage
May 28, 2007



Good Will Hrunting posted:

So I'm having trouble fixing up a function I wrote for a homework assignment. Here's what I have so far:

http://i.imgur.com/PwzaH.png

The goal of the function is to handle a folder. If it's a folder it should call itself, but if its a .htm or .html file it should call the "Process file" function. My problem is that when it gets to a folder inside a folder, it prints "Inside the while loop with said folder" but then just stops and doesn't step through that folder.

Thanks in advance. I made it an image so I could take it down when I'm done.

The problem is that is_dir() and is_file() need the full path to the directory/file you want to test whereas readdir() only returns the name of the directory/file.

Therefore line 6 of the function should probably be:
code:
if (is_dir($folderToProcess . '/' . $test) && ($test != ".") && ($test != "..")) {
and line 9 should be:
code:
} elseif (is_file($folderToProcess . '/' . $test)

Pile Of Garbage fucked around with this message at 20:24 on Oct 25, 2012

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.
You guys are the best. Seriously, thanks so much for the help.

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!

Good Will Hrunting posted:

You guys are the best. Seriously, thanks so much for the help.

My pleasure. Now pair that code with something like this and could be pretty slick looking!
http://jquery.bassistance.de/treeview/demo/

Impotence
Nov 8, 2010
Lipstick Apathy
I ran out of entropy today

root@530w6th-fs2app1:~# cat /proc/sys/kernel/random/entropy_avail
0


Should I regenerate any hashes or bcrypted things that were created or are they cryptographically sound (webapp, invalidate passwords for new registraitons during that period and make them reenter a new one on next login)?

McGlockenshire
Dec 16, 2005

GOLLOCKS!
That counter is only valid if you're reading out of /dev/random itself. Reads from /dev/random will block until there is enough entropy available. There's no need to worry or change anything, because none of the things you have mentioned are likely to have either used /dev/random directly. Keep in mind that /dev/urandom is a different thing than /dev/random.

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

fuf posted:

Yeah it's purely for looks, but I don't know how I would do it with just CSS. I need PHP to tell me whether a post should be on the start of a new row so I know when to close the last row and start a new one. I guess I could have written the CSS better so that each row didn't have its own container, but that's the way it's laid out...

Biowarfare posted:

div:nth-child(Xn+Y) {} or something?

Yep, you'd say:
code:
div.child_divs { float: left; }
div.child_divs:nth-child(3n) { clear: left; }

Flaggy
Jul 6, 2007

Grandpa Cthulu needs his napping chair



Grimey Drawer
code:
Fatal error: require() [function.require]: Failed opening required 'scalesheader.php' (include_path='.:/usr/local/php5/lib/php') 
in /home/content/v/a/n/vandebergscale/html/Products/Scales/indScales.php on line 53
So I am getting this error on our webpage, apparently our hosting switched us over to linux and broke all kinds of things on the website.

This is line 53:
<?php require("scalesheader.php"); ?>

We were on Windows hosting and they switched us to linux hosting and it broke everything. I need help bad as its basically messed up our entire website.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
Is that file readable by the program running the webserver?

Golbez fucked around with this message at 16:26 on Oct 26, 2012

Flaggy
Jul 6, 2007

Grandpa Cthulu needs his napping chair



Grimey Drawer

Golbez posted:

Is that file readable by the program running the webserver?

To be honest I am not quite sure. I compared it to other files that are being read on the webpage and those are working and these are not.

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.

Flaggy posted:

code:
Fatal error: require() [function.require]: Failed opening required 'scalesheader.php' (include_path='.:/usr/local/php5/lib/php') 
in /home/content/v/a/n/vandebergscale/html/Products/Scales/indScales.php on line 53
So I am getting this error on our webpage, apparently our hosting switched us over to linux and broke all kinds of things on the website.

This is line 53:
<?php require("scalesheader.php"); ?>

We were on Windows hosting and they switched us to linux hosting and it broke everything. I need help bad as its basically messed up our entire website.

Are you using any type of auto loader that depends on backward slashes instead of forward slashes? Something for Windows only that doesn't use PATH_SEPARATOR?

Also, fire your web host. How can they just change operating systems on you!? That's insane.

Flaggy
Jul 6, 2007

Grandpa Cthulu needs his napping chair



Grimey Drawer

musclecoder posted:

Are you using any type of auto loader that depends on backward slashes instead of forward slashes? Something for Windows only that doesn't use PATH_SEPARATOR?

Also, fire your web host. How can they just change operating systems on you!? That's insane.

The webhost was godaddy. Wooo. Unfortunately we are locked in with them. The coder we had for the site quit a while back and I was thrust into this role, to be quite honest, I don't know that much about php. I don't know if its using an autoloader or not. They switched us from Windows hosting to Linux hosting because they said Windows couldn't support the PHP. Our entire site is php. I appreciate any help.

DaWolfey
Oct 25, 2003

College Slice
Check the case of all the filenames and directories. Windows is not case sensitive, but Linux is.

Flaggy
Jul 6, 2007

Grandpa Cthulu needs his napping chair



Grimey Drawer

DaWolfey posted:

Check the case of all the filenames and directories. Windows is not case sensitive, but Linux is.

Thats exactly what it is, thank you so much, need a forums upgrade or anything? I think I owe a bunch of those in this thread. Thanks again.

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:
I am looking at learning PHP so I can use Zend Studio to make native apps. My question is are there any code academy type sites worth looking at? Where there is a built in console to test your tutorial code? I presume I just need to learn PHP and not Zend specific tutorials?

Adbot
ADBOT LOVES YOU

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

thegasman2000 posted:

I am looking at learning PHP so I can use Zend Studio to make native apps. My question is are there any code academy type sites worth looking at? Where there is a built in console to test your tutorial code? I presume I just need to learn PHP and not Zend specific tutorials?

I don't know about interactive tutorials for learning PHP, although there are some sandboxed PHP interpreters on the internet that you can use to test your code. You can also download and install PHP, and test your work out by running your scripts locally. The main thing you have to know about PHP is that there are a lot of really bad and outdated tutorials out there giving bad advice. Before you settle on a learning resource, try to find out when it was written, how actively it has been updated since then, and for which version of PHP it was written. The current major version of PHP is 5; don't use a resource that was written for PHP 4. One good way to identify fairly quickly whether a resource is giving bad advice is to look at its coverage of database interaction. If it tells the reader about how to access a database using the mysql_* family of functions, it's most likely a bad resource.

Edit: By the way, I just thought to check the OP of this thread, and it contains a link to W3Schools' PHP coverage, which is not exactly great. Does anybody know whether Duz still posts?

Hammerite fucked around with this message at 02:58 on Oct 27, 2012

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