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
Oh My Science
Dec 29, 2008

KuruMonkey posted:

I would make that string be constructed on one line, and check the error line changes; I suspect your error isn't in that line at all.

It certainly was not, and I am no longer confused. Essentially, I gave up on the mod because it royally messed up the formatting of the entire forum.

Thank your for all the help.

Adbot
ADBOT LOVES YOU

duck monster
Dec 15, 2004

Oh god my current job is driving me nuts.

The place I started working for has a loving *massive* inhouse CMS , and its atrociously written. You know the sort. Load in the chrome, ?action=xxxxxxx include (getIncludeFile($_GET['action'])); blah

All procedural. Theres a custom database layer that doesn't seem to understand cursors and cant do prepared statements.

On the upside, it has smarty, which is something I guess, since its a 40 man dev team.

Or is it? One of the sites had a smarty template with about 4-5 thousand lines of smarty conditional template logic mangled with javascript that generated custom javascipt to deal with some poo poo that was all if product='aaaa' then bbbbbbb else if product = 'bbbb' then ccccc else if pro<blah> for thousands of lines.

gently caress PHP with a rusty screwdriver. It encourages some *horrifying* coding sometimes..

I'm dying for a django job here folks.

KuruMonkey
Jul 23, 2004
Don't blame the tools; blame the Tools using the tools.

Cad_Monkey2
Feb 15, 2004

I have the problem where a regular text input two word value is being passed into a hidden input but one one word coming out of it.

Like this

Page 1
text input box containing "two words"

Page 2
picks up "two words" from text input box, displays "two words" as text and stores "two words" in a hidden input.

Page 3
Displays "two" from the hidden input instead of "two words"

This is what I'm using as the hidden input line:

code:
echo "<input type='hidden' name='address_line3' value='$address_line3'>";
I've tried it without quotes but is the same result

code:
echo "<input type='hidden' name='address_line3' value=$address_line3>";
Can anybody think of a reason why this is happening? It's only happening with input derived from text inputs..

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH
Add quotes around the second input's value attribute.

Cad_Monkey2
Feb 15, 2004

supster posted:

Add quotes around the second input's value attribute.

I did, I did it without quotes and with quotes. Even with quotes it didn't pass the values through.

I might as well pass all this stuff through through sessions, can you see a downside to using sessions to pass through about 25 values?

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
You're only showing us half the party. Show us the code from page 2 that stores the post value as $address_line3. Is it a simple assignment? "$address_line3 = $_POST['address_line3']"? I've never had any problem with text input boxes sending only one thing...

Also, is the name of the text input box "address_line3", or are there any [] brackets in it?

Cad_Monkey2
Feb 15, 2004

This sets the hidden value
code:
echo "<input type='hidden' name='address_line1' value='$address_line1'>";
And this catches it on the same page (after a submit)
code:
$address_line1 = $_POST['address_line1'];
I have dozens of this type of hidden values but only the ones originating from text inputs are borked.

Should I dismiss the idea of passing data through multiple hidden values or should I go through sessions?

Zorilla
Mar 23, 2005

GOING APE SPIT

Cad_Monkey2 posted:

Should I dismiss the idea of passing data through multiple hidden values or should I go through sessions?
If I were doing a multipage form, I would strongly recommend sessions. In the mean time, do either of these work?

php:
<?php
echo "<input type='hidden' name='address_line1' value='".$address_line1."' />";
?>
Or this? (which I would recommend since using echo statements to output HTML produces really lovely code)

php:
<?php
// code
?>
<input type="hidden" name="address_line1" value="<?php echo $address_line1?>" />
<?php
// more code
?>
Get Firebug and turn on the Net console so you can see what fields get sent when you post.

Zorilla fucked around with this message at 20:46 on Jan 26, 2009

sonic bed head
Dec 18, 2003

this is naturual, baby!

Cad_Monkey2 posted:

This sets the hidden value
code:
echo "<input type='hidden' name='address_line1' value='$address_line1'>";
And this catches it on the same page (after a submit)
code:
$address_line1 = $_POST['address_line1'];
I have dozens of this type of hidden values but only the ones originating from text inputs are borked.

Should I dismiss the idea of passing data through multiple hidden values or should I go through sessions?

Install the Live HTTP headers firefox extension and see if the value for "address_line1" is being sent at all. If it isn't, there's probably a naming problem. If it is, then try echoing it directly onto the page to see if the value is being assigned to $address_line1 correctly. If it is, continue with more debugging.

This is really one of those times to refine your debugging skills. There are a lot of ways that you could figure out what is wrong.

Civil
Apr 21, 2003

Do you see this? This means "Have a nice day".
Does anyone have a decent PHP-based directory index generator? I've stolen a few off websites, and they all suck, and I'm too green at this to do a decent job myself.

Our server admin turned off index generation, which is fine, as a lot of our filenames are long enough that they're truncated with a standard server generated index, which isn't desirable in this application.

Something simple that just shows Filename, denotes [directory names] differently, shows file size, maybe file date, and can sort columns, and is smart enough not to list index.php. I don't know, I figure this has to be common enough that someone has created a nice one.

niralisse
Sep 14, 2003
custom text: never ending story

Civil posted:

Does anyone have a decent PHP-based directory index generator? I've stolen a few off websites, and they all suck, and I'm too green at this to do a decent job myself.

Our server admin turned off index generation, which is fine, as a lot of our filenames are long enough that they're truncated with a standard server generated index, which isn't desirable in this application.

Something simple that just shows Filename, denotes [directory names] differently, shows file size, maybe file date, and can sort columns, and is smart enough not to list index.php. I don't know, I figure this has to be common enough that someone has created a nice one.

They're so easy to write with DirectoryIterators that you could probably manage it yourself.

http://us.php.net/manual/en/class.directoryiterator.php

Cad_Monkey2
Feb 15, 2004

I'll be testing sonic bed head and Zorrilla's replies tonight but I've pretty much abandoned the idea of sending stuff through hidden inputs and switching to sessions instead.

Cheers guys.

Zorilla posted:

(which I would recommend since using echo statements to output HTML produces really lovely code)

Do you mean it produces lovely HTML code or just hard to read php code?

Internet Headache
May 14, 2007

Cad_Monkey2 posted:

Do you mean it produces lovely HTML code or just hard to read php code?
1. Passing things through echo probably uses more resources, especially if you're using double quotes. Text outside of PHP tags is fed directly to the output buffer while echo goes through some processing.
2. IDEs ignore HTML inside of PHP tags, so forget syntax highlighting, block folding (instantly skipping past divs or tables), and DOM error feedback (forgetting a closing tag or some other HTML syntax error). If you don't know what these are, try Eclipse.

Internet Headache fucked around with this message at 12:54 on Jan 27, 2009

Cad_Monkey2
Feb 15, 2004

Right, I've downloaded the All-in-One Eclipse PDT + Zend Debugger Package and I'll be having a play with that while reviewing and simplifying my code tonight, thanks for the help Internet Headache. I've got loads of php pages to write so I'd rather iron out these problems and get into 'best practice' while in the early stages.

Zorilla
Mar 23, 2005

GOING APE SPIT

Cad_Monkey2 posted:

Do you mean it produces lovely HTML code or just hard to read php code?

Both. You end up with a whole lot of the word "echo" in your PHP and the HTML output likely won't be tabbed properly, and if you didn't litter your code with "\n" all over the place, the output will likely all on one line too.

If you want to assign large blocks of HTML to variables, either use output buffers or heredoc statements (I recommend the first since it will keep your HTML context highlighted in most editors).

Zorilla fucked around with this message at 14:04 on Jan 27, 2009

Cad_Monkey2
Feb 15, 2004

You've pretty much hit the nail on the head here, Zorrila. Echos and \n all over it with the added benefit of sometimes forgetting to end the php line with ;. The actual html output (code wise) looks pretty good though. Oh well, as I said, I'd rather find this stuff out at the beginning of a project than at the end.

Cheers for the advice everybody.

MeTa_Cunt0rV2.1
Jul 30, 2004

by elpintogrande
I have inherited a web server from someone else at work and up till now all websites have been developed using asp .net

I only know php so I plan to install php on the web server but I am totally paranoid that doing so will cause the asp.net driven web applications to stop working.

Can anybody reassure me this is not the case or point me in the correct direction for more reading?

Is this thread the best place to post this I wonder?

MeTa_Cunt0rV2.1 fucked around with this message at 15:49 on Jan 27, 2009

SuckerPunched
Dec 20, 2006

Just do a Google search for "Install PHP IIS <IIS version number>". You can definitely run ASP.NET and PHP together on the same server peacefully.

MeTa_Cunt0rV2.1
Jul 30, 2004

by elpintogrande
Thanks, just wanted to make sure. I knew I was being paranoid but I've been stitched up so many times by thinking "things will be fine if I do this..."

er0k
Nov 21, 2002

i like ham.

Civil posted:

Does anyone have a decent PHP-based directory index generator? I've stolen a few off websites, and they all suck, and I'm too green at this to do a decent job myself.

Our server admin turned off index generation, which is fine, as a lot of our filenames are long enough that they're truncated with a standard server generated index, which isn't desirable in this application.

Something simple that just shows Filename, denotes [directory names] differently, shows file size, maybe file date, and can sort columns, and is smart enough not to list index.php. I don't know, I figure this has to be common enough that someone has created a nice one.

I wrote one of these once http://r0klist.sf.net/

it's all procedural and has echos all over but I don't give a gently caress!

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 this legal?

code:
if ($var == ('a' || 'b'))
Whenever I try it, it doesn't seem to work; I have to split it out, like:

code:
if (($var == 'a') || ($var == 'b'))
Am I doing it wrong?

scr0llwheel
Sep 11, 2004
ohelo
It's certainly legal but it isn't doing what you're hoping it is doing :)

Golbez posted:

code:
if ($var == ('a' || 'b'))

The statement inside of the inner-most parenthesis is interpreted first, always resulting in TRUE (see http://www.php.net/manual/en/types.comparisons.php). Therefore, your conditional statement will always be:

code:
if ($var == true)
If you'll only be testing a couple of values, I would definitely split up the conditional checks like you are doing. If you'll be testing for a lot of values, you can do something similar to:

code:
if (in_array($var, array('a', 'b')))

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
Aha. Thanks. :)

Super Delegate
Jan 20, 2005

ƃɐlɟ ǝɥʇ
This is being used instead of mysql_real_escape_string. Is there a way to make prepareformysql the same as the real escape string.

php:
<?
function prepareformysql($sqt)
{
    return str_replace("'", "''", $sqt);
}?>


It is used a bunch of times. Here are two examples.

php:
<?
$to_action = prepareformysql($_REQUEST['to_action']);?>


php:
<?
if(!$dbc->sql_exec("update users set info='".prepareformysql($_POST['info'])."', insert_date = insert_date where id = ".prepareformysql($_POST['user_id'])))?>

J. Elliot Razorledgeball
Jan 28, 2005
Can I install pdo_mssql on a PHP 4.x Linux installation?

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker

Super Delegate posted:

...

Easiest would be
code:
function prepareformysql($sqt)
{
    return mysql_real_escape_string($sqt);
}
better would be a search-replace /prepareformysql/mysql_real_escape_string/ on everything.

But the best way would be to see what kind of $dbc object is and hope it supports prepared statements, so you can use them instead.

spiritual bypass
Feb 19, 2008

Grimey Drawer

J. Elliot Razorledgeball posted:

Can I install pdo_mssql on a PHP 4.x Linux installation?

At work I use MSSQL on Linux with PHP5 and I had to compile my own package. It's a huge pain.

J. Elliot Razorledgeball
Jan 28, 2005

royallthefourth posted:

At work I use MSSQL on Linux with PHP5 and I had to compile my own package. It's a huge pain.

Yeah I'm not looking forward to it. Do you have any tips? Is it even compatible with PHP 4.x though?

spiritual bypass
Feb 19, 2008

Grimey Drawer
I've never even used PHP4 before, but I followed these instructions which helped me a great deal.
http://panthar.org/2006/06/15/php-with-mssql-on-ubuntu-606/

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Is there a good way to handle nodes with perios in their names when using simplexml?

code:
<this.will.break.poo poo>
  <oh.crap>Haha, loser.</oh.crap>
</this.will.break.poo poo>
Without leaning on xpath all over the place?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
My website has a particular PHP file "commonthings.php", outside of webroot, that almost every single script "includes" right at the start so that things like the database connection are set up before the real work of the script starts running. commonthings.php contains two types of content:

1) variables like the database name, database account name and password, email address and account password, switches that allow me to enable or disable login, the site's address (for echoing into scripts); stuff that will need to be clear and uncluttered for when I want to drop in and change things.

2) stuff that is set in stone and that I don't anticipate changing: the statement that sets up the database connection, a function for echoing the form that allows login.

Since this file is called so very often, would there any kind of performance increase (or indeed decrease) if I were to eliminate whitespace completely throughout the block of content of type (2)? I mean, instead of having something that looks like

php:
<?
$a = 1;
$b = 4;
$c = 9;
$cxn = mysqli_connect($host,$user,$password,$database)
    or die ('Failed to connect to database');
function EchoLoginForm () {
    echo 'some stuff';
}
?>
have it look like this (line breaks added only to avoid breaking tables):

php:
<?
$a=1;$b=4;$c=9;$cxn=mysqli_connect($host,$user,$password,$database)or
die('Failed to connect to database');function EchoLoginForm(){echo'some
stuff';}
?>

waffle iron
Jan 16, 2004
When the PHP file it is interpreted and then becomes OPCODEs that are excuted in the Zend Engine. The code should generate the same OPCODEs regardless of formatting.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
What I meant is, is it any faster at all at reading and interpreting the file? But I take it from your answer that no, it is not any faster. Thanks!

MononcQc
May 29, 2007

Hammerite posted:

What I meant is, is it any faster at all at reading and interpreting the file? But I take it from your answer that no, it is not any faster. Thanks!

The biggest speed upgrades you can have when including a file many times is to not include it many times. Usually, you'll use statements like require_once("file.php");, which are pretty slow compared to imports in many other languages. A way to bypass this is to use a defined constant once a file is loaded and check it before including it again. This makes ugly code though, and in most cases is not worth it at all. I do not recommend it.

I may not have everyone's approval on this, but optimizing the server-side code is rarely what you need to do to speedup your website.
Overall, you'll get a bigger speedup for the client making sure everything is gzipped and using a cache than optimizing trivial things like file imports. As a general rule, downloading images, css and/or javascript files is longer than the processing needed server-side.

Otherwise, the only big bottlenecks which really have a noticeable effect are operating on large amounts of data (image rendering, nested loop on large datasets, bad written templating engines without caching ever, etc) and SQL queries (look at indexes and whatnot, also use caches if possible).

Ferg
May 6, 2007

Lipstick Apathy

MononcQc posted:

The biggest speed upgrades you can have when including a file many times is to not include it many times. Usually, you'll use statements like require_once("file.php");, which are pretty slow compared to imports in many other languages. A way to bypass this is to use a defined constant once a file is loaded and check it before including it again. This makes ugly code though, and in most cases is not worth it at all. I do not recommend it.

I may not have everyone's approval on this, but optimizing the server-side code is rarely what you need to do to speedup your website.
Overall, you'll get a bigger speedup for the client making sure everything is gzipped and using a cache than optimizing trivial things like file imports. As a general rule, downloading images, css and/or javascript files is longer than the processing needed server-side.

Otherwise, the only big bottlenecks which really have a noticeable effect are operating on large amounts of data (image rendering, nested loop on large datasets, bad written templating engines without caching ever, etc) and SQL queries (look at indexes and whatnot, also use caches if possible).

What about passing by reference when necessary? I'm currently working on a project that was shooting back enough data to crash FirePHP, so I was thinking if I passed things around by reference (since most of it is references to constant data anyways) it might help improve performance.

MononcQc
May 29, 2007

Ferg posted:

What about passing by reference when necessary? I'm currently working on a project that was shooting back enough data to crash FirePHP, so I was thinking if I passed things around by reference (since most of it is references to constant data anyways) it might help improve performance.
If you use large arrays or objects, passing by reference will certainly have its advantages if you can make sure you won't modify data when you shouldn't. It's going to give some savings on processing time and memory usage for sure. To some extent, this is more about design than optimization.

What kind of data do you have? why does it need to be moved around? It may be that the design of the solution is not right, rather than the moving data necessary.

Ferg
May 6, 2007

Lipstick Apathy

MononcQc posted:

If you use large arrays or objects, passing by reference will certainly have its advantages if you can make sure you won't modify data when you shouldn't. It's going to give some savings on processing time and memory usage for sure. To some extent, this is more about design than optimization.

What kind of data do you have? why does it need to be moved around? It may be that the design of the solution is not right, rather than the moving data necessary.

I've got a lot of data being pulled, stored, and processed. I'm using a facade design pattern to hide the messy subsystem where all of this information is stored and clients will be pulling the information out as arrays. So when I say moved around all I'm saying is it goes from Source -> Facade -> Client.

Not being able to refrain users from changing the data will suck, but it is what it is. The performance of FirePHP once I switched to references and spaced out calls was pretty amazing.

A hamburger?
Jul 16, 2004
So, this is perhaps a silly question, but I've never experienced it before:

I've been developing a site on a server that is mostly PHP/MYSQL. To keep parts of the code clean, in the header of the page I do a require(dbconnect.php); - the file which does all the connecting to the database. It all worked fine...

Now I've moved this project to a new server, and - as far as I can tell - the server is closing the connection immediately after the require(). Now, normally the connection is automatically closed at the "end of the script" and I always assumed this meant the end of the page, etc. but it seems, in this case to mean the first time it sees a ?> which might be the end of that piece, but hardly the end of the page.

If this is correct, obviously coding the entire page in pure PHP (rather than partial PHP, partial HTML) would fix the problem, but I'm too deep to want to consider that, so any other option is better.

edit: Figured out, and reminded myself of my love/hate with coding... don't leave old bits of code in files that reconnect to other databases! That won't work at all. :(

A hamburger? fucked around with this message at 22:25 on Jan 29, 2009

Adbot
ADBOT LOVES YOU

Ferg
May 6, 2007

Lipstick Apathy
While we're on the subject of speed, what is everybody's thoughts on a heavily OOP written site? The lack of structs in PHP makes it difficult to create lightweight objects, but with associative arrays you can easily work around this but not without eliminating intuitive design decisions. Is a lot of OOP going to inhibit performance a lot?

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