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
Hammerite
Mar 9, 2007

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

thedaian posted:

You can do it. You probably have the syntax wrong (it's also not the best method, but it would work). No need for eval()

php:
<?
function red()
{
    echo 'RED!';
}

$color='red';

$color();?>

That's weird; I could have sworn I used the exact same syntax earlier and it didn't work, but I got it to work just now. I got some error about "function name must be a string" earlier.

Adbot
ADBOT LOVES YOU

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH

Plorkyeran posted:

It lets you pretend php has first-class functions.

Who's pretending?

php:
<?

$green = function()
{
    echo 'green!';
}

$green();

?>
5.3.0 :smug:


ok, not exactly first-class, but it's getting there

TreFitty
Jan 18, 2003

I have a question about PHP/MySQL and checkboxes. I want to store boolean values in a database table and when I submit a form with an unchecked box, it stores the value as '0'. That's great. When I submit a form with a checked box, it tries to store the value as 'on'. NOT great.

After the values are stored, I need to be able to repopulate the same form with that information at some point. Going through and changing all the values (all 30 of them) in the database from 'on' to something usable by my site by way of conditional statements is something that I probably shouldn't be doing.


I'm also using CodeIgniter for this site, but I don't think that matters here.

Any of you have any ideas?

edit: Pretty sure that setting the value of the checkbox in HTML to "1" will fix my problem, but I haven't tried it yet. Didn't want to delete my post in case some other moron like myself found this as a solution.

TreFitty fucked around with this message at 06:28 on Oct 20, 2009

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:

TreFitty posted:

I have a question about PHP/MySQL and checkboxes. I want to store boolean values in a database table and when I submit a form with an unchecked box, it stores the value as '0'. That's great. When I submit a form with a checked box, it tries to store the value as 'on'. NOT great.

After the values are stored, I need to be able to repopulate the same form with that information at some point. Going through and changing all the values (all 30 of them) in the database from 'on' to something usable by my site by way of conditional statements is something that I probably shouldn't be doing.


I'm also using CodeIgniter for this site, but I don't think that matters here.

Any of you have any ideas?

edit: Pretty sure that setting the value of the checkbox in HTML to "1" will fix my problem, but I haven't tried it yet. Didn't want to delete my post in case some other moron like myself found this as a solution.

Try setting value="1" in the checkbox <input>s? I think you end up with "on" if you don't specify the value.

Hammerite
Mar 9, 2007

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

TreFitty posted:

I have a question about PHP/MySQL and checkboxes. I want to store boolean values in a database table and when I submit a form with an unchecked box, it stores the value as '0'. That's great. When I submit a form with a checked box, it tries to store the value as 'on'. NOT great.

Just to check, you are escaping the data from the form aren't you? It's not entirely clear from your post. You will need to escape the form data if the application is ever going to be accessible by untrusted individuals.

ctz
Feb 6, 2003
This thread is the best ever!

Yossarko
Jan 22, 2004

Yeah it is pretty rad

Yossarko
Jan 22, 2004

Safe Mode is driving me crazy.

I need to turn it off, for various reasons, on my dedicated server running Plesk.

In Plesk, I can successfully turn it off by selecting the domain and unchecking Safe_Mode. But I make lots of websites, and the less time I spend configuring or checking various options the better. So I want Safe_Mode to be OFF by default, on the whole server.

Via SSH, in /etc/php.ini I turned it off (safe_mode = Off). It's still on.
Via SSH, in /etc/httpd/conf/httpd.conf I added "php_admin_value safe_mode 0". It is still on.

Checking a PHP_INFO, the MASTER value is OFF (yay!) but the LOCAL value is ON (gently caress!)

This leaves me to believe that, despite all my efforts to globally turn this fucker off, PLESK is setting it's local value ON unless I manually turn it off for each domain via Plesk interface (over 100 right now and growing every day).

I've tried over-riding in htaccess but it doesn't budge.

jasonbar
Apr 30, 2005
Apr 29, 2005

Yossarko posted:

Safe Mode is driving me crazy.

I need to turn it off, for various reasons, on my dedicated server running Plesk.

In Plesk, I can successfully turn it off by selecting the domain and unchecking Safe_Mode. But I make lots of websites, and the less time I spend configuring or checking various options the better. So I want Safe_Mode to be OFF by default, on the whole server.

Via SSH, in /etc/php.ini I turned it off (safe_mode = Off). It's still on.
Via SSH, in /etc/httpd/conf/httpd.conf I added "php_admin_value safe_mode 0". It is still on.

Checking a PHP_INFO, the MASTER value is OFF (yay!) but the LOCAL value is ON (gently caress!)

This leaves me to believe that, despite all my efforts to globally turn this fucker off, PLESK is setting it's local value ON unless I manually turn it off for each domain via Plesk interface (over 100 right now and growing every day).

I've tried over-riding in htaccess but it doesn't budge.

Did you restart Apache / whatever after you made the config change?

Yossarko
Jan 22, 2004

Yes, I restarted each time.

The PHP.ini turned the GLOBAL value off. So that's OK. On a "server-wide" level it's turned off. It's just Plesk being a frick'n bitch and turning it on by default for a domain (unless I switch it off manually later for that domain).

Maybe there is some way to let me turn it off via htaccess ? I don't mind adding the line to an htaccess for each domain as this will be automated / added into our framework. But right now, adding "php_admin_value safe_mode 0" doesn't change anything, so maybe I am not "allowed" to over-ride this ?

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Yossarko posted:

Yes, I restarted each time.

The PHP.ini turned the GLOBAL value off. So that's OK. On a "server-wide" level it's turned off. It's just Plesk being a frick'n bitch and turning it on by default for a domain (unless I switch it off manually later for that domain).

Get rid of Plesk, it's a giant piece of poo poo.

TreFitty
Jan 18, 2003

Hammerite posted:

Just to check, you are escaping the data from the form aren't you? It's not entirely clear from your post. You will need to escape the form data if the application is ever going to be accessible by untrusted individuals.
Yep. Filtering for cross site scripting, trimming, and form validating. Thanks for the heads up, though.

Yossarko
Jan 22, 2004

Hmmm, my problem might not be strictly sade_mode related.

I switched safe_mode off on a domain, and successfully get (via phpinfo or get_ini) safe_mode off.

But I'm trying to chmod some files to 0755 and I get "Operation not permitted".

The owner of the file (well, all files) is my FTP username. PHP script is running as "apache" I think.

I don't want to have to manually chmod files or folders in FTP, rather I want my script, when run, to chmod various directories and files (upload folders, temp folders, log files). Once I put my website online I run this script and it correctly sets the permissions.

How can I get around this ?

Standish
May 21, 2001

Yossarko posted:

But I'm trying to chmod some files to 0755 and I get "Operation not permitted".

The owner of the file (well, all files) is my FTP username. PHP script is running as "apache" I think.

I don't want to have to manually chmod files or folders in FTP, rather I want my script, when run, to chmod various directories and files (upload folders, temp folders, log files). Once I put my website online I run this script and it correctly sets the permissions.

How can I get around this ?
You need to be the owner of the file (or root) to call chmod on it. Have your PHP script make a temp copy of the file, delete the original, then copy your temp copy back over it.

Hanpan
Dec 5, 2004

I am having some really strange issues with __autoload. I have the following file:

code:
<?php

class Class1 {}
class Class2 {}

?>
Then, in another file I am doing this:

code:
<?php

new Class1;
new Class2;

?>
For some reason, __autoload is being called for both Class1 AND Class2, despite them residing in the same file. I am worried because surely this is unnecessary overhead? Any ideas why this is happening, and how I can avoid it?

Yossarko
Jan 22, 2004

Standish posted:

You need to be the owner of the file (or root) to call chmod on it. Have your PHP script make a temp copy of the file, delete the original, then copy your temp copy back over it.

That's clever.

Problem is, I don't have the permissions to delete the file before copying the temp file back over. Here is the function I wrote :

code:
function Chmodder($file,$permissions=0755) {
	if(!chmod($file,$permissions)) {
		if(copy($file,"/tmp/$file")) {
			if(!unlink($file)) {
				return "could not unlink...";
			} else {
				copy("/tmp/$file",$file);
				chmod($file,$permissions);
			}
		} else {
			return "could not copy";
		}
	} else {
		return "chmod is ok";
	}
}
Function returns "could not unlink"...

So I'm back at square one. Isn't there just same way (via php.ini) to let the user "apache" do whatever the gently caress he wants to files ? Chmod, unlink, etc ?

Yossarko fucked around with this message at 15:10 on Oct 21, 2009

v1nce
Sep 19, 2004

Plant your brassicas in may and cover them in mulch.
Sandish has the right idea. It sound like you've managed to get the files on there using one method (samba, ftp, ssh) which has created them under one user, we'll call him "Jeff", while the web server is running under another user, "www-data".

Both Jeff and www-data are different users in different groups. If the files are set to permissions 755 then the only person who can modify those files are the owner, in this case Jeff, while everyone else can only view them.

As Sandish suggested, you'll have to use ftp/samba/ssh to delete the files/directories you're trying to get www-data to edit, then use a script to make apache/php/www-data create the files. This way the file will be created under the ownership of www-data rather than Jeff.

Alternatively, depending on your level of access to the server, you can try setting the permissions of the file to 777 (so any user can edit them), or chown the file over to www-data.

Begby
Apr 7, 2005

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

Hanpan posted:

I am having some really strange issues with __autoload. I have the following file:

code:
<?php

class Class1 {}
class Class2 {}

?>
Then, in another file I am doing this:

code:
<?php

new Class1;
new Class2;

?>
For some reason, __autoload is being called for both Class1 AND Class2, despite them residing in the same file. I am worried because surely this is unnecessary overhead? Any ideas why this is happening, and how I can avoid it?

That is odd, not sure why that is happening.

You might as well put class1 and class2 each in their own file though. When all is said and done the overhead isn't that big of a deal, and it will just make it easier for yourself and others to edit your code if each class is in its own file.

I wouldn't worry about file hits until your site is so large and overloaded that it actually matters.

Yossarko
Jan 22, 2004

Yeah, I know. I understand, but isn't there any way to just give "apache" (www-data in my case) full rights ?

This is for a framework that is deployed (via FTP) by different people onto my server. I want to make sure all websites on any domain, as long as they are using my framework running on my server, work corrrectly.

This means I don't want to have to go connecting via FTP to each site and manually chmodding files or folders, or telling them to do so. They dump the framework (website) to the FTP I give them, the domain is set up and when running the website the first time it sets off a script to set all the permissions for uploads and logs etc.

So the files are always going to be put onto the server by "ftp-user", but I need "apache" to be able to do whatever he wants to do (chmod, unlink, write, etc) without needing any human intervention or manual chmodding.

This HAS to be possible no ? I have access to the php.ini or httpd.conf. If this was just for one website I wouldn't care and would just 777 certain folders and be gold. But the number of websites on the server and using the framework grow every day, and I need to be able to do as little as possible in the deployement of these websites while being 100% that my clients can upload files if they have to, that everything will be logged, etc.

As for chown, it won't let me change the owner (unless maybe if the file was already 777 ?).

Yossarko fucked around with this message at 15:45 on Oct 21, 2009

Yossarko
Jan 22, 2004

To go into more detail, I actually have this working at the moment (and have had for some time) by using the PHP FTP commands. My "setup" script connects to FTP and chmods the files and folders I need to 777. It works.

Problem is, 1) I don't like this method, it's a hack and 2) I have to fill out the FTP username / password combo in a config file for it to work, which occasionlly is forgotten or mistyped.

Oh, and my dev machine (windows XP running WAMP) does all this fine, it lets me chmod and whatever, probably because it doesn't have the FTP username or WAMP is running as root or something. This also means I have SWITCH's everywhere to know if I have to do things via FTP (online) or normally (localhost). It's a headache.

Yossarko fucked around with this message at 15:51 on Oct 21, 2009

Standish
May 21, 2001

Yossarko posted:

Yeah, I know. I understand, but isn't there any way to just give "apache" (www-data in my case) full rights ?
Not really, and running your webserver as root is a really bad idea anyway.

Your best bet would probaby write a tiny C program that is owned by the FTP upload user, and has the setuid bit set, and that calls the chmod(2) library function on its (carefully validated) argument. You can then invoke that program from PHP using system() or exec() whatever.

Edit: or depending on which FTP server software you're using, you might be able to set the default umask so the permissions on uploaded files are the ones you want to begin with.

Standish fucked around with this message at 15:58 on Oct 21, 2009

Munkeymon
Aug 14, 2003

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



If he just changes the group the files belong to to Apache's group, would that allow Apache to write to them without being stupidly dangerous?

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Hanpan posted:

I am having some really strange issues with __autoload. I have the following file:
For some reason, __autoload is being called for both Class1 AND Class2, despite them residing in the same file. I am worried because surely this is unnecessary overhead? Any ideas why this is happening, and how I can avoid it?

How big is your __autoload function that you're worried about it causing overhead?

v1nce
Sep 19, 2004

Plant your brassicas in may and cover them in mulch.
That could work, though the files would still need to be masked to 775 if they're only part of the same group. It is worth looking into if you want to keep the users as individuals.

What we do, at least with samba, is configure samba to create files under the same user as apache is running and umask them to 755. What FTP server are you using? I'd expect there to be things you can add or change with the configuration.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Hanpan posted:

I am having some really strange issues with __autoload. I have the following file:

code:
<?php

class Class1 {}
class Class2 {}

?>
Then, in another file I am doing this:

code:
<?php

new Class1;
new Class2;

?>
For some reason, __autoload is being called for both Class1 AND Class2, despite them residing in the same file. I am worried because surely this is unnecessary overhead? Any ideas why this is happening, and how I can avoid it?


First of all, you don't need to use autoload if your classes are all defined in the same file. Use an include or require_once or something. You should be writing each class in a separate file anyways though.

Second of all, read the docs on using autoload. Specifically the first sentence:

quote:

one PHP source file per-class definition

Rat Supremacy
Jul 15, 2007

The custom title is an image and/or line of text that appears below your name in the forums
Is there a FastCGI process manager (like lighttpd's spawnfcgi.exe, but that is cygwin and thus doesn't work with native php-cgi.exe) that supports PHP and is win32 native?

I've made a sh/sc thread but in retrospect perhaps the coding forum is a better place to ask.

http://forums.somethingawful.com/showthread.php?threadid=3217679&pagenumber=1

I'm basically trying to build an all-native windows/nginx/php setup. It works currently using php-cgi.exe -b 127.0.0.1:9000 to simply get it working, but a process manager would actually utilise the benefits of fcgi (multiple threads etc).

Rat Supremacy fucked around with this message at 10:11 on Oct 23, 2009

MrMoo
Sep 14, 2000

I can't imagine it's going that difficult to build under MinGW32?

Lighty seems to have a native port via MinGW32 and bundles it's own version of spawn-fcgi, is that any good?

Rat Supremacy
Jul 15, 2007

The custom title is an image and/or line of text that appears below your name in the forums
Ah, found this:
http://en.wlmp-project.net/downloads.php?cat=other

It seems to be pretty loving awesome.

LP0 ON FIRE
Jan 25, 2006

beep boop
I want to add a number of days to a current day, current month and current year all as separate variables. I know there should be an easy way to do this, but I haven't been able to find any clear way how.

Say the current date is Oct 23, 2009:

php:
<?
    $currentDayPlus =date("j")+10 days;
//Equals 2
    $currentMonthPlus=date("n")+10 days;
//Equals November
    $currentYearPlus =date("Y")+ 10 days;
//Equals 2009
?>
I just want to add a number of days on, and be able to echo back the result.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

awdio posted:

I want to add a number of days to a current day, current month and current year all as separate variables. I know there should be an easy way to do this, but I haven't been able to find any clear way how.

Say the current date is Oct 23, 2009:

php:
<?
    $currentDayPlus =date("j")+10 days;
//Equals 2
    $currentMonthPlus=date("n")+10 days;
//Equals November
    $currentYearPlus =date("Y")+ 10 days;
//Equals 2009
?>
I just want to add a number of days on, and be able to echo back the result.

http://www.php.net/manual/en/datetime.add.php

Begby
Apr 7, 2005

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

awdio posted:

I want to add a number of days to a current day, current month and current year all as separate variables. I know there should be an easy way to do this, but I haven't been able to find any clear way how.

Say the current date is Oct 23, 2009:

php:
<?
    $currentDayPlus =date("j")+10 days;
//Equals 2
    $currentMonthPlus=date("n")+10 days;
//Equals November
    $currentYearPlus =date("Y")+ 10 days;
//Equals 2009
?>
I just want to add a number of days on, and be able to echo back the result.

There are lots of ways to skin this cat, here is one way

A date is stored as the number of seconds since some other fixed date. So you can calculate the number of seconds in a day, and add it onto your date

php:
<?
$secondsInADay = 60 * 60 * 24;

$myDate = time();
$datePlus = $myDate + $secondsInADay * 10;

$currentDayPlus = date("j", $datePlus);
$currentMonthPlus = date("n", $datePlus);
$currentYearPlus = date("Y"m $datePlus);

?>

Standish
May 21, 2001

Begby posted:

$secondsInADay = 60 * 60 * 24;
Not all days have 24 hours.

Sneaking Mission
Nov 11, 2008

I always enjoy playing around with the strtodate function

php:
<?
$ten_days_from_now = strtodate("+10 days");

$currentDayPlus = date("j", $ten_days_from_now);
$currentMonthPlus = date("n", $ten_days_from_now);
$currentYearPlus = date("Y"m $ten_days_from_now);
?>

Begby
Apr 7, 2005

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

Standish posted:

Not all days have 24 hours.

Oh, thanks for raining on my parade by getting all exact and technical on my rear end ;)

LP0 ON FIRE
Jan 25, 2006

beep boop

dcallen posted:

I always enjoy playing around with the strtodate function

php:
<?
$ten_days_from_now = strtodate("+10 days");

$currentDayPlus = date("j", $ten_days_from_now);
$currentMonthPlus = date("n", $ten_days_from_now);
$currentYearPlus = date("Y"m $ten_days_from_now);
?>

That's how you use it! I've used this before a long time ago. Makes it so easy. Thanks very much.

Cad_Monkey2
Feb 15, 2004

I'm having some problems with the mail() function.
I'm sending a mail out using html and attempting to use addional headers (as described here.)

The mail will send out just fine with these additional headers...
code:
$headers =  'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
But when I add headers like this..
code:
$headers .= "To: " . $firstname . " " . $lastname . " <" . $email . ">" . "\r\n";
$headers .= "From: " . $f_firstname . " " . $f_lastname . " <" . $f_email . ">" . "\r\n";
.. as described in the above link to php.net in the format of..
code:
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
.. it falls over and doesn't send. I've tried hard coding it, constructing it in a seperate string before passing it into the $header, using the above code from php.net but it still doesn't work.

chemosh6969
Jul 3, 2004

code:
cat /dev/null > /etc/professionalism

I am in fact a massive asswagon.
Do not let me touch computer.
I don't normally use PHP and need help with a super easy exception issue that I can't seem to get working right for some reason.

So I go through a list of ids pulled from a db. We have another php file filled with functions that are strings and the function names are something like fn_234().

In theory, all the ids have a corresponding function but in reality other people change the db and the function might not exist. Ignoring all the issues with how that works, I just want to be able to print something instead of having the entire thing break with "Fatal error: Call to undefined function fn_970()"

Here's the code
code:
$id = $ScholList['id'];
$fn_id = 'fn_'.$id;		
$schol = $fn_id();
I've tried something like this but it still dies on the error where the function's called instead of screaming error repeatedly.
code:
$id = $ScholList['id'];
$fn_id = 'fn_'.$id;
try{		
$schol = $fn_id();
}
catch (Exception $e) {echo 'error error error'}
What stupid thing am I missing?

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Sounds like you want http://php.net/manual/en/function.function-exists.php

99% sure there's a better way to go about what you are trying to accomplish though

chemosh6969
Jul 3, 2004

code:
cat /dev/null > /etc/professionalism

I am in fact a massive asswagon.
Do not let me touch computer.

fletcher posted:

Sounds like you want http://php.net/manual/en/function.function-exists.php

99% sure there's a better way to go about what you are trying to accomplish though

If you saw the rest of the code, you'd know there's a better way to do the entire thing. There's all sorts of wacky poo poo in there like if else statements that will never be false, if a change is made to a certain thing it needs to be duplicated to two other files and I just discovered yesterday that one of them doesn't even work in the first place.

The plan was to rework everything starting around May but all the meetings got pushed back until a week ago and it goes up in about a week. I'm pretty much just rigging it to work until I can get some of the things setup in the way they should've been in the first place, and until the entire thing can just be rebuilt from the ground up.

Adbot
ADBOT LOVES YOU

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

chemosh6969 posted:

If you saw the rest of the code, you'd know there's a better way to do the entire thing. There's all sorts of wacky poo poo in there like if else statements that will never be false, if a change is made to a certain thing it needs to be duplicated to two other files and I just discovered yesterday that one of them doesn't even work in the first place.

The plan was to rework everything starting around May but all the meetings got pushed back until a week ago and it goes up in about a week. I'm pretty much just rigging it to work until I can get some of the things setup in the way they should've been in the first place, and until the entire thing can just be rebuilt from the ground up.

After I read this post I sang "P-H-P" aloud to the tune of AC/DC's T.N.T. :rock:

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