12 Replies - 551 Views - Last Post: 07 April 2012 - 03:13 AM Rate Topic: -----

#1 hiddenghost  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 37
  • View blog
  • Posts: 599
  • Joined: 15-December 09

php ini include

Posted 06 April 2012 - 04:49 PM

Is it suitable to place all php_ini() directives in one file and include that file in all other pages?

Like:
File: ini.php
<?php
ini_set();
ini_set();
?>


Then:
<?php
include 'ini.php';
?>


Is This A Good Question/Topic? 0
  • +

Replies To: php ini include

#2 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3052
  • View blog
  • Posts: 4,575
  • Joined: 08-June 10

Re: php ini include

Posted 06 April 2012 - 04:55 PM

Sure. As long as all the directives set in your "ini.php" file should apply to every one of those pages.

However, it may be simpler to just set the directives in the PHP configuration file itself, if they are meant to apply to all pages being served. - If you're on a shared host and can't edit the main php.ini file, check if they allow you to create a per-directory config file. Sometimes you are allowed to create "php.ini" files in the web-root of your own space to set directives specific to your own website. (With some restrictions, of course.)
Was This Post Helpful? 0
  • +
  • -

#3 hiddenghost  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 37
  • View blog
  • Posts: 599
  • Joined: 15-December 09

Re: php ini include

Posted 06 April 2012 - 10:21 PM

Well it doesn't even matter any way.

The thing I really want to change is magic quotes to off and it turns out that can't be set in the ini_set function.

My host uses shared hosting and they have magic quotes on.

I tried .htaccess and that didn't work.
I tried a php.ini file in my script file and that just broke my script.
The page just came up blank.

There are already a bunch of entries with escapes. It doesn't seem like that would effect it to me being that they're just characters.

I'm using pdo for mysql.

There is a warning in the error logs about the .htaccess setting being misspelled or something.
It's in there spelled right so I don't know.

No errors for php.ini with magic quotes off. Just a blank page.

This is what the help at my host said:
Using the php.ini file would be the route to go rather than the .htaccess file. If it is breaking your script by turning it off than you will need to modify your script to work with it, otherwise it is suggested to be on.

I almost considering using the globals to remove escapes like on this post here:
http://stackoverflow...-shared-hosting

At least until php6 is out, or I'll just move to another host.
Was This Post Helpful? 0
  • +
  • -

#4 hiddenghost  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 37
  • View blog
  • Posts: 599
  • Joined: 15-December 09

Re: php ini include

Posted 06 April 2012 - 10:32 PM

Found this:
$_REQUEST = array_map('stripslashes', $_REQUEST);

over here:
http://stackoverflow...ini-or-htaccess

Does that look any good for magic quotes?

Sorry I've now turned this thread into a thread about magic quotes.
Was This Post Helpful? 0
  • +
  • -

#5 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3052
  • View blog
  • Posts: 4,575
  • Joined: 08-June 10

Re: php ini include

Posted 07 April 2012 - 01:19 AM

Quote

I tried a php.ini file in my script file and that just broke my script.
The page just came up blank.

What do you mean? The "php.ini" file doesn't really have anything to do with the actual script files. You just create a "php.ini" file in the web-root of your site and put this line into it:
magic_quotes_gpc = Off


You shouldn't be including this into your PHP scripts or anything like that.

Quote

At least until php6 is out, or I'll just move to another host.

PHP6 is pretty much dead at this point, but don't worry, the Magic Quotes feature has been removed as of PHP 5.4 [ref.] :)
Was This Post Helpful? 0
  • +
  • -

#6 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3052
  • View blog
  • Posts: 4,575
  • Joined: 08-June 10

Re: php ini include

Posted 07 April 2012 - 01:45 AM

View Posthiddenghost, on 07 April 2012 - 05:32 AM, said:

Does that look any good for magic quotes?

It works fine, I suppose, but I would be much more inclined to use a per-variable approach. I never liked applying a function to all the request data before any of it is needed.

It's not that hard to define a function to strip the tags automatically when needed. I would probably try something like this:
class Request 
{
	/**
	 * Finds and returns the value within the given array,
	 * removing the slashes if magic_quotes_gpc is on.
	 * @param string $key The key of the array element to find.
	 * @param array $source The array to be searched.
	 * @returns mixed The value if it exists, null otherwise.
	 */
	private static function find($key, array &$source)
	{
		if (!isset($source[$key])) {
			return null;
		}
		if (get_magic_quotes_gpc()) {
			return stripslashes($source[$key]);
		}
		return $source[$key];
	}

	/**
	 * Get a GET value
	 * @param string $key The key of the GET value
	 * @returns mixed The value if it exists, null otherwise.
	 */
	public static function get($key) 
	{
		return self::find($key, $_GET);
	}
	
	/**
	 * Get a POST value
	 * @param string $key The key of the POST value
	 * @returns mixed The value if it exists, null otherwise.
	 */
	public static function post($key) 
	{
		return self::find($key, $_POST);
	}
}


Then you just do:
$myGetVar = Request::get("getVariable");
$myPostVar = Request::post("postVariable");


Was This Post Helpful? 1
  • +
  • -

#7 hiddenghost  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 37
  • View blog
  • Posts: 599
  • Joined: 15-December 09

Re: php ini include

Posted 07 April 2012 - 01:57 AM

View PostAtli, on 07 April 2012 - 02:19 AM, said:

Quote

I tried a php.ini file in my script file and that just broke my script.
The page just came up blank.

What do you mean? The "php.ini" file doesn't really have anything to do with the actual script files. You just create a "php.ini" file in the web-root of your site and put this line into it:
magic_quotes_gpc = Off


You shouldn't be including this into your PHP scripts or anything like that.


This is what the host people said: "Using the php.ini file would be the route to go rather than the .htaccess file. If it is breaking your script by turning it off than you will need to modify your script to work with it"

I was unsure of what that meant too.
edit: I meant folder/directory. Sorry about the confusion. It was in my script directory.

All I did was add the php.ini file with the line magic_quotes_gpc = Off and the script just came up blank. I removed the php.ini file and the script had output.
Also, I thought php.ini wasn't recursive so it needs to be in all the directories it would be used in.
edit: We now know that I meant directory instead of file so we can now move on without ceremony. :blush:
Which would probably just be two, but that's beside the point.

I haven't found any documentation about scripts not being able to run php.ini because of something in them stopping it.

Unless this is something bigger that has to do with a bug in php or apache, but I doubt it. :pinch:

This post has been edited by hiddenghost: 07 April 2012 - 02:03 AM

Was This Post Helpful? 0
  • +
  • -

#8 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3052
  • View blog
  • Posts: 4,575
  • Joined: 08-June 10

Re: php ini include

Posted 07 April 2012 - 02:13 AM

Try adding this to the same "php.ini" file that broke your scripts:
display_errors = On
error_reporting = E_ALL


Maybe the addition of this directory level "php.ini" file is somehow defaulting some other directives and causing errors. It shouldn't, but who knows what your host is up to...
Was This Post Helpful? 0
  • +
  • -

#9 hiddenghost  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 37
  • View blog
  • Posts: 599
  • Joined: 15-December 09

Re: php ini include

Posted 07 April 2012 - 02:50 AM

Haha. Still a blank page.

Even a blank php.ini file makes my script load blank.

It's not working even though it was their advice.

Here's some possible snafus.
I'm using PHP5.3.10 as an optional version.
There's an odd file in the public_html folder called .htaccess.phpswitch
It has these lines in it:
# Do not Remove! Added by PHP Switcher from cPanel to use an alternate PHP version. Contact Support for details.
AddHandler application/x-httpd-php-5.3.8 .php


Though cpanel says the current version is PHP5.3.10

Here's the error that comes after setting magic_quotes_gpc = Off: Invalid command 'magic_quotes_gpc', perhaps misspelled or defined by a module not included in the server configuration
Was This Post Helpful? 0
  • +
  • -

#10 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3052
  • View blog
  • Posts: 4,575
  • Joined: 08-June 10

Re: php ini include

Posted 07 April 2012 - 03:01 AM

Don't worry about the .htaccess.phpswitch file. Just leave it be. It just a cPanel thing that you aren't meant to mess with.

View Posthiddenghost, on 07 April 2012 - 09:50 AM, said:

Here's the error that comes after setting magic_quotes_gpc = Off: Invalid command 'magic_quotes_gpc', perhaps misspelled or defined by a module not included in the server configuration

That's when you try to do it in a .htaccess file, right? What, exactly, does that look like?

It should look like this:
php_flag magic_quotes_gpc Off


The php_flag would be the command, the the other two input parameters for it.
Was This Post Helpful? 0
  • +
  • -

#11 hiddenghost  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 37
  • View blog
  • Posts: 599
  • Joined: 15-December 09

Re: php ini include

Posted 07 April 2012 - 03:06 AM

What the hell?!

I just changed the version of php to 5.4 in cPanel and voila magic quotes off now works.

I am going to be confused for a while now even though my script at least works.

Blarg!!!

View PostAtli, on 07 April 2012 - 04:01 AM, said:

Don't worry about the .htaccess.phpswitch file. Just leave it be. It just a cPanel thing that you aren't meant to mess with.

View Posthiddenghost, on 07 April 2012 - 09:50 AM, said:

Here's the error that comes after setting magic_quotes_gpc = Off: Invalid command 'magic_quotes_gpc', perhaps misspelled or defined by a module not included in the server configuration

That's when you try to do it in a .htaccess file, right? What, exactly, does that look like?

It should look like this:
php_flag magic_quotes_gpc Off


The php_flag would be the command, the the other two input parameters for it.



Yeah I got the php.ini directives and the .htaccess directives mixed up. Ya, the error is for htaccess, but with it actually looking like:
php_flag magic_quotes_gpc Off



Blah! It doesn't matter any way because now it works with the php.ini
Was This Post Helpful? 0
  • +
  • -

#12 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3052
  • View blog
  • Posts: 4,575
  • Joined: 08-June 10

Re: php ini include

Posted 07 April 2012 - 03:09 AM

View Posthiddenghost, on 07 April 2012 - 10:06 AM, said:

I just changed the version of php to 5.4 in cPanel and voila magic quotes off now works.

I am going to be confused for a while now even though my script at least works.

Like I mentioned above, there is no such thing as Magic Quotes in PHP 5.4 ;)

It's great that you can choose to use PHP 5.4 so early. Not many hosts I know offer support for new PHP versions this quickly.
Was This Post Helpful? 0
  • +
  • -

#13 hiddenghost  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 37
  • View blog
  • Posts: 599
  • Joined: 15-December 09

Re: php ini include

Posted 07 April 2012 - 03:13 AM

lo frickin l
Magic quotes aren't even in PHP5.4.
That's why the script works.
Oh my @!$%^$%^!

View PostAtli, on 07 April 2012 - 04:09 AM, said:

View Posthiddenghost, on 07 April 2012 - 10:06 AM, said:

I just changed the version of php to 5.4 in cPanel and voila magic quotes off now works.

I am going to be confused for a while now even though my script at least works.

Like I mentioned above, there is no such thing as Magic Quotes in PHP 5.4 ;)


Ya, I forgot you mentioned that. I looked up the 5.4 release notes and found it there too.
Well at least the fargin thing is fixed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1