Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




PHP Default Host Best Practices


I've got my dev and production environments all setup, and the mysql
DBs working fine. What need to do is set the mysql.default_host option
in php.ini to be one thing on dev, and something different on
production. Unfortunately, my web host doesn't allow me to mess with
php.ini.

So, what's the best way to specify a different host to mysql_connect()
on dev and production. Yes, I could manually edit the variable
everything I FTP, but I'd rather not.

Should I use a global variable in a separate include file? Other
options?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Database Stores Default Number Everytime, But I Havent Set A Default Number??
Im having some problems with my database. Everytime i store a number which is longer than 10 numbers the script or database puts this number into the database: 2147483647. Its does this everytime no mather how i write the numbers and nomather how long the number is, it just needs to be over 10.

I have set any default value in the database and to be sure i havent i tried deleting the table, but same thing happends again???

PHP Best Practices
I have a basic design question, in terms of what is "better"
programming.

I have a web site, and am using php pages as includes. some of the php
pages have php tags, and "echo" or "print" the php variables and html.

Like this:
<div id="body">
<?php include("phpincludes/server-nav.php"); ?>
</div>

the php page has code like this:
<div id="header">
<ul>
<li class="tab" <?php if ($thisPage=="Home")
echo " id="currentpage""; ?>>
<a href="http://abf966/LBA/index.php">Home</a>
</li>
<li class="tab" <?php if ($thisPage=="Introduction")
echo " id="currentpage""; ?>>
<a href="http://abf966/LBA/intro.php">Introduction</a></li...
etc

Some PHP Best Practices
I'm starting a new project, and I was wondering what is considered best
practise in the following cases:

* Connecting to multiple databases using the PEAR library.
* Triggering your archive script from within the project without cron on
the server
It doesn't looks right to start archiving each time a user visits a
page.
* Providing some sort of login authorization over XML-RPC.
If you work on a user-based permissions site, how do you continue that
to XML-RPC.

General OOP Practices..
I'm newer to the OOP in php world, but my questions revolve around good practices when programming OO in PHP rather than can this be done. So, I have a class with 7 functions in it, and I set in my constructor 7 variables. Is it better to pass the variables as needed through the functions for example:

Bad PHP Coding Practices?
I'm just wondering what are some bad (inefficient / resource intensive) PHP coding practices. For example, in Visual Basic string concatenation in a loop can really slow things down since a new string is created each time. Object creation has overhead and only so many objects can be created before it bogs down. Any significant problems with $a .= $a + "text" or objects in PHP? Any other bottlenecks?

Best Practices - GUI Standards
I hope this is on topic this looks like a pretty generic PHP group. If not
I'm a nooB so be gentle.

Question:
Could anyone recommend a "best practice" for maintaining commonality of what
the user sees on a medium scale PHP application? For example: button size,
color, font, alignment, labels, etc.

My intent is to build an application that has been pre-designed in phases,
piece by piece and outsource most of the coding. There must be a common
look and feel. Is there a better way then me simply listing them out? Ex:
all buttons are 10px by 20px, all font arial 10pt, etc.

Programming Practices
Which are considered to be the best programming practices? for example i prefer to not store sessions into files (as done by default by php), but in a database as this gives me the possibility to use the same session on multiple servers, this is possible because of the session_set_save_handler() function! So which do you use (non-oop)?

To enlarge the topic a bit: which threads are all out there and how do you solve them (e.g.: cross site scripting)?

Best Practices For Sortable Columns
I have several forms that display information from the database after
users log in. I would like the column titles to be sortable so that
when the user clicks on a column heading, the data re-displays in
sorted order of that column. Next time they click on it, it toggles
the order from ascending to descending, and then back to ascending
again.

Since I have many forms and each form has different columns, I was
wondering if there was a method that would be better than a brute force
approach. What are the best practices for this functionality?

Include() & Paths - Best Practices
I have a question regarding paths and the include() statement in PHP.

I develop in a Windows environment and will be publishing to a Linux
server. I would like to do the following:

1. Setup my include references in such a way that I don't have to
change them all every time I have to publish to the production server

2. Setup above in such a way that won't involve php.ini (& LInux
equivalent), as I have access to edit this file locally, but won't be
able to do so in the production environment

My file structure is such:

wwwroot
subdir
global
inc

I tried Windows-styled virtual references such as "/" to refer to the
wwwroot, but that didn't work in the production evironment. I switched
to relative paths (eg include("global/inc/config.inc") or include
("../global/inc/config").

I guess what I'm looking for here is a best practice for how to set
the includes up for maximum portability across servers with different
file systems as well as different platforms. Can you, for instance,
incorporate a variable that defines the root path into the include
statement above? If so, where do you define this variable globally
without having to add to every file? (b/c you can't use an include
statement if you haven't gotten the includes to work) Is there an
equivalent of global.asa for the PHP world?

I'm just raising some issues with my experience thus far. I know
there's a solution and a best practice that I'm just missing to the
point--I would appreciate any wisdom that could be shared.

Best Practices For Bundling PHP Runtime Libs?
My company makes a tool which generates (among other things) PHP
client-side bindings to WebServices. We have also implemented a
collection of PHP-code required by these bindings ("runtime
libraries"). Our tool creates a file containing the PHP-bindings, but
the runtime libraries should also be placed somewhere where it will be
picked up by the PHP-engine.

Is there a common/standard way or to do this in the PHP-community? I do
not like the idea of installing the runtime libraries in system-folders
or something like that. Would someone offer their recommendations?

GD Default DPI
I'm currently making a website that needs to edit images with adding text,
the problem is, the picture starts at 300 DPI (pixels/inch), but after GD
edits the image, it's set to 72 which i read to be the default value GD
always uses. is there a way to edit that default to a higher number, if not
are there other ways to edit images through php and still keeping the
original DPI.

Magic_quotes_gpc On By Default In PHP 4.3.3?
Prior to upgrading to PHP 4.3.3 (Windows), magic_quotes_gpc was turned off in the php.ini file. However, when I upgraded, I told the installer overwrite my previous php.ini files. I didn't have anything special in my previous version of php.ini and I wanted a clean slate.

After I upgraded to 4.3.3, I noticed that my scripts were acting strange, specifically form input. I checked php.ini and found that magic_quotes_gpc was turned on.

I unzipped the installer exe and upon inspecting the php.ini, I found the default php.ini included had magic_quotes_gpc On.

I thought they were going to set magic_quotes_gpc off by default in the later versions.

Anyone know why they did this? Was it a mistake?

What Is Better As A Default Value: NULL Or ''?
I would like to collect some statistical data and then make some reports on it. I'm creating tables for this task and i'm not sure what is better for filling default values: NULL or ''. What is optimal for storage purposes and for further reports creation?

Default Image
How can I write a function in such a way that it would look for a specific image to load. If that image exists on the server it will load it, if not it will load a default image.

Dropdown - Default Value
I want to be able to have a drop down list that doesn't necessarily have the first item as the default. The content is being populated by PHP so I have no idea how to do it.

Default Variable Value
Does php provide a built in way to use a variable's current value if
that variable is already set but to use a default value otherwise.
That is, a more compact syntax for:

$some_var = isset("$some_var") ? $some_var : "default value";

Set Column Default
we have a table  sistock with column cameramodel  varchar(30) and try to  set default value to blank with the following:

ALTER TABLE SISTOCK CHANGE COLUMN CAMERAMODEL CAMERAMODEL ENUM ('INSTOCK',
'BACKORDER','SERVICE','OBSOLETE') DEFAULT '';

and we get an error at the mysql prompt;

ImageString: How Do I Use A Font That Is Not One Of The Default 5?
I am playing with imagegd for generating images, and was wondering if there is a way I could use a font that is not one of the default 5? I remember reading somewhere about a TT font library for imagegd, but don't remember the specifics. If someone could point me in the right direction I would appreciate it.

Problem On Default Value : : MySQL
Problem on default value : : MySQL

I am facing problem in this line

`datetime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,

when I tried to crate a new table in MySQL(version 3.23.47-nt)

Default Option On Select Box
I need to make a field in a admin form to be a drop down select box. I have the field right now as: PHP Code:

Using Default DB, User, Password
How do I use odbc.default_db, odbc.default_user and odbc.default_password defined in php.ini in the mssql_connect() function? I do not want to define these vars globally at the application level for many reasons. Shouldn’t calling the function without any parameters force PHP to look at the INI file for the defaults?

Form With To Submits, Which One To Default To?
Say, I have a form. Both cancel and save (in that order) are submits, then in the code I check which button was pressed. The point is that I want the save button (2nd) to be default, not the cancel. Is there a way (in js?) to "focus" the other button? One other way to be some simple js, which submits the page anyway......

Object Default Value In Constructor
I'm trying to write a class with a constructor that takes a single object
parameter. So far so good, but I can't for the life of me make the parameter
optional. I understand how to do it with a numerical or textual parameter,
but not with an object. I tried null, but it doesn't work.

class A
{
}

class B
{
function B($a = ???)
{
if (!isset($a)) $a = new A;
}
}

Default Selection From Query
I'm having difficulty trying to have a DEFAULT selected record from a query in my dropdown box (code below). I have about 20 records in a 'facility' table, which listed names of our company's locations. I want to default select one of those records "exton" to be selected in my dropdown box. Code:

Default Argument Values
something like this possible in PHP:

function foo($a=1, $b=2, $c=3) {
//...
}

foo($b=2);

Will this assign $a and $c to default values?

How To Overwrite Default Php Installation
On my linux system php seems to have been installed by default. When I
type:

"which php" it tells me /usr/bin/php

I installed php and it has put an executable in the /usr/local/bin/php

"which php" still says /usr/bin/php

"whereis php"
php: /etc/php.ini /usr/bin/php /usr/local/bin/php /usr/local/lib/php
/usr/local/lib/php.ini

/usr/local/lib/php -v shows the new version but php -v shows the old
version.

How can I correct this problem?

I want to run the command php -v and it shows the newest version.

I have already tried removing /etc/php.ini /usr/bin/php

Default Value To Insert Into MySQL
What should I insert as the default value if a form field is blank? My fields don't currently accept null.

if($_POST['height']) {
  // error checking
  $height = $_POST['height'];
}
else {
  $height = '';
}
Should $height be equal to '', NULL, or maybe 'NULL'? I'm thinking 'NULL' incase I or someone else decides to change the field to accept null?

PHP Session Default Timeout
what is the default Session Timeout for php...is there a way to increase this on the web server I am hostign my php scripts on..

Default Error Message
How to prevent the default error message from being  displayed ?

Default Date Drop Down
Ive got the following drop down which works perfectly, although the default date is set to todays date. Could you please advise me on how to set it to show -- -- ---- instead of 31 05 2007? Code:

Php's Default Character Set
Where does it say that on php.net, that iso8859 is the default charset for strings? Can't find anything about it.

Display A Default Image?
Is there an "if" statement I can use to check if an image exists in a certain directory, and if it does display it, but if it doesn't exist then display another image in a different directory? I've written simple "if" statements for text display, but nothing like this. Is this possible?

It might help to tell the scenario. I am putting together templates for teacher web sites. If they wish, they can upload their own logo into their upload directory to display at the top of the page, but if they choose not to upload their own logo I want the default (district) logo to appear there. The default logo is located in another directory on the same server.

Default Error Page If No Rows
If there are no rows in the result of my query, instead of just showing some text in the browser saying no rows found, could i redirect to a standard error page using this function?

Need Access To Default File Attributes
When I was first learning php, I created an upload script. The basics of the script had:

<form method="POST" ENCTYPE="multipart/form-data">
<input type="file" name="FILE">
<input type="submit" name="SUBMIT" value="Upload">
</form>

Then in the submit section, it accesses the filename and filesize by virtue of a default php ability to extract these attributes by using: $FILE_name and $FILE_size (where _name gives the name of $FILE and _size gives the size of $FILE).

if($SUBMIT)
echo " Filename: $FILE_name <br> Filesize: $FILE_size";

Also, I did add the necessary lines to handle the post variables, like so:

$FILE = $_POST['FILE'];
$SUBMIT = $_POST['SUBMIT'];

I have tried to mimic this script in a new upload script, but am unable to access those same attributes (_name and _size).

At the time of my original upload script, we were running it on a Linux server (but I don't remember what we were running for a php version). Currently, I am running PHP 4.2.3 on Mac OS 10.2.8 server.

One thought I had was that maybe PHP 4.2.3 no longer supports _name and _size. Or, maybe I am not handling the retrieval of the POST var for the file correctly? I wonder this because I did try print_r($_POST) and I only got the submit returned as a post var.

Dropdown List - Trying To Get Default Populated From Db.
Nooby question but when I try and get this to work (it should identify which
rows in the database have GK, MID, DEF, FWD against them and then put
SELECTED into the option value to give a default of what the entry is
currently) it just adds SELECTED to all the results as if $row["Position"]
is returning true against all four conditions? What am I doing wrong? CODE:..

Entering The Date As Default Within A Form
Anyone know how to enter the time into a form or a website that might
tell how? I'm using the following html code and trying to get the
time to default into the text box. thanks

html code
<tr>
<td><b>Date:</b></td>
<td align="left"><input type="text" name="date" size="8"
maxlength="8"></td>
</tr>

php code
<? print strftime("%m/%d/%Y"); ?>

Default Function Argument Issue
function test($foo=array()) {
echo gettype($foo);
implode(' ',$foo);
}

foo();

This code will output:
null

and generate the error
Bad arguments. in .... on line x ( bad implode args )

what's the deal?
$foo should be an array!

Send Default Apache 404 Error From Php
How can I trigger the default Apache 404 error from PHP? I don't want
to specify a custom handler, I want the default handler. The reason is
that I am using mod_rewrite with Apache for my site. If certain a
certain page is requested that is not published, then I want to send
the apache default 404 error page. Currently, I am doing this to
return a custom error.

if($pageNotPublished) {
header("HTTP/1.1 404 Not Found");
// How do I send the default apache 404 message
// instead of the message below?
print("<html><body>HTTP 404 - Not Found</body></html>");
exit();
}

The default 404 error page has more details,

Default Home Page Under Xampp.
Is there a way to change default home page under Xampp, so that when I
type http://localhost it would go to a home page other than page with
popup asking for Xampp authorization.

How To Change PCRE Default Delimiters
I try to use alternative delimiters for a regular expression.
When will it be supported?

www@mike:/home/www > /usr/local/bin/php -a
Interactive mode enabled

<?php
preg_match('m!A(d*)B!', 'A12345B', $X));
?>
X-Powered-By: PHP/4.2.3
Content-type: text/html

<br />
<b>Parse error</b>: parse error in <b>-</b> on line <b>2</b><br />

http://perldoc.com/perl5.8.4/pod/perlrequick.html

How Can I Delete The Default Apache And Php On Linux?
I installed php4.0.2 and apache 1.3.12,but I use the function phpinfo() checked the version of the php,it always tells me it is 3.0.15,so I want to delete the default apache and php on linux,so I can install new php4 and apache and it can connect to the mysql.By the way how can I get rid of the php and apche which the in linux when I installed the linux.

Setting Imagecreatetruecolor() To Have Transparency As Default
Does anyone know if its possible to set imagecreatetruecolor() to initialise
with transparency
rather than black?

Default Select Drop Down Menu?
I have a drop down menu populated via a script that pulls all categories from the category table. However, when a user clicks to view a specify category (i.e. Toys), I want the drop down menu to display toys as the default value. Code:

MYSQL: How To Set A User's Default Database?
Is it possible to set a user's default database for MySQL database?

Instead of having an additional line of command, i.e:

mysql> use database <database_name>

Perhaps there are parameters I can set up a default database for a user when
she log on to mysql.

Default Redirect To Webpage For Authentication?
I'm hunting for a script that would allow me to place a wide-open
wireless access point in my client's business. Then, anyone connecting
and then surfing a webpage would be redirected to a default webpage for
their username/password. Once they log-in, they can surf as normal
until they close their browser. Each new browser session would require
a new cookie/login to surf the web.

Has anyone seen a script that can do this? Or, should I be looking at
some sort of proxy server product?

Setting An Image Field As A Default?
In my application I have 6 image fields. If a user uploads an image they must upload an image 1 which is the main image. So I dont want them to be able to jump to the 2nd or 3rd fields and upload their file there. I am just not sure how to go about defaulting them to upload image 1 first?

Default Selection Radio Button
I have a table where users input a date, time, and quantity for a reservation.  On my page ... because I have a junk calendar and coding, every time you click a different month on the calendar or click the "book now" button without entering all the necessary data, the page refreshes and erases all the data. 

One significant problem is that the times display as radio buttons. Some tours have one time and some have multiple times. On the page, if there is only one time, then to make it easier for users to book tours, I inputted CHECKED into the html code. But unfortunately if the tour has multiple times, then CHECKED doesn't work for the first radio button, it defaults the last radio button because of the php loop. Code:

Conditional Statement For Default Case
I'm trying to create a conditional statement for my menu that will check to see if the page is on the default case. Code:

Automatic Select Form Field Default
I would like to allow registered users to my site the ability to change your personal information. Let's say the country in which they are in.

The country field is a drop down list. So its supposed to read from the table and make the value the default. How am I going to do this?


Copyright © 2005-08 www.BigResource.com, All rights reserved