[PHP] mysql and php questions

2012-09-03 Thread Littlefield, Tyler

Hello all:
I had a few questions.
First, I'm using php-fastcgi with nginx for my primary web server. I was 
wondering what sorts of optimizations exist to make this process a lot 
faster.
Second, I'm setting up a custom application, and it contains an 
authentication module for login/registration. In doing this, I 
discovered PDO (I used to just use the mysql_* functions). According to 
google, it's easier to prevent mysql injection attacks with PDO, so I 
dove in.
Before, I was using $pdo-exec(...);, but I read that I need to call 
quote on the variables I'm passing in. It looks like that all quote does 
is just add '...' on the variables, but I could be wrong.

So, here's my questions:
First, I know that prepared statements are immune to mysql injection 
attacks, if I just use the variables with placeholders in the 
statements. I know that caching these means that the optimization does 
not have to be done every time, but is this the most efficient method 
for adding a single user for registration? Or would a basic query be better.
Also, I had the idea of building up common queries and cacheing them, 
but this isn't really possible since each php script (as far as I'm 
aware) gets it's own process or environment. If I can build the prepared 
statements and cache them, it seems like things would be a lot quicker. 
Is this something commonly done?


--
Take care,
Ty
http://tds-solutions.net
The aspen project: a barebones light-weight mud engine:
http://code.google.com/p/aspenmud
He that will not reason is a bigot; he that cannot reason is a fool; he that 
dares not reason is a slave.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-19 Thread tamouse mailing lists
On Sat, Mar 10, 2012 at 7:43 PM, Tedd Sperling tedd.sperl...@gmail.com wrote:
 On Mar 10, 2012, at 3:53 PM, tamouse mailing lists wrote:
 On Sat, Mar 10, 2012 at 9:37 AM, Tedd Sperling tedd.sperl...@gmail.com 
 wrote:
 That's correct, but to access those variables outside of their scope (such 
 as a function) you do via a SuperGlobal, namely $GLOBAL['whatever'].

 As such, there are no globals in PHP other than SuperGlobals. As I said, 
 if I'm wrong, please show me otherwise.

 I guess I don't know what you mean by globals. I know what globals
 are, but not globals.

 I don't understand your question. I know what questions are, but not your 
 question. :-)

Well, I've been pondering this for a while, and now I'm sure.

 - kill file

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-13 Thread Tedd Sperling
On Mar 12, 2012, at 7:12 PM, Tim Streater wrote:
 ?php
 
 function yes ($a)
 {
 global $x;
 if  ($a)  $x = yes\n;
 }
 
 first (true);
 
 echo $x;
 
 ?
 
 
 but I haven't looked into $GLOBALS enough to know whether using them instead 
 would have saved my bacon.

I'm not sure what would have saved bacon in the above case. I don't see how 
your example would work. I think it contained a typo.

In what I think you were trying to demonstrate, I would just pass $x by 
reference ($x) -- or -- return $x by value. I would not have used a global,

In any event, I seldom use globals anyway. This was more an academic discussion.

Cheers,

tedd

_
tedd.sperl...@gmail.com
http://sperling.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-13 Thread Tedd Sperling
On Mar 12, 2012, at 12:04 PM, Daniel Brown wrote:
 On Sun, Mar 11, 2012 at 14:16, Tedd Sperling tedd.sperl...@gmail.com wrote:
 This document clearly states that $GLOBALS is a SuperGlobal -- what am I not 
 understanding here?
 
You are understanding it correctly, the only thing that's missing
 is the population.  The variables are defined (set), but not all are
 populated.  $GLOBALS is a superglobal, you're right; globals set from
 userland scripts are not superglobals, but do wind up in the $GLOBALS
 array.  Thus, all superglobals are globals, but not all globals are
 superglobals.

So, it's a question of population timing -- I see.

Additionally, I like the term userland -- I will use it in class. :-)

What would be the opposite term, serverland?

Thanks,

tedd

_
tedd.sperl...@gmail.com
http://sperling.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-13 Thread Matijn Woudt
On Tue, Mar 13, 2012 at 4:59 PM, Tedd Sperling tedd.sperl...@gmail.com wrote:
 On Mar 12, 2012, at 7:12 PM, Tim Streater wrote:
 ?php

 function yes ($a)
     {
     global $x;
     if  ($a)  $x = yes\n;
     }

 first (true);

 echo $x;

 ?


 but I haven't looked into $GLOBALS enough to know whether using them instead 
 would have saved my bacon.

 I'm not sure what would have saved bacon in the above case. I don't see how 
 your example would work. I think it contained a typo.

 In what I think you were trying to demonstrate, I would just pass $x by 
 reference ($x) -- or -- return $x by value. I would not have used a global,

 In any event, I seldom use globals anyway. This was more an academic 
 discussion.

 Cheers,

 tedd


I would indeed mark it as bad practice using them. I only use them for
debugging purposes. When developing something, you might end up
needing some global variable temporary, and you don't want to pass it
through a few dozen functions before reaching the one where you need
it.

- Matijn

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-13 Thread Stuart Dallas
On 13 Mar 2012, at 15:59, Tedd Sperling wrote:

 In any event, I seldom use globals anyway. This was more an academic 
 discussion.

If you're being academic about it please remember that the way PHP defines 
globals is different to most other languages.

PHP: A variable defined at the top-level scope.

World: A variable that is visible at every scope.

This is an important difference if you ever move from PHP to another language. 
It ultimately also means that only the superglobals are true globals.

The $GLOBALS superglobal contains all variables defined at the top-level scope, 
including $GLOBALS, so $GLOBALS['GLOBALS']['GLOBALS']['GLOBALS']['_SERVER'] is 
a perfectly valid, if daft, way of accessing $_SERVER.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-13 Thread Tedd Sperling
On Mar 13, 2012, at 12:20 PM, Stuart Dallas wrote:
 On 13 Mar 2012, at 15:59, Tedd Sperling wrote:
 
 In any event, I seldom use globals anyway. This was more an academic 
 discussion.
 -snip-
 It ultimately also means that only the superglobals are true globals.

That was my initial statement in this thread.

After 47 years of programming, I think I'm beginning to get the idea. :-)

As I've said for many years I've learned something new every day of my life -- 
and I'm getting damned tried of it.

Cheers,

tedd

_
tedd.sperl...@gmail.com
http://sperling.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-13 Thread Tim Streater
On 13 Mar 2012 at 15:59, Tedd Sperling tedd.sperl...@gmail.com wrote: 

 I'm not sure what would have saved bacon in the above case. I don't see how
 your example would work. I think it contained a typo.

 In what I think you were trying to demonstrate, I would just pass $x by
 reference ($x) -- or -- return $x by value. I would not have used a global,

 In any event, I seldom use globals anyway. This was more an academic
 discussion.

As was my example - and yes, it had a typo. Worse, trying it in a shell it 
doesn't exhibit the failure mode I thought I'd had. Never mind.

--
Cheers  --  Tim

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] questions about $_SERVER

2012-03-13 Thread Donovan Brooke

Stuart Dallas wrote:

[snip] so $GLOBALS['GLOBALS']['GLOBALS']['GLOBALS']['_SERVER'] is a perfectly 
valid, if daft, way of accessing $_SERVER.

-Stuart




Now this is becoming educational! ;-)

Donovan


--
D Brooke

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-12 Thread Daniel Brown
On Sun, Mar 11, 2012 at 14:16, Tedd Sperling tedd.sperl...@gmail.com wrote:

 As to placing an additional requirement (i.e., being predefined) on the 
 definition as to what constitutes a SuperGlobal is outside my understanding. 
 As such, I must defer to the PHP Manual, namely:

 http://php.net/manual/en/language.variables.superglobals.php

 This document clearly states that $GLOBALS is a SuperGlobal -- what am I not 
 understanding here?

You are understanding it correctly, the only thing that's missing
is the population.  The variables are defined (set), but not all are
populated.  $GLOBALS is a superglobal, you're right; globals set from
userland scripts are not superglobals, but do wind up in the $GLOBALS
array.  Thus, all superglobals are globals, but not all globals are
superglobals.

-- 
/Daniel P. Brown
Network Infrastructure Manager
http://www.php.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-12 Thread Tedd Sperling
On Mar 11, 2012, at 3:04 PM, Tim Streater wrote:
 
 In the following, $x is a global but not a super-global (AFAIK).
 
 
 ?php
 
 function echox ()
 {
 
 global $x;
 
 echo $x;
 
 }
 
 $x = Hello world\n;
 
 echox ();
 
 ?
 
 --
 Cheers  --  Tim


Tim:

I read somewhere that using:

global $x;

is not recommended. Whereas, it is recommended to use:

$x = $GLOBALS['x'];
echo $x;

In any event, what I found interesting is:

print_r($GLOBALS)

if will list all the variables (plus more) in your script. Thus, all variables 
in your main script are also included in the $GLOBALS array.

Cheers,

tedd

_
tedd.sperl...@gmail.com
http://sperling.com





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-12 Thread Jim Giner
The purpose of the global statement within a function is to let PHP know 
that the usage of a var name INSIDE that function is not meant to create a 
NEW variable, but instead, to reference the other (global) variable being 
used (and perhaps already defined) in your main script.

Basically it works like this:

You can:
- create vars in the main script usable in that script's main body outside 
of any functions

- create vars to be used entirely and only within any functions in your 
script;

-reference vars from the main script within a specific function by 
referencing them with a global $xxx,$yyy,$zzz statement at the top of your 
function;

And Finally You Can:

- create $_SESSION['xxx'] var that can be seen anywhere in your 
application(s) during the life of the current session.  Close the browser or 
fail to do a session_start() in a script and you can't see them, but who 
would do that?

I'm sure someone will have something else to add, but I think this is all 
the knowledge one needs to accomplish most php programming. 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-12 Thread Tim Streater
On 12 Mar 2012 at 20:07, Tedd Sperling tedd.sperl...@gmail.com wrote: 

 Tim:

 I read somewhere that using:

 global $x;

 is not recommended. Whereas, it is recommended to use:

 $x = $GLOBALS['x'];
 echo $x;

Tedd,

That may well be, although as I write I can't recollect having seen that 
anywhere; so I don't use that form. However I have been caught by something 
like the following:

?php

function yes ($a)
 {
 global $x;
 if  ($a)  $x = yes\n;
 }

first (true);

echo $x;

?


but I haven't looked into $GLOBALS enough to know whether using them instead 
would have saved my bacon.

--
Cheers  --  Tim

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] questions about $_SERVER

2012-03-11 Thread Stuart Dallas
On 11 Mar 2012, at 01:43, Tedd Sperling wrote:

 On Mar 10, 2012, at 3:53 PM, tamouse mailing lists wrote:
 On Sat, Mar 10, 2012 at 9:37 AM, Tedd Sperling tedd.sperl...@gmail.com 
 wrote:
 That's correct, but to access those variables outside of their scope (such 
 as a function) you do via a SuperGlobal, namely $GLOBAL['whatever'].
 
 As such, there are no globals in PHP other than SuperGlobals. As I said, 
 if I'm wrong, please show me otherwise.
 
 I guess I don't know what you mean by globals. I know what globals
 are, but not globals.
 
 I don't understand your question. I know what questions are, but not your 
 question. :-)

I think the confusion is arising because the word superglobal is used in PHP 
when referring to globals, because the word global has been incorrectly applied 
for quite some time.

A global variable is a variable that is accessible in every scope, so Tedd is 
right… the only true globals in PHP are the superglobals. Here's an overview of 
the various scopes in PHP (I've probably missed some, but it's enough to make 
the point)…

?php
  // Only visible when not in a function or class. The PHP manual calls
  // this the global scope: http://php.net/variables.scope
  $var1 = 'a';

  function funcB()
  {
// Only visible inside this function.
$var2 = 'b';
  }

  function funcB()
  {
// This statement makes the variable from the top-level scope visible
// within this function. Essentially this is the same as passing the
// variable in to the function by reference.
global $var1;
  }

  class classC
  {
// Visible to methods in this class only.
private $var3 = 'c';

// Visible to methods in this class and methods in derived classes.
protected $var4 = 'd';

// Method visible in this class only.
private methodA()
{
  // Visible only inside this method.
  $var5 = 'e';
}

// Method visible in this class and methods in derived classes.
protected methodB()
{
  // See funcB()
  global $var1;
}

// Method visible on any instance of this class.
public methodC()
{
  // See funcB()
  global $var1;
}
  }
?

The global keyword allows you to expose a variable that has been defined at the 
top-level scope ($var1 in the above example) in the current scope. It does NOT 
create a global variable; the keyword is not an accurate reflection of what it 
does.

My guess is that calling the top-level scope global made sense when functions 
were the only other level of scope that existed. Now that we have yet more 
levels of scope it can be a bit confusing.

I hope this helps clear things up.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-11 Thread Daniel Brown
On Sat, Mar 10, 2012 at 10:37, Tedd Sperling tedd.sperl...@gmail.com wrote:
 As such, there are no globals in PHP other than SuperGlobals. As I said, if 
 I'm wrong, please show me otherwise.

A superglobal is predefined at run-time by the parser,
environment, SAPI, etc. (_SERVER, _POST, _GET, _REQUEST, _ENV,
_SESSION, _COOKIE), whereas a global can be defined at any time, and
is available to the current instance.  All superglobals are globals,
but not all globals are superglobals.

-- 
/Daniel P. Brown
Network Infrastructure Manager
http://www.php.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-11 Thread Tedd Sperling
On Mar 11, 2012, at 10:25 AM, Daniel Brown wrote:

 On Sat, Mar 10, 2012 at 10:37, Tedd Sperling tedd.sperl...@gmail.com wrote:
 As such, there are no globals in PHP other than SuperGlobals. As I said, 
 if I'm wrong, please show me otherwise.
 
A superglobal is predefined at run-time by the parser,
 environment, SAPI, etc. (_SERVER, _POST, _GET, _REQUEST, _ENV,
 _SESSION, _COOKIE), whereas a global can be defined at any time, and
 is available to the current instance.  All superglobals are globals,
 but not all globals are superglobals.
 
 -- 
 /Daniel P. Brown
 Network Infrastructure Manager
 http://www.php.net/


Now I'm confused.

My understanding is that all variables defined within the main script are 
accessible within the main script because they are all within scope by 
definition.

Additionally, main script variables are not accessible out of scope (such as in 
a function) unless one uses $GLOBALS to retrieve those values.

That is the limit of my understanding of $GLOBALS.

As to placing an additional requirement (i.e., being predefined) on the 
definition as to what constitutes a SuperGlobal is outside my understanding. As 
such, I must defer to the PHP Manual, namely:

http://php.net/manual/en/language.variables.superglobals.php

This document clearly states that $GLOBALS is a SuperGlobal -- what am I not 
understanding here?

Cheers,

tedd

_
tedd.sperl...@gmail.com
http://sperling.com





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-11 Thread Tim Streater
On 11 Mar 2012 at 18:16, Tedd Sperling tedd.sperl...@gmail.com wrote: 

 On Mar 11, 2012, at 10:25 AM, Daniel Brown wrote:

 On Sat, Mar 10, 2012 at 10:37, Tedd Sperling tedd.sperl...@gmail.com wrote:
 As such, there are no globals in PHP other than SuperGlobals. As I said,
 if I'm wrong, please show me otherwise.

A superglobal is predefined at run-time by the parser,
 environment, SAPI, etc. (_SERVER, _POST, _GET, _REQUEST, _ENV,
 _SESSION, _COOKIE), whereas a global can be defined at any time, and
 is available to the current instance.  All superglobals are globals,
 but not all globals are superglobals.


 Now I'm confused.

 My understanding is that all variables defined within the main script are
 accessible within the main script because they are all within scope by
 definition.

 Additionally, main script variables are not accessible out of scope (such as
 in a function) unless one uses $GLOBALS to retrieve those values.

In the following, $x is a global but not a super-global (AFAIK).


?php

function echox ()
 {

 global $x;

 echo $x;

 }

$x = Hello world\n;

echox ();

?

--
Cheers  --  Tim

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] questions about $_SERVER

2012-03-10 Thread Tedd Sperling
On Mar 9, 2012, at 10:20 PM, Jim Giner wrote:
 tamouse mailing lists tamouse.li...@gmail.com wrote in message 
 news:CAHUC_t8g43GE3xqvSU5SwFePGS1XG=tk1mhrbem9gjaarve...@mail.gmail.com...
 On Mon, Feb 13, 2012 at 2:39 PM, Tedd Sperling tedd.sperl...@gmail.com 
 wrote:
 On Feb 13, 2012, at 4:10 AM, Stuart Dallas wrote:
 On 13 Feb 2012, at 06:28, Rui Hu wrote:
 How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I 
 know
 if I want to modify $_SERVER myself?
 
 Once your script starts the superglobals are no different to any other 
 variables, except that they're in scope at all times.
 
 That's probably the reason why they are named SuperGlobals. :-)
 
 But to be more descriptive, these are simply globals that are predefined 
 by php -- see:
 
 http://php.net/manual/en/language.variables.superglobals.php
 
 I believe, (please show me otherwise) there are no globals in PHP other 
 than SuperGlobals.
 
 Assuming you mean pre-defined ones, there shouldn't be, since no other
 ones are documented. If there are, then either they should be
 documented, or they should be ignored as it can be dangerous to use
 undocumented features. :)
 
 Just to be clear - you asked if it were true that there are no globals in 
 PHP other than SuperGlobals:  Don't forget that anything that you declare as 
 global in a script is a global for that instance of that script (and 
 whatever includes, etc. that it calls during its run) 

That's correct, but to access those variables outside of their scope (such as a 
function) you do via a SuperGlobal, namely $GLOBAL['whatever'].

As such, there are no globals in PHP other than SuperGlobals. As I said, if 
I'm wrong, please show me otherwise.

Cheers,

tedd

_
tedd.sperl...@gmail.com
http://sperling.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-10 Thread Jim Giner

Tedd Sperling tedd.sperl...@gmail.com wrote in message 
news:315faa8f-3103-4661-b167-d30248952...@gmail.com...
On Mar 9, 2012, at 10:20 PM, Jim Giner wrote:
 tamouse mailing lists tamouse.li...@gmail.com wrote in message
 news:CAHUC_t8g43GE3xqvSU5SwFePGS1XG=tk1mhrbem9gjaarve...@mail.gmail.com...
 On Mon, Feb 13, 2012 at 2:39 PM, Tedd Sperling tedd.sperl...@gmail.com
 wrote:
 On Feb 13, 2012, at 4:10 AM, Stuart Dallas wrote:
 On 13 Feb 2012, at 06:28, Rui Hu wrote:
 How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I
 know
 if I want to modify $_SERVER myself?

 Once your script starts the superglobals are no different to any other
 variables, except that they're in scope at all times.

 That's probably the reason why they are named SuperGlobals. :-)

 But to be more descriptive, these are simply globals that are predefined
 by php -- see:

 http://php.net/manual/en/language.variables.superglobals.php

 I believe, (please show me otherwise) there are no globals in PHP 
 other
 than SuperGlobals.

 Assuming you mean pre-defined ones, there shouldn't be, since no other
 ones are documented. If there are, then either they should be
 documented, or they should be ignored as it can be dangerous to use
 undocumented features. :)

 Just to be clear - you asked if it were true that there are no globals 
 in
 PHP other than SuperGlobals:  Don't forget that anything that you declare 
 as
 global in a script is a global for that instance of that script (and
 whatever includes, etc. that it calls during its run)

That's correct, but to access those variables outside of their scope (such 
as a function) you do via a SuperGlobal, namely $GLOBAL['whatever'].

As such, there are no globals in PHP other than SuperGlobals. As I said, 
if I'm wrong, please show me otherwise.

Cheers,

tedd
**
Actually - I've never used $GLOBAL - I've just referenced them by their 
name as specified in the global statement - so it's not always obvious 
that a specific var IS a global.I can see thought that you are aware of 
them so my point is unnecessary. 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-10 Thread tamouse mailing lists
On Sat, Mar 10, 2012 at 9:37 AM, Tedd Sperling tedd.sperl...@gmail.com wrote:
 On Mar 9, 2012, at 10:20 PM, Jim Giner wrote:
 tamouse mailing lists tamouse.li...@gmail.com wrote in message
 news:CAHUC_t8g43GE3xqvSU5SwFePGS1XG=tk1mhrbem9gjaarve...@mail.gmail.com...
 On Mon, Feb 13, 2012 at 2:39 PM, Tedd Sperling tedd.sperl...@gmail.com
 wrote:
 On Feb 13, 2012, at 4:10 AM, Stuart Dallas wrote:
 On 13 Feb 2012, at 06:28, Rui Hu wrote:
 How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I
 know
 if I want to modify $_SERVER myself?

 Once your script starts the superglobals are no different to any other
 variables, except that they're in scope at all times.

 That's probably the reason why they are named SuperGlobals. :-)

 But to be more descriptive, these are simply globals that are predefined
 by php -- see:

 http://php.net/manual/en/language.variables.superglobals.php

 I believe, (please show me otherwise) there are no globals in PHP other
 than SuperGlobals.

 Assuming you mean pre-defined ones, there shouldn't be, since no other
 ones are documented. If there are, then either they should be
 documented, or they should be ignored as it can be dangerous to use
 undocumented features. :)

 Just to be clear - you asked if it were true that there are no globals in
 PHP other than SuperGlobals:  Don't forget that anything that you declare as
 global in a script is a global for that instance of that script (and
 whatever includes, etc. that it calls during its run)

 That's correct, but to access those variables outside of their scope (such as 
 a function) you do via a SuperGlobal, namely $GLOBAL['whatever'].

 As such, there are no globals in PHP other than SuperGlobals. As I said, if 
 I'm wrong, please show me otherwise.

I guess I don't know what you mean by globals. I know what globals
are, but not globals.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-10 Thread Tedd Sperling
On Mar 10, 2012, at 3:53 PM, tamouse mailing lists wrote:
 On Sat, Mar 10, 2012 at 9:37 AM, Tedd Sperling tedd.sperl...@gmail.com 
 wrote:
 That's correct, but to access those variables outside of their scope (such 
 as a function) you do via a SuperGlobal, namely $GLOBAL['whatever'].
 
 As such, there are no globals in PHP other than SuperGlobals. As I said, 
 if I'm wrong, please show me otherwise.
 
 I guess I don't know what you mean by globals. I know what globals
 are, but not globals.

I don't understand your question. I know what questions are, but not your 
question. :-)

Cheers,

tedd


_
tedd.sperl...@gmail.com
http://sperling.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-09 Thread tamouse mailing lists
On Mon, Feb 13, 2012 at 2:39 PM, Tedd Sperling tedd.sperl...@gmail.com wrote:
 On Feb 13, 2012, at 4:10 AM, Stuart Dallas wrote:
 On 13 Feb 2012, at 06:28, Rui Hu wrote:
 How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I know
 if I want to modify $_SERVER myself?

 Once your script starts the superglobals are no different to any other 
 variables, except that they're in scope at all times.

 That's probably the reason why they are named SuperGlobals. :-)

 But to be more descriptive, these are simply globals that are predefined by 
 php -- see:

 http://php.net/manual/en/language.variables.superglobals.php

 I believe, (please show me otherwise) there are no globals in PHP other 
 than SuperGlobals.

Assuming you mean pre-defined ones, there shouldn't be, since no other
ones are documented. If there are, then either they should be
documented, or they should be ignored as it can be dangerous to use
undocumented features. :)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-03-09 Thread Jim Giner

tamouse mailing lists tamouse.li...@gmail.com wrote in message 
news:CAHUC_t8g43GE3xqvSU5SwFePGS1XG=tk1mhrbem9gjaarve...@mail.gmail.com...
 On Mon, Feb 13, 2012 at 2:39 PM, Tedd Sperling tedd.sperl...@gmail.com 
 wrote:
 On Feb 13, 2012, at 4:10 AM, Stuart Dallas wrote:
 On 13 Feb 2012, at 06:28, Rui Hu wrote:
 How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I 
 know
 if I want to modify $_SERVER myself?

 Once your script starts the superglobals are no different to any other 
 variables, except that they're in scope at all times.

 That's probably the reason why they are named SuperGlobals. :-)

 But to be more descriptive, these are simply globals that are predefined 
 by php -- see:

 http://php.net/manual/en/language.variables.superglobals.php

 I believe, (please show me otherwise) there are no globals in PHP other 
 than SuperGlobals.

 Assuming you mean pre-defined ones, there shouldn't be, since no other
 ones are documented. If there are, then either they should be
 documented, or they should be ignored as it can be dangerous to use
 undocumented features. :)

Just to be clear - you asked if it were true that there are no globals in 
PHP other than SuperGlobals:  Don't forget that anything that you declare as 
global in a script is a global for that instance of that script (and 
whatever includes, etc. that it calls during its run) 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-02-13 Thread Stuart Dallas
On 13 Feb 2012, at 06:28, Rui Hu wrote:

 How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I know
 if I want to modify $_SERVER myself?


Once your script starts the superglobals are no different to any other 
variables, except that they're in scope at all times.

The only thing you need to bear in mind if you're going to modify them is that 
other code that's using them will also see your changes, so beware of knock-on 
effects.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

Re: [PHP] questions about $_SERVER

2012-02-13 Thread Tedd Sperling
On Feb 13, 2012, at 4:10 AM, Stuart Dallas wrote:

 On 13 Feb 2012, at 06:28, Rui Hu wrote:
 
 How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I know
 if I want to modify $_SERVER myself?
 
 Once your script starts the superglobals are no different to any other 
 variables, except that they're in scope at all times.

That's probably the reason why they are named SuperGlobals. :-)

But to be more descriptive, these are simply globals that are predefined by php 
-- see:

http://php.net/manual/en/language.variables.superglobals.php

I believe, (please show me otherwise) there are no globals in PHP other than 
SuperGlobals.

Cheers,

tedd

_
t...@sperling.com
http://sperling.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-02-12 Thread Michael Save
On Mon, Feb 13, 2012 at 5:28 PM, Rui Hu tchrb...@gmail.com wrote:
 hi,

 How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I know
 if I want to modify $_SERVER myself?

 Thanks!


 --
 Best regards,

 Rui Hu
 
 State Key Laboratory of Networking  Switching Technology
 Beijing University of Posts and Telecommunications(BUPT)
 MSN: tchrb...@gmail.com
 -

Rui,

$_SERVER is an associative array. You can access DOCUMENT_ROOT with
$_SERVER['DOCUMENT_ROOT']. It contains the document root directory
under which the current script is executing.

You can make changes to the $_SERVER array but it will have no effect
on PHP itself. I mean, you can change the value of
$_SERVER['DOCUMENT_ROOT'] to whatever you want at runtime, but of
course it will not actually change the current directory if that's
what you're after.

Thanks,
Michael

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] questions from page Reference Counting Basics

2012-01-08 Thread Adi Mutu


Hello,

I was reading http://www.php.net/manual/en/features.gc.refcounting-basics.php, 
and i saw this:

The xdebug_debug_zval() function does not show this, but you could see it by 
also displaying the memory pointer.

My question is, how can you get the memory pointer of a php variable? 

Thanks,
A.

[PHP] questions about fastcgi

2011-12-19 Thread Rui Hu
hi,

I encountered a problem while configured virtual host. My experiment
environment is Apache2+fastcgi+php-cgi.

I want to implement mass virtual hosting using rewrite rules based on
apache rewrite module. That is, for a request url like:
http://1000.xyz.com/test.php, apache will translate it to a absolute file
path like: $DOCUMENT_ROOT/1000/test.php, and then get this script to
execute.

And my conf is:
*RewriteEngine On*
*RewriteCond %{HTTP_HOST} !^www.xyz.com*
*RewriteCond %{HTTP_HOST} ^([^.]+)\.xyz\.com [NC]*
*RewriteRule (.*) /%1$1 [PT]*
I use inner redirection in order not to expose this detail to users.
Besides, I succeeded when I use external redirection, namely the [R] tag
instead of [PT] tag.
When I use [PT] tag, apache cannot run expectedly. I request a url :
http://1000.xyz.com/test.php, error message pops out like: The requested
URL /1000/cgi-bin/php.fcgi/1000/test.php was not found on this server.

I don't know if this error results from fastcgi, is it the inappropriate
config in fastcgi or inevitable problem by using it?

Really appreciate your help.

Vic

-- 
Best regards,

Rui Hu

State Key Laboratory of Networking  Switching Technology
Beijing University of Posts and Telecommunications(BUPT)
MSN: tchrb...@gmail.com
-


[PHP] Questions Regarding Recent Ubuntu PHP5 Security Announcement

2011-10-19 Thread Jon Watson
Hello All,

I am trying to make some sense of this PHP5 security vulnerability notice
from 18 October 2011:

http://comments.gmane.org/gmane.linux.ubuntu.security.announce/1478

It states that for Ubuntu 8.04 users, a PHP upgrade to 5.2.4 is required to
take care of the security issues. It also states that for Ubuntu 10.04
users, a PHP upgrade to 5.3.3 is required.

For operational reasons, I am running 5.2.17 on Ubuntu 10.04 and cannot
upgrade to PHP 5.3, Does anyone know if 5.2.17 is safe since evidently 5.2.4
is?

The security notice doesn't go into any real detail on the specific version
numbers so I am having trouble understanding what needs to be done.

Thanks.


-- 
Jon Watson
Systems Engineer
Teamspace Canada
Suite 304 Bedford Tower
1496 Bedford Highway, Bedford, NS, Canada  B4A 1E5
Phone:  902.444.3490 x | Fax: 902.444.3495
email: jon.wat...@teamspace.ca
http://www.theredspace.com | http://www.teamspace.ca


Re: [PHP] Questions Regarding Recent Ubuntu PHP5 Security Announcement

2011-10-19 Thread Jim Lucas
On 10/19/2011 7:00 AM, Jon Watson wrote:
 Hello All,
 
 I am trying to make some sense of this PHP5 security vulnerability notice
 from 18 October 2011:
 
 http://comments.gmane.org/gmane.linux.ubuntu.security.announce/1478
 
 It states that for Ubuntu 8.04 users, a PHP upgrade to 5.2.4 is required to
 take care of the security issues. It also states that for Ubuntu 10.04
 users, a PHP upgrade to 5.3.3 is required.
 
 For operational reasons, I am running 5.2.17 on Ubuntu 10.04 and cannot
 upgrade to PHP 5.3, Does anyone know if 5.2.17 is safe since evidently 5.2.4
 is?
 
 The security notice doesn't go into any real detail on the specific version
 numbers so I am having trouble understanding what needs to be done.
 
 Thanks.
 
 

This is discussing the packages distributed for Ubuntu X.X.  Sounds like what
you have is your own custom install.  If that is the case, the concern may still
apply, but it is going to be up to you to figure out what the security issue is
and verify your system in some manor.

-- 
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
http://www.bendsource.com/

C - (541) 408-5189
O - (541) 323-9113
H - (541) 323-4219

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions Regarding Recent Ubuntu PHP5 Security Announcement

2011-10-19 Thread Jon Watson
On Wed, Oct 19, 2011 at 11:54 AM, Jim Lucas li...@cmsws.com wrote:

 On 10/19/2011 7:00 AM, Jon Watson wrote:
  Hello All,
 
  I am trying to make some sense of this PHP5 security vulnerability notice
  from 18 October 2011:
 
  http://comments.gmane.org/gmane.linux.ubuntu.security.announce/1478

 snip


 This is discussing the packages distributed for Ubuntu X.X.  Sounds like
 what
 you have is your own custom install.  If that is the case, the concern may
 still
 apply, but it is going to be up to you to figure out what the security
 issue is
 and verify your system in some manor.


Agreed and I guess that is what I am trying to assess. The Ubuntu security
notice doesn't go into specifics about the 5.2.x version has the issues
other than presumably something earlier than 5.2.4. It would have been most
helpful of them to provide some sort of test or at least the full version of
the affected release.

So, basically hunting around for some confirmation that my version is OK.

I also find it odd that there is no accompanying security notice from
PHP.net. If this is a security vulnerability in PHP 5 as reported by
Canonical, why has PHP.net not released a security notice?


Re: [PHP] Questions Regarding Recent Ubuntu PHP5 Security Announcement

2011-10-19 Thread Jim Lucas
On 10/19/2011 8:05 AM, Jon Watson wrote:
 On Wed, Oct 19, 2011 at 11:54 AM, Jim Lucas li...@cmsws.com wrote:
 
 On 10/19/2011 7:00 AM, Jon Watson wrote:
 Hello All,

 I am trying to make some sense of this PHP5 security vulnerability notice
 from 18 October 2011:

 http://comments.gmane.org/gmane.linux.ubuntu.security.announce/1478

 snip
 
 
 This is discussing the packages distributed for Ubuntu X.X.  Sounds like
 what
 you have is your own custom install.  If that is the case, the concern may
 still
 apply, but it is going to be up to you to figure out what the security
 issue is
 and verify your system in some manor.

 
 Agreed and I guess that is what I am trying to assess. The Ubuntu security
 notice doesn't go into specifics about the 5.2.x version has the issues
 other than presumably something earlier than 5.2.4. It would have been most
 helpful of them to provide some sort of test or at least the full version of
 the affected release.
 
 So, basically hunting around for some confirmation that my version is OK.
 
 I also find it odd that there is no accompanying security notice from
 PHP.net. If this is a security vulnerability in PHP 5 as reported by
 Canonical, why has PHP.net not released a security notice?
 

My guess is that this is not a security issue with PHP but more so a security
issue with they way they had that version configured/setup on the system.

-- 
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
http://www.bendsource.com/

C - (541) 408-5189
O - (541) 323-9113
H - (541) 323-4219

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about if statements regarding a checkbox

2010-10-31 Thread a...@ashleysheridan.co.uk
What is the code you're using now? You have a syntax error, but without seeing 
the code, we are all left to guessing what the problem could be.

Thanks,
Ash
http://www.ashleysheridan.co.uk

- Reply message -
From: Ben Brentlinger b...@benbrent.com
Date: Sun, Oct 31, 2010 03:56
Subject: [PHP] questions about if statements regarding a checkbox
To: php-general@lists.php.net

I tried that, but I'm getting the syntax error that says unexpected 
T_IF.  Probably because I'm trying to process this information directly 
in an email rather letting a mysql database handle the data, which I 
find harder to set up when writing a script from scratch than it would 
be to code a php script to send the data in an email.

On 10/30/2010 22:28, ad...@buskirkgraphics.com wrote:

 input type=checkbox name=test

 If check it will submit the value of 'on'

 So

 If($_POST['test'] == on')
 {
 Do this
 }else{
 Do this
 }


 Richard L. Buskirk


 -Original Message-
 From: Ben Brentlinger [mailto:b...@benbrent.com]
 Sent: Saturday, October 30, 2010 10:05 PM
 To: php-general@lists.php.net
 Subject: [PHP] questions about if statements regarding a checkbox

 hello,

 I'd like to know the proper code to use in a php script that processes a
 form with a checkbox in order to send one email if the checkbox has been
 checked and another email if the checkbox hasn't.  I tried if($check ==
 true) and I tried putting the word true in double quotes, and both of
 them caused the unexpected variable syntax error.  The only problem
 is, all I could think to use was that line of code I just used, I'm not
 sure what the proper syntax is for checkbox when using the if statement
 to send one email when the checkbox is checked and a different email
 when it's not checked.  I'm wanting to send an email to the site admin
 with the information given by the person who filled out the form that
 contains the checkbox.


 Thanks,

 Ben


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about if statements regarding a checkbox

2010-10-31 Thread Andre Polykanine
Hello Ben,

You should use isset:
if (isset($_POST['check'])) {
// The checkbox is checked
} else {
// It's unchecked
}

-- 
With best regards from Ukraine,
Andre
Skype: Francophile
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion

- Original message -
From: Ben Brentlinger b...@benbrent.com
To: php-general@lists.php.net php-general@lists.php.net
Date: Sunday, October 31, 2010, 4:05:06 AM
Subject: [PHP] questions about if statements regarding a checkbox

hello,

I'd like to know the proper code to use in a php script that processes a 
form with a checkbox in order to send one email if the checkbox has been 
checked and another email if the checkbox hasn't.  I tried if($check == 
true) and I tried putting the word true in double quotes, and both of 
them caused the unexpected variable syntax error.  The only problem 
is, all I could think to use was that line of code I just used, I'm not 
sure what the proper syntax is for checkbox when using the if statement 
to send one email when the checkbox is checked and a different email 
when it's not checked.  I'm wanting to send an email to the site admin 
with the information given by the person who filled out the form that 
contains the checkbox.


Thanks,

Ben

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about if statements regarding a checkbox

2010-10-31 Thread Ben Brentlinger
Here's the code I'm using with the exception of the php tags and the 
redirect script that redirects to another page once the form is 
submitted.  This is just a test script I'm working on in order to teach 
myself php.  The php portion will be posted first, than the html form 
related to the php.  I've got the code inside tags similar to the code 
tag which only serves to serarate the php code from the html form.


[php_code]
$name = $_POST['firstname'] . ' ' . $_POST['lastname'];
$email = $_POST['email'];

if($_POST['reallife'] == on)
{
$to = 'b...@benbrent.com';
$subject ='test email one';
$msg = $name has filled out the test form. \n .
this is just a test message;
mail ($to, $subject, $msg, 'From:' . $email);

} else {

$to = 'b...@benbrent.com';
$subject ='test email two';
$msg = $name has filled out the test form. ;
mail ($to, $subject, $msg, 'From:' . $email);
}

if($_POST['reallife'] == on) {

$to = '$email';
$subject = Thank you email number one;
$msg = hello $name, \n .
thank you for filling out the form. \n .
This is the first of two test emails \n .
The second would have been sent \n .
if you had left the checkbox unchecked \n;
mail ($to, $subject, $msg, 'From:' . $...@benbrent.com);
}

header (location:thankyoupage)
[/php_code]



[html_code]
div align=center
table border=0
  cellpadding=3 cellspacing=0 width=59%
tr
td colspan=2
h2 align=centernbsp;/h2
h2 align=centerfont color=blue face=ArialContact Form/font/h2
p align=centernbsp;/p
td width=51% align=right
p align=leftfont face=ArialEmail/fontfont face=Times New 
Roman:/fontfont face=Arial /font/td

td width=49% align=leftinput type=text name=email size=20/td
/tr

tr
td width=51% align=right
p align=leftfont face=ArialFirst Name: /font/td
td width=49% align=leftinput type=text name=firstname 
size=20/td

/tr
tr
td width=51% align=right
p align=leftfont face=ArialLast Name: /font/td
td width=49% align=leftinput type=text name=lastname 
size=20/td

/tr
tr
td width=51% align=right
p align=leftfont face=ArialI know you in real life/font/td
td width=49% align=leftinput type=checkbox name=reallife 
size=20/td

/tr
/table
pinput type=submit value=contact me
  name=B1/p

/center/div
/form
/td
tdnbsp;/td
/tr
/table
[/html_code]


This actual code that is on the portion of my hosting account which I 
use as my test server.  In my opinion, it's much cheaper to pay for a 
hosting account to use as a test server to teach myself php than it is 
to pay some collage professor to teach it to you only to be slapped in 
the face by having him assume you're learning php to be a freelance 
coder working for a company that does freelance work.  The truth is, I 
only have an interest in learning php to use in my own business and when 
I get good enough, I may do some freelancing on the side on sites like 
Scriptlance, but my main focus will be my own business and for anyone to 
have the audacity that I plan on working for someone else my whole life 
pisses me off, so that's why I'd much rather teach myself than to take a 
college class on php.


Thanks,

Ben

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] questions about if statements regarding a checkbox

2010-10-31 Thread admin
I tested your code and besides adding a form to the beginning it works.

If you want to see the results of the posted for try.

print_r($_POST);

you can see every position of the array passed and validate they are passing as 
intended.

Try this.

//if reallife is not set (Checked it will not pass)
// I am pretty sure I read where someone had responded with the isset


if(isset($_POST['reallife']))
{

print_r($_POST);

}



Richard L. Buskirk


-Original Message-
From: Ben Brentlinger [mailto:b...@benbrent.com] 
Sent: Sunday, October 31, 2010 8:26 AM
To: php-general@lists.php.net
Subject: Re: [PHP] questions about if statements regarding a checkbox

Here's the code I'm using with the exception of the php tags and the 
redirect script that redirects to another page once the form is 
submitted.  This is just a test script I'm working on in order to teach 
myself php.  The php portion will be posted first, than the html form 
related to the php.  I've got the code inside tags similar to the code 
tag which only serves to serarate the php code from the html form.

[php_code]
$name = $_POST['firstname'] . ' ' . $_POST['lastname'];
$email = $_POST['email'];

if($_POST['reallife'] == on)
{
$to = 'b...@benbrent.com';
$subject ='test email one';
$msg = $name has filled out the test form. \n .
this is just a test message;
mail ($to, $subject, $msg, 'From:' . $email);

} else {

$to = 'b...@benbrent.com';
$subject ='test email two';
$msg = $name has filled out the test form. ;
mail ($to, $subject, $msg, 'From:' . $email);
}

if($_POST['reallife'] == on) {

$to = '$email';
$subject = Thank you email number one;
$msg = hello $name, \n .
thank you for filling out the form. \n .
This is the first of two test emails \n .
The second would have been sent \n .
if you had left the checkbox unchecked \n;
mail ($to, $subject, $msg, 'From:' . $...@benbrent.com);
}

header (location:thankyoupage)
[/php_code]



[html_code]
div align=center
table border=0
   cellpadding=3 cellspacing=0 width=59%
tr
td colspan=2
h2 align=centernbsp;/h2
h2 align=centerfont color=blue face=ArialContact Form/font/h2
p align=centernbsp;/p
td width=51% align=right
p align=leftfont face=ArialEmail/fontfont face=Times New 
Roman:/fontfont face=Arial /font/td
td width=49% align=leftinput type=text name=email size=20/td
/tr

tr
td width=51% align=right
p align=leftfont face=ArialFirst Name: /font/td
td width=49% align=leftinput type=text name=firstname 
size=20/td
/tr
tr
td width=51% align=right
p align=leftfont face=ArialLast Name: /font/td
td width=49% align=leftinput type=text name=lastname 
size=20/td
/tr
tr
td width=51% align=right
p align=leftfont face=ArialI know you in real life/font/td
td width=49% align=leftinput type=checkbox name=reallife 
size=20/td
/tr
/table
pinput type=submit value=contact me
   name=B1/p

/center/div
/form
/td
tdnbsp;/td
/tr
/table
[/html_code]


This actual code that is on the portion of my hosting account which I 
use as my test server.  In my opinion, it's much cheaper to pay for a 
hosting account to use as a test server to teach myself php than it is 
to pay some collage professor to teach it to you only to be slapped in 
the face by having him assume you're learning php to be a freelance 
coder working for a company that does freelance work.  The truth is, I 
only have an interest in learning php to use in my own business and when 
I get good enough, I may do some freelancing on the side on sites like 
Scriptlance, but my main focus will be my own business and for anyone to 
have the audacity that I plan on working for someone else my whole life 
pisses me off, so that's why I'd much rather teach myself than to take a 
college class on php.

Thanks,

Ben

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] questions about if statements regarding a checkbox

2010-10-31 Thread admin
I placed an example of your code on my site.
I simply pasted exactly what you had, minus the actual mailing portion.

If you check the box you will see the array, if you do not check the box no 
array.

http://www.richardbuskirk.com/blunk.php


Forgive my prior post, I had not woke up yet.
So the wording is missing things though, yet not put to email mid sentence.

Code from site.


?php
if(isset($_POST['reallife']))
{
print_r($_POST);
}
?

form action=? method=post
div align=center
table border=0
   cellpadding=3 cellspacing=0 width=59%
tr
td colspan=2
h2 align=centernbsp;/h2
h2 align=centerfont color=blue face=ArialContact Form/font/h2
p align=centernbsp;/p
td width=51% align=right
p align=leftfont face=ArialEmail/fontfont face=Times New
Roman:/fontfont face=Arial /font/td
td width=49% align=leftinput type=text name=email size=20/td
/tr

tr
td width=51% align=right
p align=leftfont face=ArialFirst Name: /font/td
td width=49% align=leftinput type=text name=firstname
size=20/td
/tr
tr
td width=51% align=right
p align=leftfont face=ArialLast Name: /font/td
td width=49% align=leftinput type=text name=lastname
size=20/td
/tr
tr
td width=51% align=right
p align=leftfont face=ArialI know you in real life/font/td
td width=49% align=leftinput type=checkbox name=reallife
size=20/td
/tr
/table
pinput type=submit value=contact me
   name=B1/p

/center/div
/form
/td
tdnbsp;/td
/tr
/table






Richard L. Buskirk


-Original Message-
From: ad...@buskirkgraphics.com [mailto:ad...@buskirkgraphics.com] 
Sent: Sunday, October 31, 2010 10:37 AM
To: 'Ben Brentlinger'; php-general@lists.php.net
Subject: RE: [PHP] questions about if statements regarding a checkbox

I tested your code and besides adding a form to the beginning it works.

If you want to see the results of the posted for try.

print_r($_POST);

you can see every position of the array passed and validate they are passing as 
intended.

Try this.

//if reallife is not set (Checked it will not pass)
// I am pretty sure I read where someone had responded with the isset


if(isset($_POST['reallife']))
{

print_r($_POST);

}



Richard L. Buskirk


-Original Message-
From: Ben Brentlinger [mailto:b...@benbrent.com] 
Sent: Sunday, October 31, 2010 8:26 AM
To: php-general@lists.php.net
Subject: Re: [PHP] questions about if statements regarding a checkbox

Here's the code I'm using with the exception of the php tags and the 
redirect script that redirects to another page once the form is 
submitted.  This is just a test script I'm working on in order to teach 
myself php.  The php portion will be posted first, than the html form 
related to the php.  I've got the code inside tags similar to the code 
tag which only serves to serarate the php code from the html form.

[php_code]
$name = $_POST['firstname'] . ' ' . $_POST['lastname'];
$email = $_POST['email'];

if($_POST['reallife'] == on)
{
$to = 'b...@benbrent.com';
$subject ='test email one';
$msg = $name has filled out the test form. \n .
this is just a test message;
mail ($to, $subject, $msg, 'From:' . $email);

} else {

$to = 'b...@benbrent.com';
$subject ='test email two';
$msg = $name has filled out the test form. ;
mail ($to, $subject, $msg, 'From:' . $email);
}

if($_POST['reallife'] == on) {

$to = '$email';
$subject = Thank you email number one;
$msg = hello $name, \n .
thank you for filling out the form. \n .
This is the first of two test emails \n .
The second would have been sent \n .
if you had left the checkbox unchecked \n;
mail ($to, $subject, $msg, 'From:' . $...@benbrent.com);
}

header (location:thankyoupage)
[/php_code]



[html_code]
div align=center
table border=0
   cellpadding=3 cellspacing=0 width=59%
tr
td colspan=2
h2 align=centernbsp;/h2
h2 align=centerfont color=blue face=ArialContact Form/font/h2
p align=centernbsp;/p
td width=51% align=right
p align=leftfont face=ArialEmail/fontfont face=Times New 
Roman:/fontfont face=Arial /font/td
td width=49% align=leftinput type=text name=email size=20/td
/tr

tr
td width=51% align=right
p align=leftfont face=ArialFirst Name: /font/td
td width=49% align=leftinput type=text name=firstname 
size=20/td
/tr
tr
td width=51% align=right
p align=leftfont face=ArialLast Name: /font/td
td width=49% align=leftinput type=text name=lastname 
size=20/td
/tr
tr
td width=51% align=right
p align=leftfont face=ArialI know you in real life/font/td
td width=49% align=leftinput type=checkbox name=reallife 
size=20/td
/tr
/table
pinput type=submit value=contact me
   name=B1/p

/center/div
/form
/td
tdnbsp;/td
/tr
/table
[/html_code]


This actual code that is on the portion of my hosting account which I 
use as my test server.  In my opinion, it's much cheaper to pay for a 
hosting account to use as a test server to teach myself php than it is 
to pay some collage professor to teach it to you only to be slapped in 
the face by having him assume you're learning php to be a freelance 
coder working for a company that does freelance work.  The truth is, I

Re: [PHP] questions about if statements regarding a checkbox

2010-10-31 Thread tedd

At 10:05 PM -0400 10/30/10, Ben Brentlinger wrote:

hello,

I'd like to know the proper code to use in a php script that 
processes a form with a checkbox in order to send one email if the 
checkbox has been checked and another email if the checkbox hasn't. 
I tried if($check == true) and I tried putting the word true in 
double quotes, and both of them caused the unexpected variable 
syntax error.  The only problem is, all I could think to use was 
that line of code I just used, I'm not sure what the proper syntax 
is for checkbox when using the if statement to send one email when 
the checkbox is checked and a different email when it's not checked. 
I'm wanting to send an email to the site admin with the information 
given by the person who filled out the form that contains the 
checkbox.



Thanks,

Ben


Ben:

Here you go:

http://php1.net/b/form-checkbox/

and if you want to make it sticky:

http://php1.net/b/form-checkbox1/

Cheers,

tedd

--
---
http://sperling.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about if statements regarding a checkbox

2010-10-31 Thread Ben Brentlinger
thanks for your help.  I just retested my code and even though it didn't 
work, I found the reason it wasn't working was because I had an unneeded 
space between the if and the rest of the if statement.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about if statements regarding a checkbox

2010-10-31 Thread Ben Brentlinger
Also, as far as the form is concerned, I actually did have the form in a 
separate .htm file, I just put the two together, separating them with 
the those tags to make them easier to read in the email.


On 10/31/2010 10:36, ad...@buskirkgraphics.com wrote:

I tested your code and besides adding a form to the beginning it works.

If you want to see the results of the posted for try.

print_r($_POST);

you can see every position of the array passed and validate they are passing as 
intended.

Try this.

//if reallife is not set (Checked it will not pass)
// I am pretty sure I read where someone had responded with the isset


if(isset($_POST['reallife']))
{

print_r($_POST);

}



Richard L. Buskirk


-Original Message-
From: Ben Brentlinger [mailto:b...@benbrent.com]
Sent: Sunday, October 31, 2010 8:26 AM
To: php-general@lists.php.net
Subject: Re: [PHP] questions about if statements regarding a checkbox

Here's the code I'm using with the exception of the php tags and the
redirect script that redirects to another page once the form is
submitted.  This is just a test script I'm working on in order to teach
myself php.  The php portion will be posted first, than the html form
related to the php.  I've got the code inside tags similar to the code
tag which only serves to serarate the php code from the html form.

[php_code]
$name = $_POST['firstname'] . ' ' . $_POST['lastname'];
$email = $_POST['email'];

if($_POST['reallife'] == on)
{
$to = 'b...@benbrent.com';
$subject ='test email one';
$msg = $name has filled out the test form. \n .
this is just a test message;
mail ($to, $subject, $msg, 'From:' . $email);

} else {

$to = 'b...@benbrent.com';
$subject ='test email two';
$msg = $name has filled out the test form. ;
mail ($to, $subject, $msg, 'From:' . $email);
}

if($_POST['reallife'] == on) {

$to = '$email';
$subject = Thank you email number one;
$msg = hello $name, \n .
thank you for filling out the form. \n .
This is the first of two test emails \n .
The second would have been sent \n .
if you had left the checkbox unchecked \n;
mail ($to, $subject, $msg, 'From:' . $...@benbrent.com);
}

header (location:thankyoupage)
[/php_code]



[html_code]
div align=center
table border=0
cellpadding=3 cellspacing=0 width=59%
tr
td colspan=2
h2 align=centernbsp;/h2
h2 align=centerfont color=blue face=ArialContact Form/font/h2
p align=centernbsp;/p
td width=51% align=right
p align=leftfont face=ArialEmail/fontfont face=Times New
Roman:/fontfont face=Arial  /font/td
td width=49% align=leftinput type=text name=email size=20/td
/tr

tr
td width=51% align=right
p align=leftfont face=ArialFirst Name:/font/td
td width=49% align=leftinput type=text name=firstname
size=20/td
/tr
tr
td width=51% align=right
p align=leftfont face=ArialLast Name:/font/td
td width=49% align=leftinput type=text name=lastname
size=20/td
/tr
tr
td width=51% align=right
p align=leftfont face=ArialI know you in real life/font/td
td width=49% align=leftinput type=checkbox name=reallife
size=20/td
/tr
/table
pinput type=submit value=contact me
name=B1/p

/center/div
/form
/td
tdnbsp;/td
/tr
/table
[/html_code]


This actual code that is on the portion of my hosting account which I
use as my test server.  In my opinion, it's much cheaper to pay for a
hosting account to use as a test server to teach myself php than it is
to pay some collage professor to teach it to you only to be slapped in
the face by having him assume you're learning php to be a freelance
coder working for a company that does freelance work.  The truth is, I
only have an interest in learning php to use in my own business and when
I get good enough, I may do some freelancing on the side on sites like
Scriptlance, but my main focus will be my own business and for anyone to
have the audacity that I plan on working for someone else my whole life
pisses me off, so that's why I'd much rather teach myself than to take a
college class on php.

Thanks,

Ben



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] questions about if statements regarding a checkbox

2010-10-30 Thread Ben Brentlinger

hello,

I'd like to know the proper code to use in a php script that processes a 
form with a checkbox in order to send one email if the checkbox has been 
checked and another email if the checkbox hasn't.  I tried if($check == 
true) and I tried putting the word true in double quotes, and both of 
them caused the unexpected variable syntax error.  The only problem 
is, all I could think to use was that line of code I just used, I'm not 
sure what the proper syntax is for checkbox when using the if statement 
to send one email when the checkbox is checked and a different email 
when it's not checked.  I'm wanting to send an email to the site admin 
with the information given by the person who filled out the form that 
contains the checkbox.



Thanks,

Ben

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about if statements regarding a checkbox

2010-10-30 Thread Adam Richardson
On Sat, Oct 30, 2010 at 10:05 PM, Ben Brentlinger b...@benbrent.com wrote:
 hello,

 I'd like to know the proper code to use in a php script that processes a
 form with a checkbox in order to send one email if the checkbox has been
 checked and another email if the checkbox hasn't.  I tried if($check ==
 true) and I tried putting the word true in double quotes, and both of them
 caused the unexpected variable syntax error.  The only problem is, all I
 could think to use was that line of code I just used, I'm not sure what the
 proper syntax is for checkbox when using the if statement to send one email
 when the checkbox is checked and a different email when it's not checked.
  I'm wanting to send an email to the site admin with the information given
 by the person who filled out the form that contains the checkbox.


// checkboxes are only set if checked
if (isset($_GET['checkbox_name'])) {
// checkbox is checked, so send one mail
mail($to = 'o...@email.com', $subject = 'Really cool email');
} else {
// checkbox isn't checked, so send a different email
mail($to = 'differ...@email.com', $subject = 'Just as cool email');
}

Adam

-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] questions about if statements regarding a checkbox

2010-10-30 Thread admin


input type=checkbox name=test

If check it will submit the value of 'on'

So 

If($_POST['test'] == on')
{
Do this
}else{
Do this
}


Richard L. Buskirk


-Original Message-
From: Ben Brentlinger [mailto:b...@benbrent.com] 
Sent: Saturday, October 30, 2010 10:05 PM
To: php-general@lists.php.net
Subject: [PHP] questions about if statements regarding a checkbox

hello,

I'd like to know the proper code to use in a php script that processes a 
form with a checkbox in order to send one email if the checkbox has been 
checked and another email if the checkbox hasn't.  I tried if($check == 
true) and I tried putting the word true in double quotes, and both of 
them caused the unexpected variable syntax error.  The only problem 
is, all I could think to use was that line of code I just used, I'm not 
sure what the proper syntax is for checkbox when using the if statement 
to send one email when the checkbox is checked and a different email 
when it's not checked.  I'm wanting to send an email to the site admin 
with the information given by the person who filled out the form that 
contains the checkbox.


Thanks,

Ben

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about if statements regarding a checkbox

2010-10-30 Thread Bastien


On 2010-10-30, at 10:28 PM, ad...@buskirkgraphics.com wrote:

 
 
 input type=checkbox name=test
 
 If check it will submit the value of 'on'
 
 So 
 
 If($_POST['test'] == on')
 {
 Do this
 }else{
 Do this
 }
 
 
 Richard L. Buskirk
 
 
 -Original Message-
 From: Ben Brentlinger [mailto:b...@benbrent.com] 
 Sent: Saturday, October 30, 2010 10:05 PM
 To: php-general@lists.php.net
 Subject: [PHP] questions about if statements regarding a checkbox
 
 hello,
 
 I'd like to know the proper code to use in a php script that processes a 
 form with a checkbox in order to send one email if the checkbox has been 
 checked and another email if the checkbox hasn't.  I tried if($check == 
 true) and I tried putting the word true in double quotes, and both of 
 them caused the unexpected variable syntax error.  The only problem 
 is, all I could think to use was that line of code I just used, I'm not 
 sure what the proper syntax is for checkbox when using the if statement 
 to send one email when the checkbox is checked and a different email 
 when it's not checked.  I'm wanting to send an email to the site admin 
 with the information given by the person who filled out the form that 
 contains the checkbox.
 
 
 Thanks,
 
 Ben
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

input type=checkbox name=test value=1
input type=checkbox name=test value=2
input type=checkbox name=test value=3

?php

$Val=$_POST['test'];

switch($Val){
  case 1:
// do something
break;

  case 2:
//do something else
break;

  default:
 //another process

}



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about if statements regarding a checkbox

2010-10-30 Thread Ben Brentlinger
I tried that, but I'm getting the syntax error that says unexpected 
T_IF.  Probably because I'm trying to process this information directly 
in an email rather letting a mysql database handle the data, which I 
find harder to set up when writing a script from scratch than it would 
be to code a php script to send the data in an email.


On 10/30/2010 22:28, ad...@buskirkgraphics.com wrote:


input type=checkbox name=test

If check it will submit the value of 'on'

So

If($_POST['test'] == on')
{
Do this
}else{
Do this
}


Richard L. Buskirk


-Original Message-
From: Ben Brentlinger [mailto:b...@benbrent.com]
Sent: Saturday, October 30, 2010 10:05 PM
To: php-general@lists.php.net
Subject: [PHP] questions about if statements regarding a checkbox

hello,

I'd like to know the proper code to use in a php script that processes a
form with a checkbox in order to send one email if the checkbox has been
checked and another email if the checkbox hasn't.  I tried if($check ==
true) and I tried putting the word true in double quotes, and both of
them caused the unexpected variable syntax error.  The only problem
is, all I could think to use was that line of code I just used, I'm not
sure what the proper syntax is for checkbox when using the if statement
to send one email when the checkbox is checked and a different email
when it's not checked.  I'm wanting to send an email to the site admin
with the information given by the person who filled out the form that
contains the checkbox.


Thanks,

Ben



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions from a Newbie

2010-10-19 Thread Ethan Rosenberg

Tamara -

Thanks.

No error_log.

This works ...

htmlbody
?php phpinfo(); ?
/body/html

Ethan
++
At 02:23 AM 10/19/2010, Tamara Temple wrote:

On Oct 18, 2010, at 11:01 PM, Ethan Rosenberg wrote:



I've added the code you suggest, and I still get a blank screen.
Should I be explicitly be using mysqli functions; eg mysqli_connect?

Odd you should still get a blank screen and nothing in the error_log...

Does phpinfo() work?


Ethan

At 11:00 PM 10/18/2010, you wrote:

Where do you set $host, $user and $password?

You should add the following after the new mysqli statement:

if ($mysqli-connect_error) {
   die('Connect Error (' . $mysqli-connect_errno . ') '
   . $mysqli-connect_error);
}

Tamara Temple
-- aka tamouse__
mailto:tam...@tamaratemple.comtam...@tamaratemple.com


May you never see a stranger's face in the mirror.

On Oct 18, 2010, at 4:09 PM, Ethan Rosenberg wrote:


At 05:37 PM 10/17/2010, Tamara Temple wrote:

gah, i botched that up.

For the first part, you want the following:

   $cxn = new mysql($host, $user, $password);
   $res = $cxn-query(create database test22:);
   if (!$res) {
   die(Failed to create database test22:  . 
$cxn- error());

   }

Then, reopen the connection with the new data base:

   $cxn = new mysql($host, $user, $password, test22);

Then the following code will work.


Tamara Temple
   -- aka tamouse__
mailto:tam...@tamaratemple.comtam...@tamaratemple.com


May you never see a stranger's face in the mirror.

On Oct 17, 2010, at 4:26 PM, Tamara Temple wrote:



On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote:

At 01:41 AM 10/17/2010, Tommy Pham wrote:

 I cannot get the following to work.  In my Firefox [Iceweasel]
browser, I
 enter the following URL: [w/ the http]


Whenever you get a blank screen running a php application, the
place
to look is the http server's error_log. This is frequently found
in / var/log/httpd/error_log or /var/log/apache2/error_log. (If
your
system is hosted someplace else, it could very easily be in a
different place). Typically you need root permission to read this
file. Tail the file after you run your PHP script to see the most
recent errors.


 The code  contained in the file CreateNew.php is:

 /*
   *  Create Database test22
   */
   htmlbody
 ?php
 $cxn = mysqli_connect($host,$user,$password);


Better to use the OO approach:

   $cxn = new mysqli($host, $user, $password);


 echoCreate database test22;


Instead of echo statements (which would just echo the contents to
the output, i.e., your browser, you want to assign them to a
variable, such as:

  $sql = create database test22; use test22;

Then you need to execute the sql statement:

   $res = $cxn-query($sql);
   if (!$res) {
   die(Could not create database test22:  . 
$cxn- error());

   }


 echoCreate table Names2


   $sql = create table Names2


 (
  RecordNum Int(11) Primary Key Not null default=1
auto_increment,
  FirstName varchar(10),
  LastName varchar(10),
  Height  decimal(4,1),
  Weight0 decimal(4,1),
  BMI decimal(3,1)
  Date0 date
 );


 ; // to close off the php statement
   $res = $cxn-query($sql);
   if (!$res) {
   die(Could not create table Names2:  . $cxn- error());
   }



 echo   Create table Visit2


   $sql = create table Visit2


 (
  Indx Int(7) Primary Key Not null auto_increment,
  Weight decimal(4,1) not null,
  StudyDate date not null,
  RecordNum Int(11)
 );


   ; // again, to close off the php statement
   $res = $cxn-query($sql);
   if (!$res) {
   die(Could not create table Visit2:  . $cxn- error());
   }



  $sql= SHOW DATABASES;


This doesn't work in a programmatic setting.

Terminate the database connection:

   $cxn-close();


 ?
 /body/html



 I would also like to be able to add data to a table, using
PHP,
which I
can do
 in MySQL as:
 load data infile '/home/ethan/Databases/tester21.dat.' replace
into table
 Names fields escaped by '\\' terminated by '\t'  lines
terminated by '\n'
;


That's a specific feature of the mysql program. You'd have to
write
something in php to be able to parse the file and insert the data.
There are examples all over the net. Then you would need to set up
sql insert or replace statements to actually get the data into the
data base using mysqli::query. There are numerous examples of this
as well.

Here's one example:

?php

   $host = localhost;
   $user = root;
   $pwd = rootpassword;
   $db = test22;
   $table = table_to_insert_into;

   $cxn = new mysql($host, $user, $pwd, $db);

   $filename = tab-delimited.txt;
   $contents = file($filename); // returns the contents of
the file
into an array, one line of file per array

   $columns = explode(\t, $contents[0]); // get the column
names
from the first line 

RE: [PHP] Questions from a Newbie

2010-10-19 Thread Tommy Pham
 -Original Message-
 From: Ethan Rosenberg [mailto:eth...@earthlink.net]
 Sent: Tuesday, October 19, 2010 12:05 AM
 To: php-general@lists.php.net
 Subject: Re: [PHP] Questions from a Newbie
 
 Tamara -
 
 Thanks.
 
 No error_log.
 

The error log only exists if he configures it properly and the script has
error.  IE: log_errors  error_log.  Like I said, Ethan should start from
the beginning of the manual.  It covers the configuration of PHP in addition
to the fundamentals of PHP.

 This works ...
 
 htmlbody
 ?php phpinfo(); ?
 /body/html
 
 Ethan
 ++
 At 02:23 AM 10/19/2010, Tamara Temple wrote:
 On Oct 18, 2010, at 11:01 PM, Ethan Rosenberg wrote:
 
 
 I've added the code you suggest, and I still get a blank screen.
 Should I be explicitly be using mysqli functions; eg mysqli_connect?
 Odd you should still get a blank screen and nothing in the error_log...
 
 Does phpinfo() work?
 
 Ethan
 
 At 11:00 PM 10/18/2010, you wrote:
 Where do you set $host, $user and $password?
 
 You should add the following after the new mysqli statement:
 
 if ($mysqli-connect_error) {
 die('Connect Error (' . $mysqli-connect_errno . ') '
 . $mysqli-connect_error); }
 
 Tamara Temple
 -- aka tamouse__
 mailto:tam...@tamaratemple.comtam...@tamaratemple.com
 
 
 May you never see a stranger's face in the mirror.
 
 On Oct 18, 2010, at 4:09 PM, Ethan Rosenberg wrote:
 
 At 05:37 PM 10/17/2010, Tamara Temple wrote:
 gah, i botched that up.
 
 For the first part, you want the following:
 
 $cxn = new mysql($host, $user, $password);
 $res = $cxn-query(create database test22:);
 if (!$res) {
 die(Failed to create database test22:  .
  $cxn- error());
 }
 
 Then, reopen the connection with the new data base:
 
 $cxn = new mysql($host, $user, $password, test22);
 
 Then the following code will work.
 
 
 Tamara Temple
 -- aka tamouse__
 mailto:tam...@tamaratemple.comtam...@tamaratemple.com
 
 
 May you never see a stranger's face in the mirror.
 
 On Oct 17, 2010, at 4:26 PM, Tamara Temple wrote:
 
 
 On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote:
 At 01:41 AM 10/17/2010, Tommy Pham wrote:
   I cannot get the following to work.  In my Firefox
   [Iceweasel]
 browser, I
   enter the following URL: [w/ the http]
 
 Whenever you get a blank screen running a php application, the
 place to look is the http server's error_log. This is frequently
 found in / var/log/httpd/error_log or /var/log/apache2/error_log.
 (If your system is hosted someplace else, it could very easily be
 in a different place). Typically you need root permission to read
 this file. Tail the file after you run your PHP script to see the
 most recent errors.
 
   The code  contained in the file CreateNew.php is:
  
   /*
 *  Create Database test22
 */
 htmlbody
   ?php
   $cxn = mysqli_connect($host,$user,$password);
 
 Better to use the OO approach:
 
 $cxn = new mysqli($host, $user, $password);
 
   echoCreate database test22;
 
 Instead of echo statements (which would just echo the contents to
 the output, i.e., your browser, you want to assign them to a
 variable, such as:
 
$sql = create database test22; use test22;
 
 Then you need to execute the sql statement:
 
 $res = $cxn-query($sql);
 if (!$res) {
 die(Could not create database test22:  .
  $cxn- error());
 }
 
   echoCreate table Names2
 
 $sql = create table Names2
 
   (
RecordNum Int(11) Primary Key Not null default=1
 auto_increment,
FirstName varchar(10),
LastName varchar(10),
Height  decimal(4,1),
Weight0 decimal(4,1),
BMI decimal(3,1)
Date0 date
   );
 
   ; // to close off the php statement
 $res = $cxn-query($sql);
 if (!$res) {
 die(Could not create table Names2:  . $cxn-
error());
 }
 
  
   echo   Create table Visit2
 
 $sql = create table Visit2
 
   (
Indx Int(7) Primary Key Not null auto_increment,
Weight decimal(4,1) not null,
StudyDate date not null,
RecordNum Int(11)
   );
 
 ; // again, to close off the php statement
 $res = $cxn-query($sql);
 if (!$res) {
 die(Could not create table Visit2:  . $cxn-
error());
 }
 
  
$sql= SHOW DATABASES;
 
 This doesn't work in a programmatic setting.
 
 Terminate the database connection:
 
 $cxn-close();
 
   ?
   /body/html
 
   I would also like to be able to add data to a table, using
 PHP,
 which I
 can do
   in MySQL as:
   load data infile '/home/ethan/Databases/tester21.dat.'
   replace
 into table
   Names fields escaped by '\\' terminated by '\t'  lines
 terminated by '\n'
 ;
 
 That's a specific feature of the mysql program. You'd have to
 write something in php to be able to parse the file and insert

RE: [PHP] Questions from a Newbie

2010-10-19 Thread Ethan Rosenberg

Dear List -

The error log only exists if he configures it properly and the script has
error.  IE: log_errors  error_log.

I already had done that prior to the post.  That came from the 
manual, the necessary section thereof which had been read.


Now what?

Ethan
++
At 08:31 AM 10/19/2010, Tommy Pham wrote:

 -Original Message-
 From: Ethan Rosenberg [mailto:eth...@earthlink.net]
 Sent: Tuesday, October 19, 2010 12:05 AM
 To: php-general@lists.php.net
 Subject: Re: [PHP] Questions from a Newbie

 Tamara -

 Thanks.

 No error_log.


The error log only exists if he configures it properly and the script has
error.  IE: log_errors  error_log.  Like I said, Ethan should start from
the beginning of the manual.  It covers the configuration of PHP in addition
to the fundamentals of PHP.

 This works ...

 htmlbody
 ?php phpinfo(); ?
 /body/html

 Ethan
 ++
 At 02:23 AM 10/19/2010, Tamara Temple wrote:
 On Oct 18, 2010, at 11:01 PM, Ethan Rosenberg wrote:
 
 
 I've added the code you suggest, and I still get a blank screen.
 Should I be explicitly be using mysqli functions; eg mysqli_connect?
 Odd you should still get a blank screen and nothing in the error_log...
 
 Does phpinfo() work?
 
 Ethan
 
 At 11:00 PM 10/18/2010, you wrote:
 Where do you set $host, $user and $password?
 
 You should add the following after the new mysqli statement:
 
 if ($mysqli-connect_error) {
 die('Connect Error (' . $mysqli-connect_errno . ') '
 . $mysqli-connect_error); }
 
 Tamara Temple
 -- aka tamouse__
 mailto:tam...@tamaratemple.comtam...@tamaratemple.com
 
 
 May you never see a stranger's face in the mirror.
 
 On Oct 18, 2010, at 4:09 PM, Ethan Rosenberg wrote:
 
 At 05:37 PM 10/17/2010, Tamara Temple wrote:
 gah, i botched that up.
 
 For the first part, you want the following:
 
 $cxn = new mysql($host, $user, $password);
 $res = $cxn-query(create database test22:);
 if (!$res) {
 die(Failed to create database test22:  .
  $cxn- error());
 }
 
 Then, reopen the connection with the new data base:
 
 $cxn = new mysql($host, $user, $password, test22);
 
 Then the following code will work.
 
 
 Tamara Temple
 -- aka tamouse__
 mailto:tam...@tamaratemple.comtam...@tamaratemple.com
 
 
 May you never see a stranger's face in the mirror.
 
 On Oct 17, 2010, at 4:26 PM, Tamara Temple wrote:
 
 
 On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote:
 At 01:41 AM 10/17/2010, Tommy Pham wrote:
   I cannot get the following to work.  In my Firefox
   [Iceweasel]
 browser, I
   enter the following URL: [w/ the http]
 
 Whenever you get a blank screen running a php application, the
 place to look is the http server's error_log. This is frequently
 found in / var/log/httpd/error_log or /var/log/apache2/error_log.
 (If your system is hosted someplace else, it could very easily be
 in a different place). Typically you need root permission to read
 this file. Tail the file after you run your PHP script to see the
 most recent errors.
 
   The code  contained in the file CreateNew.php is:
  
   /*
 *  Create Database test22
 */
 htmlbody
   ?php
   $cxn = mysqli_connect($host,$user,$password);
 
 Better to use the OO approach:
 
 $cxn = new mysqli($host, $user, $password);
 
   echoCreate database test22;
 
 Instead of echo statements (which would just echo the contents to
 the output, i.e., your browser, you want to assign them to a
 variable, such as:
 
$sql = create database test22; use test22;
 
 Then you need to execute the sql statement:
 
 $res = $cxn-query($sql);
 if (!$res) {
 die(Could not create database test22:  .
  $cxn- error());
 }
 
   echoCreate table Names2
 
 $sql = create table Names2
 
   (
RecordNum Int(11) Primary Key Not null default=1
 auto_increment,
FirstName varchar(10),
LastName varchar(10),
Height  decimal(4,1),
Weight0 decimal(4,1),
BMI decimal(3,1)
Date0 date
   );
 
   ; // to close off the php statement
 $res = $cxn-query($sql);
 if (!$res) {
 die(Could not create table Names2:  . $cxn-
error());
 }
 
  
   echo   Create table Visit2
 
 $sql = create table Visit2
 
   (
Indx Int(7) Primary Key Not null auto_increment,
Weight decimal(4,1) not null,
StudyDate date not null,
RecordNum Int(11)
   );
 
 ; // again, to close off the php statement
 $res = $cxn-query($sql);
 if (!$res) {
 die(Could not create table Visit2:  . $cxn-
error());
 }
 
  
$sql= SHOW DATABASES;
 
 This doesn't work in a programmatic setting.
 
 Terminate the database connection:
 
 $cxn-close();
 
   ?
   /body/html
 
   I would also like to be able to add data to a table, using
 PHP,
 which I

RE: [PHP] Questions from a Newbie - Please Help

2010-10-19 Thread Ethan Rosenberg

Dear List -

I've checked the php.ini file [again] and cannot find any errors.

I wrote a PHP script to open a non-existent data base, and receive no error.

At this point, I am out of options.

Let's all look at the code, and tell me 1]where the error is and 
2]any corrections or additions to the ini file.


For personal reasons, which I cannot explain in a public forum, I am 
under extreme pressure to learn PHP ASAP.


Thank you.

Ethan
+++

At 08:31 AM 10/19/2010, Tommy Pham wrote:

 -Original Message-
 From: Ethan Rosenberg [mailto:eth...@earthlink.net]
 Sent: Tuesday, October 19, 2010 12:05 AM
 To: php-general@lists.php.net
 Subject: Re: [PHP] Questions from a Newbie

 Tamara -

 Thanks.

 No error_log.


The error log only exists if he configures it properly and the script has
error.  IE: log_errors  error_log.  Like I said, Ethan should start from
the beginning of the manual.  It covers the configuration of PHP in addition
to the fundamentals of PHP.

 This works ...

 htmlbody
 ?php phpinfo(); ?
 /body/html

 Ethan
 ++
 At 02:23 AM 10/19/2010, Tamara Temple wrote:
 On Oct 18, 2010, at 11:01 PM, Ethan Rosenberg wrote:
 
 
 I've added the code you suggest, and I still get a blank screen.
 Should I be explicitly be using mysqli functions; eg mysqli_connect?
 Odd you should still get a blank screen and nothing in the error_log...
 
 Does phpinfo() work?
 
 Ethan
 
 At 11:00 PM 10/18/2010, you wrote:
 Where do you set $host, $user and $password?
 
 You should add the following after the new mysqli statement:
 
 if ($mysqli-connect_error) {
 die('Connect Error (' . $mysqli-connect_errno . ') '
 . $mysqli-connect_error); }
 
 Tamara Temple
 -- aka tamouse__
 mailto:tam...@tamaratemple.comtam...@tamaratemple.com
 
 
 May you never see a stranger's face in the mirror.
 
 On Oct 18, 2010, at 4:09 PM, Ethan Rosenberg wrote:
 
 At 05:37 PM 10/17/2010, Tamara Temple wrote:
 gah, i botched that up.
 
 For the first part, you want the following:
 
 $cxn = new mysql($host, $user, $password);
 $res = $cxn-query(create database test22:);
 if (!$res) {
 die(Failed to create database test22:  .
  $cxn- error());
 }
 
 Then, reopen the connection with the new data base:
 
 $cxn = new mysql($host, $user, $password, test22);
 
 Then the following code will work.
 
 
 Tamara Temple
 -- aka tamouse__
 mailto:tam...@tamaratemple.comtam...@tamaratemple.com
 
 
 May you never see a stranger's face in the mirror.
 
 On Oct 17, 2010, at 4:26 PM, Tamara Temple wrote:
 
 
 On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote:
 At 01:41 AM 10/17/2010, Tommy Pham wrote:
   I cannot get the following to work.  In my Firefox
   [Iceweasel]
 browser, I
   enter the following URL: [w/ the http]
 
 Whenever you get a blank screen running a php application, the
 place to look is the http server's error_log. This is frequently
 found in / var/log/httpd/error_log or /var/log/apache2/error_log.
 (If your system is hosted someplace else, it could very easily be
 in a different place). Typically you need root permission to read
 this file. Tail the file after you run your PHP script to see the
 most recent errors.
 
   The code  contained in the file CreateNew.php is:
  
   /*
 *  Create Database test22
 */
 htmlbody
   ?php
   $cxn = mysqli_connect($host,$user,$password);
 
 Better to use the OO approach:
 
 $cxn = new mysqli($host, $user, $password);
 
   echoCreate database test22;
 
 Instead of echo statements (which would just echo the contents to
 the output, i.e., your browser, you want to assign them to a
 variable, such as:
 
$sql = create database test22; use test22;
 
 Then you need to execute the sql statement:
 
 $res = $cxn-query($sql);
 if (!$res) {
 die(Could not create database test22:  .
  $cxn- error());
 }
 
   echoCreate table Names2
 
 $sql = create table Names2
 
   (
RecordNum Int(11) Primary Key Not null default=1
 auto_increment,
FirstName varchar(10),
LastName varchar(10),
Height  decimal(4,1),
Weight0 decimal(4,1),
BMI decimal(3,1)
Date0 date
   );
 
   ; // to close off the php statement
 $res = $cxn-query($sql);
 if (!$res) {
 die(Could not create table Names2:  . $cxn-
error());
 }
 
  
   echo   Create table Visit2
 
 $sql = create table Visit2
 
   (
Indx Int(7) Primary Key Not null auto_increment,
Weight decimal(4,1) not null,
StudyDate date not null,
RecordNum Int(11)
   );
 
 ; // again, to close off the php statement
 $res = $cxn-query($sql);
 if (!$res) {
 die(Could not create table Visit2:  . $cxn-
error());
 }
 
  
$sql= SHOW DATABASES;
 
 This doesn't work in a programmatic

RE: [PHP] Questions from a Newbie

2010-10-19 Thread Tommy Pham
 -Original Message-
 From: Ethan Rosenberg [mailto:eth...@earthlink.net]
 Sent: Tuesday, October 19, 2010 9:19 AM
 To: Tommy Pham; php-general@lists.php.net
 Subject: RE: [PHP] Questions from a Newbie
 
 Dear List -
 
 The error log only exists if he configures it properly and the script has
error.
 IE: log_errors  error_log.
 
 I already had done that prior to the post.  That came from the manual, the
 necessary section thereof which had been read.
 
 Now what?
 
 Ethan
 ++
snip

Here's what I perceive your scenario to be:

1) Connect to DB:  success? If not, why not? Server problem? Network problem
if everything is not on the same box? Firewall issue? Account privilege?
2) Send query to DB: success?  If not, why not? Same questions as above...
Did something happened after a successful connection?
3) What do I do with the success of the query?  Check if it's as expected?
Store it somewhere for later use? Display the results in html/xml?

To achieve the above, you need to understand the fundamentals such as what a
variable is and the types of variables.  What control structures are
(conditions, loops, etc.)...  Did you read the all that I've mentioned?
Since you've mentioned reading the MySQL/MySQLi section was too much for you
to comprehend implies, to me, that you don't understand the fundamentals or
didn't read the sections from the official manual that are required to begin
working with PHP.

Here's the code from OP:

 /*
  *  Create Database test22
  */
  htmlbody
 ?php
 $cxn = mysqli_connect($host,$user,$password);

See point 1 for above.

 echoCreate database test22;

See point 2.  What's the difference between display it as text/html/xml and
assigning it to use? If to use, you need to understand the fundamentals of
SQL for the below statement, which is beyond the scope of this list.  What
database are you executing the below command for?  You wouldn't know that
unless you check the result.

 echoCreate table Names2
 (
RecordNum Int(11) Primary Key Not null default=1
auto_increment,
FirstName varchar(10),
LastName varchar(10),
Height  decimal(4,1),
Weight0 decimal(4,1),
BMI decimal(3,1)
Date0 date
 );


See point 2. The below statement is the same as statement above in the
process.

 echo   Create table Visit2
 (
Indx Int(7) Primary Key Not null auto_increment,
Weight decimal(4,1) not null,
StudyDate date not null,
RecordNum Int(11)
 );


See point 2.

$sql= SHOW DATABASES;

See point 2  3 for the above.

 ?
 /body/html

Regards,
Tommy


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Questions from a Newbie - Please Help

2010-10-19 Thread Steve Staples
thread has been trimmed to NOTHING

i am pretty sure i read it on here already...  but your PHP code looks
wrong.


ORIGNAL CODE:
/*
  *  Create Database test22
  */
  htmlbody
?php
$cxn = mysqli_connect($host,$user,$password);
echoCreate database test22;
echoCreate table Names2
(
 RecordNum Int(11) Primary Key Not null default=1
auto_increment,
 FirstName varchar(10),
 LastName varchar(10),
 Height  decimal(4,1),
 Weight0 decimal(4,1),
 BMI decimal(3,1)
 Date0 date
);

echo   Create table Visit2
(
 Indx Int(7) Primary Key Not null auto_increment,
 Weight decimal(4,1) not null,
 StudyDate date not null,
 RecordNum Int(11)
);

 $sql= SHOW DATABASES;
?
/body/html

FIXED CODE:

  htmlbody
?php
/*
  *  Create Database test22
  */
$cxn = mysqli_connect($host,$user,$password);
echoCreate database test22;
echoCreate table Names2
(
 RecordNum Int(11) Primary Key Not null default=1
auto_increment,
 FirstName varchar(10),
 LastName varchar(10),
 Height  decimal(4,1),
 Weight0 decimal(4,1),
 BMI decimal(3,1)
 Date0 date
);;

echoCreate table Visit2
(
 Indx Int(7) Primary Key Not null auto_increment,
 Weight decimal(4,1) not null,
 StudyDate date not null,
 RecordNum Int(11)
);;

 $sql= SHOW DATABASES;
?
/body/html

END FIXX

firstly... you are missing your ending ; AFTER the  on most of your
lines... and i've seen this before, where it wont throw the error.

secondly, all this is doing, is echoing out lines to either the console,
or the web page... it is not running the queries at all.  So, if you're
trying to execute this from a shell script, then the line starting with
$cxn that created the connection to the database, is irrelevant.

If you are trying to just run from the website, and show what you WANT
to do, then you have to end your statements with the ; character.  You
should be able to copy and paste my FIXED code, and it should echo out
something... it is helps, before you make the $cnx call, put in 
error_reporting(E_ALL);

lastly,  if you want to call the queries from php, then you will have to
remove the echo, and make them function calls to the database...

here is a VERY quick redo of your code to make the mysqli calls:


  htmlbody
?php
/*
  *  Create Database test22
  */
$cxn = mysqli_connect($host,$user,$password);
echoCreate database test22;
mysqli_query($cxn, Create table Names2
(
 RecordNum Int(11) Primary Key Not null default=1
auto_increment,
 FirstName varchar(10),
 LastName varchar(10),
 Height  decimal(4,1),
 Weight0 decimal(4,1),
 BMI decimal(3,1)
 Date0 date
););

mysqli_query($cxn, Create table Visit2
(
 Indx Int(7) Primary Key Not null auto_increment,
 Weight decimal(4,1) not null,
 StudyDate date not null,
 RecordNum Int(11)
););

 $sql= SHOW DATABASES;
$result = mysqli_query($cxn, $sql);
echo 'pre';
print_r($result);
echo '/pre';
?
/body/html


GOOD LUCK!  and just to note, i dont guarantee that this code will work,
i am only taking what you had, and adding a little more to it, and I
didn't test it out... 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Questions from a Newbie - Please Help

2010-10-19 Thread Tommy Pham
 -Original Message-
 From: Steve Staples [mailto:sstap...@mnsi.net]
 Sent: Tuesday, October 19, 2010 11:07 AM
 To: Ethan Rosenberg
 Cc: php-general@lists.php.net
 Subject: RE: [PHP] Questions from a Newbie - Please Help
 
 thread has been trimmed to NOTHING
 
 i am pretty sure i read it on here already...  but your PHP code looks wrong.
 
 
 ORIGNAL CODE:
 /*
   *  Create Database test22
   */
   htmlbody
 ?php
 $cxn = mysqli_connect($host,$user,$password);
 echoCreate database test22;
 echoCreate table Names2
 (
  RecordNum Int(11) Primary Key Not null default=1 auto_increment,
  FirstName varchar(10),
  LastName varchar(10),
  Height  decimal(4,1),
  Weight0 decimal(4,1),
  BMI decimal(3,1)
  Date0 date
 );
 
 echo   Create table Visit2
 (
  Indx Int(7) Primary Key Not null auto_increment,
  Weight decimal(4,1) not null,
  StudyDate date not null,
  RecordNum Int(11)
 );
 
  $sql= SHOW DATABASES;
 ?
 /body/html
 
 FIXED CODE:
 
   htmlbody
 ?php
 /*
   *  Create Database test22
   */
 $cxn = mysqli_connect($host,$user,$password);
 echoCreate database test22;
 echoCreate table Names2
 (
  RecordNum Int(11) Primary Key Not null default=1 auto_increment,
  FirstName varchar(10),
  LastName varchar(10),
  Height  decimal(4,1),
  Weight0 decimal(4,1),
  BMI decimal(3,1)
  Date0 date
 );;
 
 echoCreate table Visit2
 (
  Indx Int(7) Primary Key Not null auto_increment,
  Weight decimal(4,1) not null,
  StudyDate date not null,
  RecordNum Int(11)
 );;
 
  $sql= SHOW DATABASES;
 ?
 /body/html
 
 END FIXX
 
 firstly... you are missing your ending ; AFTER the  on most of your lines...
 and i've seen this before, where it wont throw the error.
 
 secondly, all this is doing, is echoing out lines to either the console, or 
 the
 web page... it is not running the queries at all.  So, if you're trying to 
 execute
 this from a shell script, then the line starting with $cxn that created the
 connection to the database, is irrelevant.
 
 If you are trying to just run from the website, and show what you WANT to
 do, then you have to end your statements with the ; character.  You should
 be able to copy and paste my FIXED code, and it should echo out
 something... it is helps, before you make the $cnx call, put in
 error_reporting(E_ALL);
 
 lastly,  if you want to call the queries from php, then you will have to
 remove the echo, and make them function calls to the database...
 
 here is a VERY quick redo of your code to make the mysqli calls:
 
 
   htmlbody
 ?php
 /*
   *  Create Database test22
   */
 $cxn = mysqli_connect($host,$user,$password);
 echoCreate database test22;

The 2 statements below would fail ;)

 mysqli_query($cxn, Create table Names2
 (
  RecordNum Int(11) Primary Key Not null default=1 auto_increment,
  FirstName varchar(10),
  LastName varchar(10),
  Height  decimal(4,1),
  Weight0 decimal(4,1),
  BMI decimal(3,1)
  Date0 date
 ););
 
 mysqli_query($cxn, Create table Visit2
 (
  Indx Int(7) Primary Key Not null auto_increment,
  Weight decimal(4,1) not null,
  StudyDate date not null,
  RecordNum Int(11)
 ););
 
  $sql= SHOW DATABASES;
   $result = mysqli_query($cxn, $sql);
   echo 'pre';
   print_r($result);
   echo '/pre';
 ?
 /body/html
 
 
 GOOD LUCK!  and just to note, i dont guarantee that this code will work, i am
 only taking what you had, and adding a little more to it, and I didn't test it
 out...
 
 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Questions from a Newbie - Please Help

2010-10-19 Thread Steve Staples
On Tue, 2010-10-19 at 11:18 -0700, Tommy Pham wrote:
  -Original Message-
  From: Steve Staples [mailto:sstap...@mnsi.net]
  Sent: Tuesday, October 19, 2010 11:07 AM
  To: Ethan Rosenberg
  Cc: php-general@lists.php.net
  Subject: RE: [PHP] Questions from a Newbie - Please Help
  
  thread has been trimmed to NOTHING
  
  i am pretty sure i read it on here already...  but your PHP code looks 
  wrong.
  
  
  ORIGNAL CODE:
  /*
*  Create Database test22
*/
htmlbody
  ?php
  $cxn = mysqli_connect($host,$user,$password);
  echoCreate database test22;
  echoCreate table Names2
  (
   RecordNum Int(11) Primary Key Not null default=1 
  auto_increment,
   FirstName varchar(10),
   LastName varchar(10),
   Height  decimal(4,1),
   Weight0 decimal(4,1),
   BMI decimal(3,1)
   Date0 date
  );
  
  echo   Create table Visit2
  (
   Indx Int(7) Primary Key Not null auto_increment,
   Weight decimal(4,1) not null,
   StudyDate date not null,
   RecordNum Int(11)
  );
  
   $sql= SHOW DATABASES;
  ?
  /body/html
  
  FIXED CODE:
  
htmlbody
  ?php
  /*
*  Create Database test22
*/
  $cxn = mysqli_connect($host,$user,$password);
  echoCreate database test22;
  echoCreate table Names2
  (
   RecordNum Int(11) Primary Key Not null default=1 
  auto_increment,
   FirstName varchar(10),
   LastName varchar(10),
   Height  decimal(4,1),
   Weight0 decimal(4,1),
   BMI decimal(3,1)
   Date0 date
  );;
  
  echoCreate table Visit2
  (
   Indx Int(7) Primary Key Not null auto_increment,
   Weight decimal(4,1) not null,
   StudyDate date not null,
   RecordNum Int(11)
  );;
  
   $sql= SHOW DATABASES;
  ?
  /body/html
  
  END FIXX
  
  firstly... you are missing your ending ; AFTER the  on most of your 
  lines...
  and i've seen this before, where it wont throw the error.
  
  secondly, all this is doing, is echoing out lines to either the console, or 
  the
  web page... it is not running the queries at all.  So, if you're trying to 
  execute
  this from a shell script, then the line starting with $cxn that created the
  connection to the database, is irrelevant.
  
  If you are trying to just run from the website, and show what you WANT to
  do, then you have to end your statements with the ; character.  You should
  be able to copy and paste my FIXED code, and it should echo out
  something... it is helps, before you make the $cnx call, put in
  error_reporting(E_ALL);
  
  lastly,  if you want to call the queries from php, then you will have to
  remove the echo, and make them function calls to the database...
  
  here is a VERY quick redo of your code to make the mysqli calls:
  
  
htmlbody
  ?php
  /*
*  Create Database test22
*/
  $cxn = mysqli_connect($host,$user,$password);
  echoCreate database test22;
 
 The 2 statements below would fail ;)

ACUTALLY... the only reason they fail, is becuase i didn't realize that
I kept the other echo above, and it didn't create the database... that
should have been:
mysqli_query($cxn, Create database test22);

and then inside, creating the table Names2 needs to be test22.Names2
and the same for visit2.

the other issue, is with the create Names2... where the primary key is
default=1000 (should be default 1000), and auto_increment... can't have
a default AND auto_increment.

other than those, this works fine...  providing he has the $user, $host,
$password declared as well.

I personally dont use this, i use the PEAR:MDB2 classes, so this was
just a quick php.net search... WHICH would have helped the OP on this
one.

http://ca.php.net/manual/en/mysqli.query.php

I hate to say it, since i was a noob once, but RTFM, or LRN2GOOGLE and
you will find it easier, and then once you can't understand it, ask.
but there was so much fail in the OP's code.  sorry.

I think the scary part, is that you're being forced to learn PHP to
develop in, and you can't figure out a simple echo statement?

Steve

  mysqli_query($cxn, Create table Names2
  (
   RecordNum Int(11) Primary Key Not null default=1 
  auto_increment,
   FirstName varchar(10),
   LastName varchar(10),
   Height  decimal(4,1),
   Weight0 decimal(4,1),
   BMI decimal(3,1)
   Date0 date
  ););
  
  mysqli_query($cxn, Create table Visit2
  (
   Indx Int(7) Primary Key Not null auto_increment,
   Weight decimal(4,1) not null,
   StudyDate date not null,
   RecordNum Int(11)
  ););
  
   $sql= SHOW DATABASES;
  $result = mysqli_query($cxn, $sql);
  echo 'pre';
  print_r($result);
  echo '/pre';
  ?
  /body/html
  
  
  GOOD LUCK!  and just to note, i dont guarantee that this code will work, i 
  am
  only taking what you had, and adding a little more

RE: [PHP] Questions from a Newbie - Please Help

2010-10-19 Thread Tommy Pham
 -Original Message-
 From: Steve Staples [mailto:sstap...@mnsi.net]
 Sent: Tuesday, October 19, 2010 11:51 AM
 To: php-general
 Subject: RE: [PHP] Questions from a Newbie - Please Help
 
 On Tue, 2010-10-19 at 11:18 -0700, Tommy Pham wrote:
   -Original Message-
   From: Steve Staples [mailto:sstap...@mnsi.net]
   Sent: Tuesday, October 19, 2010 11:07 AM
   To: Ethan Rosenberg
   Cc: php-general@lists.php.net
   Subject: RE: [PHP] Questions from a Newbie - Please Help
  
   thread has been trimmed to NOTHING
  
   i am pretty sure i read it on here already...  but your PHP code looks
 wrong.
  
  
   ORIGNAL CODE:
   /*
 *  Create Database test22
 */
 htmlbody
   ?php
   $cxn = mysqli_connect($host,$user,$password);
   echoCreate database test22;
   echoCreate table Names2
   (
RecordNum Int(11) Primary Key Not null default=1
 auto_increment,
FirstName varchar(10),
LastName varchar(10),
Height  decimal(4,1),
Weight0 decimal(4,1),
BMI decimal(3,1)
Date0 date
   );
  
   echo   Create table Visit2
   (
Indx Int(7) Primary Key Not null auto_increment,
Weight decimal(4,1) not null,
StudyDate date not null,
RecordNum Int(11)
   );
  
$sql= SHOW DATABASES;
   ?
   /body/html
  
   FIXED CODE:
  
 htmlbody
   ?php
   /*
 *  Create Database test22
 */
   $cxn = mysqli_connect($host,$user,$password);
   echoCreate database test22;
   echoCreate table Names2
   (
RecordNum Int(11) Primary Key Not null default=1
 auto_increment,
FirstName varchar(10),
LastName varchar(10),
Height  decimal(4,1),
Weight0 decimal(4,1),
BMI decimal(3,1)
Date0 date
   );;
  
   echoCreate table Visit2
   (
Indx Int(7) Primary Key Not null auto_increment,
Weight decimal(4,1) not null,
StudyDate date not null,
RecordNum Int(11)
   );;
  
$sql= SHOW DATABASES;
   ?
   /body/html
  
   END FIXX
  
   firstly... you are missing your ending ; AFTER the  on most of your 
   lines...
   and i've seen this before, where it wont throw the error.
  
   secondly, all this is doing, is echoing out lines to either the
   console, or the web page... it is not running the queries at all.
   So, if you're trying to execute this from a shell script, then the
   line starting with $cxn that created the connection to the database, is
 irrelevant.
  
   If you are trying to just run from the website, and show what you
   WANT to do, then you have to end your statements with the ;
   character.  You should be able to copy and paste my FIXED code,
   and it should echo out something... it is helps, before you make the
   $cnx call, put in error_reporting(E_ALL);
  
   lastly,  if you want to call the queries from php, then you will
   have to remove the echo, and make them function calls to the
 database...
  
   here is a VERY quick redo of your code to make the mysqli calls:
  
  
 htmlbody
   ?php
   /*
 *  Create Database test22
 */
   $cxn = mysqli_connect($host,$user,$password);
   echoCreate database test22;
 
  The 2 statements below would fail ;)
 
 ACUTALLY... the only reason they fail, is becuase i didn't realize that I kept
 the other echo above, and it didn't create the database... that should have
 been:
 mysqli_query($cxn, Create database test22);
 
 and then inside, creating the table Names2 needs to be test22.Names2
 and the same for visit2.
 
 the other issue, is with the create Names2... where the primary key is
 default=1000 (should be default 1000), and auto_increment... can't have a
 default AND auto_increment.
 
 other than those, this works fine...  providing he has the $user, $host,
 $password declared as well.
 
 I personally dont use this, i use the PEAR:MDB2 classes, so this was just a
 quick php.net search... WHICH would have helped the OP on this one.
 
 http://ca.php.net/manual/en/mysqli.query.php
 
 I hate to say it, since i was a noob once, but RTFM, or LRN2GOOGLE and you
 will find it easier, and then once you can't understand it, ask.
 but there was so much fail in the OP's code.  sorry.
 
 I think the scary part, is that you're being forced to learn PHP to develop 
 in,
 and you can't figure out a simple echo statement?
 
 Steve
 

I did point out MySQLi section in the manual but he said it was too much for 
him to comprehend.  And from the codes he provided, he lacked the basic 
knowledge of PHP.  Thus, he shouldn't even consider doing anything else, much 
less accessing the DB as there are more complications arise other than just PHP 
syntax error.

   mysqli_query($cxn, Create table Names2 (
RecordNum Int(11) Primary Key Not null default=1
 auto_increment,
FirstName varchar(10),
LastName varchar(10

RE: [PHP] Questions from a Newbie

2010-10-18 Thread Tommy Pham
 -Original Message-
 From: Paul M Foster [mailto:pa...@quillandmouse.com]
 Sent: Sunday, October 17, 2010 9:46 PM
 To: php-general@lists.php.net
 Subject: Re: [PHP] Questions from a Newbie
 
 On Sun, Oct 17, 2010 at 01:00:44AM -0400, Ethan Rosenberg wrote:
 
  Dear List -
 
  Here are some questions, which I am sure are trivial, but I am a
  newbie, and cannot find the answers online
 
  I cannot get the following to work.  In my Firefox [Iceweasel]
  browser, I enter the following URL: [w/ the http]
 
   localhost/CreateNew.php All I get is a blank browser screen.
 
  The code  contained in the file CreateNew.php is:
 
  /*
   *  Create Database test22
   */
   htmlbody
  ?php
  $cxn = mysqli_connect($host,$user,$password);
  echoCreate database test22;
  echoCreate table Names2
 
 There's no need to quote $host above. Why your echo statements aren't
 showing up possibly indicates the script is aborting before it gets to
them.
 
 In situations like this, check the error logs if possible. If not, break
the
 problem down into even smaller chunks. Do your connect with MySQL and
 then test to see if the connection actually worked. According to the docs,
 mysqli_connect() should return an object representing the connection. So
 check that first:
 
 if (!is_object($cxn))
   echo Not connected!;
 else
   echo Yep, it connected!;
 
  (
  RecordNum Int(11) Primary Key Not null default=1
 auto_increment,
  FirstName varchar(10),
  LastName varchar(10),
  Height  decimal(4,1),
  Weight0 decimal(4,1),
  BMI decimal(3,1)
  Date0 date
  );
 
 
 As has been mentioned, you're simply echoing these to the page, not
 sending them to MySQL. That won't work. You have to feed your SQL
 statements to the mysqli_query() function. See the docs.
 
 Also, let me strongly advise you against using upper-and-lower-case field
 names in your tables. Others will undoubtedly disagree, but I find this a
 maintenance nightmare in the long run. Note that in some SQL variants
 (maybe in MySQL as well; I don't recall), you must quote the field names
in
 queries to preserve their case and make the queries work.
 
  echo   Create table Visit2
  (
  Indx Int(7) Primary Key Not null auto_increment,
  Weight decimal(4,1) not null,
  StudyDate date not null,
  RecordNum Int(11)
  );
 
  $sql= SHOW DATABASES;
 
 As mentioned elsewhere, this statement won't work in a web context. It
 only works from the MySQL console interface. There are other ways to
 achieve this in a programming context, but they involve querying the MySQL
 meta-tables.
 
 Also, to those recommending PHPMyAdmin, it ignores the OP's question,
 and doesn't help him/her learn anything. It is completely possible to do
 what he wants programmatically, and often is done that way while
installing
 various frameworks, etc. *You're* welcome to use PHPMyAdmin, but let the
 OP do it his/her way, and help them along if you can.
 
 Paul
 
 --
 Paul M. Foster
 

I recommended phpMyAdmin because I thought that he wanted to manage the
database using PHP.  Anyway, he lacked the fundamental understanding of PHP
and wanted to get into more advanced stuff.  As for what he intends in OP,
the statements will work provided that the MySQL account has the proper
privileges to do so and if the MySQL server is configured with 'show
databases' enabled.  Either case, he won't know for sure if those statements
executed correctly unless he understood the PHP fundamentals and use
conditions to check the results of each individual statement execution.
That's why I recommended him to read the manual from the beginning to get
the fundamentals because reading that MySQL section in the manual was too
much for him.

Regards,
Tommy 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions from a Newbie

2010-10-17 Thread Alexis
Ethan,you have the end of line semi colons enclosed in double 
quotes..move them to the true end of line.


On 17/10/10 04:45, Christian Heinrich wrote:

Am Sonntag, den 17.10.2010, 01:00 -0400 schrieb Ethan Rosenberg:

Dear List -

Here are some questions, which I am sure are trivial, but I am a
newbie, and cannot find the answers online

I cannot get the following to work.  In my Firefox [Iceweasel]
browser, I enter the following URL: [w/ the http]

   localhost/CreateNew.php All I get is a blank browser screen.

The code  contained in the file CreateNew.php is:

/*
   *  Create Database test22
   */
   htmlbody
?php
$cxn = mysqli_connect($host,$user,$password);
echoCreate database test22;
echoCreate table Names2
(
  RecordNum Int(11) Primary Key Not null default=1 auto_increment,
  FirstName varchar(10),
  LastName varchar(10),
  Height  decimal(4,1),
  Weight0 decimal(4,1),
  BMI decimal(3,1)
  Date0 date
);

echo   Create table Visit2
(
  Indx Int(7) Primary Key Not null auto_increment,
  Weight decimal(4,1) not null,
  StudyDate date not null,
  RecordNum Int(11)
);

  $sql= SHOW DATABASES;
?
/body/html

If I search for test22 or Visit2, nothing is found.

I would also like to be able to add data to a table, using PHP, which
I can do in MySQL as:
load data infile '/home/ethan/Databases/tester21.dat.' replace into
table Names fields escaped by '\\' terminated by '\t'  lines
terminated by '\n' ;

Thanks in advance.

Ethan
===
Using Debian(sid)






Hi,

maybe you also want to take a look at PDO - http://php.net/pdo

Regards
Christian




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions from a Newbie

2010-10-17 Thread Christian Heinrich
Am Sonntag, den 17.10.2010, 01:00 -0400 schrieb Ethan Rosenberg:
 Dear List -
 
 Here are some questions, which I am sure are trivial, but I am a 
 newbie, and cannot find the answers online
 
 I cannot get the following to work.  In my Firefox [Iceweasel] 
 browser, I enter the following URL: [w/ the http]
 
   localhost/CreateNew.php All I get is a blank browser screen.
 
 The code  contained in the file CreateNew.php is:
 
 /*
   *  Create Database test22
   */
   htmlbody
 ?php
 $cxn = mysqli_connect($host,$user,$password);
 echoCreate database test22;
 echoCreate table Names2
 (
  RecordNum Int(11) Primary Key Not null default=1 auto_increment,
  FirstName varchar(10),
  LastName varchar(10),
  Height  decimal(4,1),
  Weight0 decimal(4,1),
  BMI decimal(3,1)
  Date0 date
 );
 
 echo   Create table Visit2
 (
  Indx Int(7) Primary Key Not null auto_increment,
  Weight decimal(4,1) not null,
  StudyDate date not null,
  RecordNum Int(11)
 );
 
  $sql= SHOW DATABASES;
 ?
 /body/html
 
 If I search for test22 or Visit2, nothing is found.
 
 I would also like to be able to add data to a table, using PHP, which 
 I can do in MySQL as:
 load data infile '/home/ethan/Databases/tester21.dat.' replace into 
 table Names fields escaped by '\\' terminated by '\t'  lines 
 terminated by '\n' ;
 
 Thanks in advance.
 
 Ethan
 ===
 Using Debian(sid)  
 
 
 


Hi,

maybe you also want to take a look at PDO - http://php.net/pdo

Regards
Christian


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Questions from a Newbie

2010-10-17 Thread Tommy Pham
 -Original Message-
 From: Alexis [mailto:phplis...@antonakis.co.uk]
 Sent: Sunday, October 17, 2010 4:10 AM
 To: php-general@lists.php.net
 Subject: Re: [PHP] Questions from a Newbie
 
 Ethan,you have the end of line semi colons enclosed in double
 quotes..move them to the true end of line.
 

Even if he does move the semicolons to outside the quote, it doesn't do what he 
intended as maintaining the database.  His code merely echo the SQL syntax for 
viewing and not actually executing the SQL syntax, which is what I think he 
intended.  In which case, he's better off using phpMyAdmin.

Regards,
Tommy

 On 17/10/10 04:45, Christian Heinrich wrote:
  Am Sonntag, den 17.10.2010, 01:00 -0400 schrieb Ethan Rosenberg:
  Dear List -
 
  Here are some questions, which I am sure are trivial, but I am a
  newbie, and cannot find the answers online
 
  I cannot get the following to work.  In my Firefox [Iceweasel]
  browser, I enter the following URL: [w/ the http]
 
 localhost/CreateNew.php All I get is a blank browser screen.
 
  The code  contained in the file CreateNew.php is:
 
  /*
 *  Create Database test22
 */
 htmlbody
  ?php
  $cxn = mysqli_connect($host,$user,$password);
  echoCreate database test22;
  echoCreate table Names2
  (
RecordNum Int(11) Primary Key Not null default=1
 auto_increment,
FirstName varchar(10),
LastName varchar(10),
Height  decimal(4,1),
Weight0 decimal(4,1),
BMI decimal(3,1)
Date0 date
  );
 
  echo   Create table Visit2
  (
Indx Int(7) Primary Key Not null auto_increment,
Weight decimal(4,1) not null,
StudyDate date not null,
RecordNum Int(11)
  );
 
$sql= SHOW DATABASES;
  ?
  /body/html
 
  If I search for test22 or Visit2, nothing is found.
 
  I would also like to be able to add data to a table, using PHP, which
  I can do in MySQL as:
  load data infile '/home/ethan/Databases/tester21.dat.' replace into
  table Names fields escaped by '\\' terminated by '\t'  lines
  terminated by '\n' ;
 
  Thanks in advance.
 
  Ethan
  ===
  Using Debian(sid)
 
 
 
 
 
  Hi,
 
  maybe you also want to take a look at PDO - http://php.net/pdo
 
  Regards
  Christian
 
 
 
 --
 PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
 http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Questions from a Newbie

2010-10-17 Thread Ethan Rosenberg



At 01:41 AM 10/17/2010, Tommy Pham wrote:

 -Original Message-
 From: Ethan Rosenberg [mailto:eth...@earthlink.net]
 Sent: Saturday, October 16, 2010 10:01 PM
 To: php-general@lists.php.net
 Subject: [PHP] Questions from a Newbie

 Dear List -

 Here are some questions, which I am sure are trivial, but I am a newbie,
and
 cannot find the answers online

 I cannot get the following to work.  In my Firefox [Iceweasel] browser, I
 enter the following URL: [w/ the http]

   localhost/CreateNew.php All I get is a blank browser screen.

 The code  contained in the file CreateNew.php is:

 /*
   *  Create Database test22
   */
   htmlbody
 ?php
 $cxn = mysqli_connect($host,$user,$password);
 echoCreate database test22;
 echoCreate table Names2
 (
  RecordNum Int(11) Primary Key Not null default=1
auto_increment,
  FirstName varchar(10),
  LastName varchar(10),
  Height  decimal(4,1),
  Weight0 decimal(4,1),
  BMI decimal(3,1)
  Date0 date
 );

 echo   Create table Visit2
 (
  Indx Int(7) Primary Key Not null auto_increment,
  Weight decimal(4,1) not null,
  StudyDate date not null,
  RecordNum Int(11)
 );

  $sql= SHOW DATABASES;
 ?
 /body/html

 If I search for test22 or Visit2, nothing is found.

 I would also like to be able to add data to a table, using PHP, which I
can do
 in MySQL as:
 load data infile '/home/ethan/Databases/tester21.dat.' replace into table
 Names fields escaped by '\\' terminated by '\t'  lines terminated by '\n'
;

 Thanks in advance.

 Ethan
 ===
 Using Debian(sid)


You're reinventing the wheel that's been rolling along very smoothly for a
long time... Google 'phpmyadmin'.  Also, read this entire section [1].

Regards,
Tommy

[1] http://www.php.net/manual/en/book.mysqli.php


Tommy -

Thanks.

As I stated, I am a newbie.

1] I am trying to shorten the learning curve by asking some 
questions, which I understand are probably trivial.  A whole MySQLi 
list of functions at this point is to much for me.  I have to break 
the problem into manageable parts.


2] It has been my experience that using a GUI does not teach the 
whole subject.  Linux, which is the OS I use cannot be run from a GUI.


In the code being discussed, I wish to create a database and add two 
tables.  I also note a MySQL statement that can be used to add data 
to an existing table, and wish to be able to execute this statement 
using PHP.


So, therefore..

Let us try to answer the following two(2) questions:

a] What changes [other than moving the simicolons] have to be made to 
correct the code.


b] What books can you suggest to help w/ MySQL and PHP?  I already 
have the SQL, MySQL  PHP, and HTML books in the . for Dummies 
series.  I need something with a little more depth and detail.


Thanks to all for your excellent help.

Ethan

 Using Debian(sid)
 




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions from a Newbie

2010-10-17 Thread a...@ashleysheridan.co.uk
Linux can be run as a GUI, using a window manager.

Aside from that, have a look at the manual pages on php.net, which give some 
good examples of how to use the various mysql functions.

Also, on your development machine, its a good idea to turn on errors, as it can 
indicate where these problems are. You can do this from the php.ini, look for 
display_errors.

Thanks,
Ash
http://www.ashleysheridan.co.uk

- Reply message -
From: Ethan Rosenberg eth...@earthlink.net
Date: Sun, Oct 17, 2010 19:22
Subject: [PHP] Questions from a Newbie
To: Tommy Pham tommy...@gmail.com, php-general@lists.php.net



At 01:41 AM 10/17/2010, Tommy Pham wrote:
  -Original Message-
  From: Ethan Rosenberg [mailto:eth...@earthlink.net]
  Sent: Saturday, October 16, 2010 10:01 PM
  To: php-general@lists.php.net
  Subject: [PHP] Questions from a Newbie
 
  Dear List -
 
  Here are some questions, which I am sure are trivial, but I am a newbie,
and
  cannot find the answers online
 
  I cannot get the following to work.  In my Firefox [Iceweasel] browser, I
  enter the following URL: [w/ the http]
 
localhost/CreateNew.php All I get is a blank browser screen.
 
  The code  contained in the file CreateNew.php is:
 
  /*
*  Create Database test22
*/
htmlbody
  ?php
  $cxn = mysqli_connect($host,$user,$password);
  echoCreate database test22;
  echoCreate table Names2
  (
   RecordNum Int(11) Primary Key Not null default=1
auto_increment,
   FirstName varchar(10),
   LastName varchar(10),
   Height  decimal(4,1),
   Weight0 decimal(4,1),
   BMI decimal(3,1)
   Date0 date
  );
 
  echo   Create table Visit2
  (
   Indx Int(7) Primary Key Not null auto_increment,
   Weight decimal(4,1) not null,
   StudyDate date not null,
   RecordNum Int(11)
  );
 
   $sql= SHOW DATABASES;
  ?
  /body/html
 
  If I search for test22 or Visit2, nothing is found.
 
  I would also like to be able to add data to a table, using PHP, which I
can do
  in MySQL as:
  load data infile '/home/ethan/Databases/tester21.dat.' replace into table
  Names fields escaped by '\\' terminated by '\t'  lines terminated by '\n'
;
 
  Thanks in advance.
 
  Ethan
  ===
  Using Debian(sid)
 

You're reinventing the wheel that's been rolling along very smoothly for a
long time... Google 'phpmyadmin'.  Also, read this entire section [1].

Regards,
Tommy

[1] http://www.php.net/manual/en/book.mysqli.php

Tommy -

Thanks.

As I stated, I am a newbie.

1] I am trying to shorten the learning curve by asking some 
questions, which I understand are probably trivial.  A whole MySQLi 
list of functions at this point is to much for me.  I have to break 
the problem into manageable parts.

2] It has been my experience that using a GUI does not teach the 
whole subject.  Linux, which is the OS I use cannot be run from a GUI.

In the code being discussed, I wish to create a database and add two 
tables.  I also note a MySQL statement that can be used to add data 
to an existing table, and wish to be able to execute this statement 
using PHP.

So, therefore..

Let us try to answer the following two(2) questions:

a] What changes [other than moving the simicolons] have to be made to 
correct the code.

b] What books can you suggest to help w/ MySQL and PHP?  I already 
have the SQL, MySQL  PHP, and HTML books in the . for Dummies 
series.  I need something with a little more depth and detail.

Thanks to all for your excellent help.

Ethan

  Using Debian(sid)
 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions from a Newbie

2010-10-17 Thread Tamara Temple


On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote:

At 01:41 AM 10/17/2010, Tommy Pham wrote:
 I cannot get the following to work.  In my Firefox [Iceweasel]  
browser, I

 enter the following URL: [w/ the http]


Whenever you get a blank screen running a php application, the place  
to look is the http server's error_log. This is frequently found in / 
var/log/httpd/error_log or /var/log/apache2/error_log. (If your system  
is hosted someplace else, it could very easily be in a different  
place). Typically you need root permission to read this file. Tail the  
file after you run your PHP script to see the most recent errors.



 The code  contained in the file CreateNew.php is:

 /*
   *  Create Database test22
   */
   htmlbody
 ?php
 $cxn = mysqli_connect($host,$user,$password);


Better to use the OO approach:

$cxn = new mysqli($host, $user, $password);


 echoCreate database test22;


Instead of echo statements (which would just echo the contents to the  
output, i.e., your browser, you want to assign them to a variable,  
such as:


   $sql = create database test22; use test22;

Then you need to execute the sql statement:

$res = $cxn-query($sql);
if (!$res) {
die(Could not create database test22:  . $cxn-error());
}


 echoCreate table Names2


$sql = create table Names2


 (
  RecordNum Int(11) Primary Key Not null default=1
auto_increment,
  FirstName varchar(10),
  LastName varchar(10),
  Height  decimal(4,1),
  Weight0 decimal(4,1),
  BMI decimal(3,1)
  Date0 date
 );


  ; // to close off the php statement
$res = $cxn-query($sql);
if (!$res) {
die(Could not create table Names2:  . $cxn-error());
}



 echo   Create table Visit2


$sql = create table Visit2


 (
  Indx Int(7) Primary Key Not null auto_increment,
  Weight decimal(4,1) not null,
  StudyDate date not null,
  RecordNum Int(11)
 );


; // again, to close off the php statement
$res = $cxn-query($sql);
if (!$res) {
die(Could not create table Visit2:  . $cxn-error());
}



  $sql= SHOW DATABASES;


This doesn't work in a programmatic setting.

Terminate the database connection:

$cxn-close();


 ?
 /body/html



 I would also like to be able to add data to a table, using PHP,  
which I

can do
 in MySQL as:
 load data infile '/home/ethan/Databases/tester21.dat.' replace  
into table
 Names fields escaped by '\\' terminated by '\t'  lines terminated  
by '\n'

;



That's a specific feature of the mysql program. You'd have to write  
something in php to be able to parse the file and insert the data.  
There are examples all over the net. Then you would need to set up sql  
insert or replace statements to actually get the data into the data  
base using mysqli::query. There are numerous examples of this as well.


Here's one example:

?php

$host = localhost;
$user = root;
$pwd = rootpassword;
$db = test22;
$table = table_to_insert_into;

$cxn = new mysql($host, $user, $pwd, $db);

$filename = tab-delimited.txt;
	$contents = file($filename); // returns the contents of the file into  
an array, one line of file per array


	$columns = explode(\t, $contents[0]); // get the column names from  
the first line of the file


$sql = insert into $table set ;
for ($i=1; $icount($contents) ; $i++) {
$data = explode(\t, $contents[$i]);
$j = 0;
foreach ($columns as $column) {
			$insertdata[] = $column=' . $cxn-real_escape_string($data[$j+ 
+]) . '; // this assumes the column names in the tsv file match the  
column names in your data base table exactly. It also assumes that all  
your data are strings, not numerics.

}
$sql .= implode(,,$insertdata);
$res = $cxn-query($sql);
if (!res) die (Error inserting data:  . $cxn-error());
}
?
htmlheadtitleImported data/title/head
body
pData just imported:/p
table border=1 cellpadding=2px cellspacing=2px
thead
tr style=color: white; background-color: black; text-align: center
?

	$res = $cxn-query(select * from $table limit 1); // get one row  
from table for generating column names

if (!res) die (Query failed for table $table:  . $cxn-error());
$row = $res-fetch_assoc();
foreach ($row as $column = $value) {
echo th . $column . /th;
}
?
/tr
/thead
tbody
?

$res = $cxn-query(select * from $table);
if (!res) die (Query failed for table $table:  . $cxn-error());
while ($row = $res-fetch_assoc()) {
echo tr;
foreach ($row as $column = $value) {
echo td . $value . /td;
}
echo /tr\n;
   

Re: [PHP] Questions from a Newbie

2010-10-17 Thread Tamara Temple

gah, i botched that up.

For the first part, you want the following:

$cxn = new mysql($host, $user, $password);
$res = $cxn-query(create database test22:);
if (!$res) {
die(Failed to create database test22:  . $cxn-error());
}

Then, reopen the connection with the new data base:

$cxn = new mysql($host, $user, $password, test22);

Then the following code will work.


Tamara Temple
-- aka tamouse__
tam...@tamaratemple.com


May you never see a stranger's face in the mirror.

On Oct 17, 2010, at 4:26 PM, Tamara Temple wrote:



On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote:

At 01:41 AM 10/17/2010, Tommy Pham wrote:
 I cannot get the following to work.  In my Firefox [Iceweasel]  
browser, I

 enter the following URL: [w/ the http]


Whenever you get a blank screen running a php application, the place  
to look is the http server's error_log. This is frequently found in / 
var/log/httpd/error_log or /var/log/apache2/error_log. (If your  
system is hosted someplace else, it could very easily be in a  
different place). Typically you need root permission to read this  
file. Tail the file after you run your PHP script to see the most  
recent errors.



 The code  contained in the file CreateNew.php is:

 /*
   *  Create Database test22
   */
   htmlbody
 ?php
 $cxn = mysqli_connect($host,$user,$password);


Better to use the OO approach:

$cxn = new mysqli($host, $user, $password);


 echoCreate database test22;


Instead of echo statements (which would just echo the contents to  
the output, i.e., your browser, you want to assign them to a  
variable, such as:


   $sql = create database test22; use test22;

Then you need to execute the sql statement:

$res = $cxn-query($sql);
if (!$res) {
die(Could not create database test22:  . $cxn-error());
}


 echoCreate table Names2


$sql = create table Names2


 (
  RecordNum Int(11) Primary Key Not null default=1
auto_increment,
  FirstName varchar(10),
  LastName varchar(10),
  Height  decimal(4,1),
  Weight0 decimal(4,1),
  BMI decimal(3,1)
  Date0 date
 );


  ; // to close off the php statement
$res = $cxn-query($sql);
if (!$res) {
die(Could not create table Names2:  . $cxn-error());
}



 echo   Create table Visit2


$sql = create table Visit2


 (
  Indx Int(7) Primary Key Not null auto_increment,
  Weight decimal(4,1) not null,
  StudyDate date not null,
  RecordNum Int(11)
 );


; // again, to close off the php statement
$res = $cxn-query($sql);
if (!$res) {
die(Could not create table Visit2:  . $cxn-error());
}



  $sql= SHOW DATABASES;


This doesn't work in a programmatic setting.

Terminate the database connection:

$cxn-close();


 ?
 /body/html



 I would also like to be able to add data to a table, using PHP,  
which I

can do
 in MySQL as:
 load data infile '/home/ethan/Databases/tester21.dat.' replace  
into table
 Names fields escaped by '\\' terminated by '\t'  lines  
terminated by '\n'

;



That's a specific feature of the mysql program. You'd have to write  
something in php to be able to parse the file and insert the data.  
There are examples all over the net. Then you would need to set up  
sql insert or replace statements to actually get the data into the  
data base using mysqli::query. There are numerous examples of this  
as well.


Here's one example:

?php

$host = localhost;
$user = root;
$pwd = rootpassword;
$db = test22;
$table = table_to_insert_into;

$cxn = new mysql($host, $user, $pwd, $db);

$filename = tab-delimited.txt;
	$contents = file($filename); // returns the contents of the file  
into an array, one line of file per array


	$columns = explode(\t, $contents[0]); // get the column names  
from the first line of the file


$sql = insert into $table set ;
for ($i=1; $icount($contents) ; $i++) {
$data = explode(\t, $contents[$i]);
$j = 0;
foreach ($columns as $column) {
			$insertdata[] = $column=' . $cxn-real_escape_string($data[$j+ 
+]) . '; // this assumes the column names in the tsv file match  
the column names in your data base table exactly. It also assumes  
that all your data are strings, not numerics.

}
$sql .= implode(,,$insertdata);
$res = $cxn-query($sql);
if (!res) die (Error inserting data:  . $cxn-error());
}
?
htmlheadtitleImported data/title/head
body
pData just imported:/p
table border=1 cellpadding=2px cellspacing=2px
thead
tr style=color: white; background-color: black; text-align: center
?

	$res = $cxn-query(select * from $table limit 1); // get one row  
from 

Re: [PHP] Questions from a Newbie

2010-10-17 Thread Tommy Pham
On Sun, Oct 17, 2010 at 11:22 AM, Ethan Rosenberg eth...@earthlink.net wrote:



snip


 Tommy -

 Thanks.

 As I stated, I am a newbie.

 1] I am trying to shorten the learning curve by asking some questions, which
 I understand are probably trivial.  A whole MySQLi list of functions at this
 point is to much for me.  I have to break the problem into manageable parts.

 2] It has been my experience that using a GUI does not teach the whole
 subject.  Linux, which is the OS I use cannot be run from a GUI.

 In the code being discussed, I wish to create a database and add two tables.
  I also note a MySQL statement that can be used to add data to an existing
 table, and wish to be able to execute this statement using PHP.

 So, therefore..

 Let us try to answer the following two(2) questions:

 a] What changes [other than moving the simicolons] have to be made to
 correct the code.

That's why I suggested you to read that section regarding the usage of
PHP's MySQL extension.  If you still have problems understanding that
section or if it's a bit too much, I strongly suggest you start
reading the manual from the beginning.  It's obvious you're not very
clear on the syntax of PHP and you jumped right into the middle of
accessing the database and try to manipulate the DB using PHP.

What you need to know is the fundamentals 1st: variable declarations
and assignments, types of variables, basic outputs (such as echo,
print, etc), conditions, loops, etc...  In the official manual, all of
that is covered up to Classes  Objects, not including.  Class 
Objects and there after are for more of PHP5+ and OOP.  When in doubt,
there is always the function reference.


 b] What books can you suggest to help w/ MySQL and PHP?  I already have the
 SQL, MySQL  PHP, and HTML books in the . for Dummies series.  I need
 something with a little more depth and detail.

If you intend to use PHP to access the a DBMS, you need to have a
strong grasp of fundamentals of SQL.  I mean that as beyond  a simple
select statement.  If you already have that and the fundamentals of
PHP, reading that MySQL section I mentioned should give you the
understanding you needed on how to use PHP to access and manipulate
the data from the DB.  One good way to learn to copy the sample codes
from the manual and run it on your development box.   Make some
changes to code after the 1st few runs to see if you're understanding
it correctly and that you should be getting the output from the code
change as you expected based on your understanding of the material you
just read.  Reading any books (hard copy or electronic version) are
good but you won't truly understand and remember how it works unless
you apply that knowledge ASAP, IMO.  Learning for me is reverse
engineering.  That's the fastest way I learn.


 Thanks to all for your excellent help.

 Ethan
 
  Using Debian(sid)
 



Regards,
Tommy

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions from a Newbie

2010-10-17 Thread Paul M Foster
On Sun, Oct 17, 2010 at 01:00:44AM -0400, Ethan Rosenberg wrote:

 Dear List -
 
 Here are some questions, which I am sure are trivial, but I am a
 newbie, and cannot find the answers online
 
 I cannot get the following to work.  In my Firefox [Iceweasel]
 browser, I enter the following URL: [w/ the http]
 
  localhost/CreateNew.php All I get is a blank browser screen.
 
 The code  contained in the file CreateNew.php is:
 
 /*
  *  Create Database test22
  */
  htmlbody
 ?php
 $cxn = mysqli_connect($host,$user,$password);
 echoCreate database test22;
 echoCreate table Names2

There's no need to quote $host above. Why your echo statements aren't
showing up possibly indicates the script is aborting before it gets to
them.

In situations like this, check the error logs if possible. If not, break
the problem down into even smaller chunks. Do your connect with MySQL
and then test to see if the connection actually worked. According to the
docs, mysqli_connect() should return an object representing the
connection. So check that first:

if (!is_object($cxn))
echo Not connected!;
else
echo Yep, it connected!;

 (
 RecordNum Int(11) Primary Key Not null default=1 auto_increment,
 FirstName varchar(10),
 LastName varchar(10),
 Height  decimal(4,1),
 Weight0 decimal(4,1),
 BMI decimal(3,1)
 Date0 date
 );
 

As has been mentioned, you're simply echoing these to the page, not
sending them to MySQL. That won't work. You have to feed your SQL
statements to the mysqli_query() function. See the docs.

Also, let me strongly advise you against using upper-and-lower-case
field names in your tables. Others will undoubtedly disagree, but I find
this a maintenance nightmare in the long run. Note that in some SQL
variants (maybe in MySQL as well; I don't recall), you must quote the
field names in queries to preserve their case and make the queries work.

 echo   Create table Visit2
 (
 Indx Int(7) Primary Key Not null auto_increment,
 Weight decimal(4,1) not null,
 StudyDate date not null,
 RecordNum Int(11)
 );
 
 $sql= SHOW DATABASES;

As mentioned elsewhere, this statement won't work in a web context. It
only works from the MySQL console interface. There are other ways to
achieve this in a programming context, but they involve querying the
MySQL meta-tables. 

Also, to those recommending PHPMyAdmin, it ignores the OP's question,
and doesn't help him/her learn anything. It is completely possible to do
what he wants programmatically, and often is done that way while
installing various frameworks, etc. *You're* welcome to use PHPMyAdmin,
but let the OP do it his/her way, and help them along if you can.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Questions from a Newbie

2010-10-16 Thread Ethan Rosenberg

Dear List -

Here are some questions, which I am sure are trivial, but I am a 
newbie, and cannot find the answers online


I cannot get the following to work.  In my Firefox [Iceweasel] 
browser, I enter the following URL: [w/ the http]


 localhost/CreateNew.php All I get is a blank browser screen.

The code  contained in the file CreateNew.php is:

/*
 *  Create Database test22
 */
 htmlbody
?php
$cxn = mysqli_connect($host,$user,$password);
echoCreate database test22;
echoCreate table Names2
(
RecordNum Int(11) Primary Key Not null default=1 auto_increment,
FirstName varchar(10),
LastName varchar(10),
Height  decimal(4,1),
Weight0 decimal(4,1),
BMI decimal(3,1)
Date0 date
);

echo   Create table Visit2
(
Indx Int(7) Primary Key Not null auto_increment,
Weight decimal(4,1) not null,
StudyDate date not null,
RecordNum Int(11)
);

$sql= SHOW DATABASES;
?
/body/html

If I search for test22 or Visit2, nothing is found.

I would also like to be able to add data to a table, using PHP, which 
I can do in MySQL as:
load data infile '/home/ethan/Databases/tester21.dat.' replace into 
table Names fields escaped by '\\' terminated by '\t'  lines 
terminated by '\n' ;


Thanks in advance.

Ethan
===
Using Debian(sid)  




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Questions from a Newbie

2010-10-16 Thread Tommy Pham
 -Original Message-
 From: Ethan Rosenberg [mailto:eth...@earthlink.net]
 Sent: Saturday, October 16, 2010 10:01 PM
 To: php-general@lists.php.net
 Subject: [PHP] Questions from a Newbie
 
 Dear List -
 
 Here are some questions, which I am sure are trivial, but I am a newbie,
and
 cannot find the answers online
 
 I cannot get the following to work.  In my Firefox [Iceweasel] browser, I
 enter the following URL: [w/ the http]
 
   localhost/CreateNew.php All I get is a blank browser screen.
 
 The code  contained in the file CreateNew.php is:
 
 /*
   *  Create Database test22
   */
   htmlbody
 ?php
 $cxn = mysqli_connect($host,$user,$password);
 echoCreate database test22;
 echoCreate table Names2
 (
  RecordNum Int(11) Primary Key Not null default=1
auto_increment,
  FirstName varchar(10),
  LastName varchar(10),
  Height  decimal(4,1),
  Weight0 decimal(4,1),
  BMI decimal(3,1)
  Date0 date
 );
 
 echo   Create table Visit2
 (
  Indx Int(7) Primary Key Not null auto_increment,
  Weight decimal(4,1) not null,
  StudyDate date not null,
  RecordNum Int(11)
 );
 
  $sql= SHOW DATABASES;
 ?
 /body/html
 
 If I search for test22 or Visit2, nothing is found.
 
 I would also like to be able to add data to a table, using PHP, which I
can do
 in MySQL as:
 load data infile '/home/ethan/Databases/tester21.dat.' replace into table
 Names fields escaped by '\\' terminated by '\t'  lines terminated by '\n'
;
 
 Thanks in advance.
 
 Ethan
 ===
 Using Debian(sid)
 

You're reinventing the wheel that's been rolling along very smoothly for a
long time... Google 'phpmyadmin'.  Also, read this entire section [1].

Regards,
Tommy

[1] http://www.php.net/manual/en/book.mysqli.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about $_SERVER

2010-09-03 Thread tedd

Peter and Paul:

Sorry, I went on vacation for a few days (it was a surprise vacation 
with a 2 day notice).


I think you both understand what I was looking for and found what I 
wanted was not possible. It's just one of those things in life you 
have to live with.


Thanks very much for your time and comment.

Cheers,

tedd
--
---
http://sperling.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about $_SERVER

2010-08-30 Thread Paul M Foster
On Sun, Aug 29, 2010 at 06:04:23PM +0200, Per Jessen wrote:

 Jason Pruim wrote:
 
  My understanding of how shared hosting works would make this near
  impossible... Basically Apache grabs a header that is sent at the
  initial connection which includes the destination hostname and from
  there it translates it to the proper directory on the shared host.
 
  All the IP's though are based off of the parent site's server...
  
  Now with dedicated hosting where you have the entire machine you can
  do what you are looking at because the IP address will always
  translate back to your website.
 
 AFAICT, Tedd was not asking about the server, he's asking about the
 client. 

No, he's talking about the server. But the server he's using may offload
the processing of a script to another machine. So

$_SERVER['SERVER_ADDR'] and $_SERVER['SERVER_NAME']

both relate to the server which the client is originally communicating
with. But he wants to know if he can get the same information about a
different remote server which is processing a script for him. The
problem is that we have:

$_SERVER['REMOTE_ADDR']

but no

$_SERVER['REMOTE_NAME']

So the question is, how would he get that last variable. It becomes
complicated when using a shared hosting environment, because server
names and IPs aren't a 1:1 mapping. An IP may represent numerous actual
site names. This was part or all of the reason why the http protocol was
revised from 1.0 to 1.1-- in order to accommodate all the domains, which
because of the cramped IP space of IPv4, had to share IPs. So in the
HTTP 1.1 protocol, there is additional information passed about the name
of the domain.

Paul


-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about $_SERVER

2010-08-30 Thread Peter Lind
On 30 August 2010 21:32, Paul M Foster pa...@quillandmouse.com wrote:
 On Sun, Aug 29, 2010 at 06:04:23PM +0200, Per Jessen wrote:

 Jason Pruim wrote:

  My understanding of how shared hosting works would make this near
  impossible... Basically Apache grabs a header that is sent at the
  initial connection which includes the destination hostname and from
  there it translates it to the proper directory on the shared host.
 
  All the IP's though are based off of the parent site's server...
 
  Now with dedicated hosting where you have the entire machine you can
  do what you are looking at because the IP address will always
  translate back to your website.

 AFAICT, Tedd was not asking about the server, he's asking about the
 client.

 No, he's talking about the server. But the server he's using may offload
 the processing of a script to another machine. So

 $_SERVER['SERVER_ADDR'] and $_SERVER['SERVER_NAME']

 both relate to the server which the client is originally communicating
 with. But he wants to know if he can get the same information about a
 different remote server which is processing a script for him. The
 problem is that we have:

 $_SERVER['REMOTE_ADDR']

 but no

 $_SERVER['REMOTE_NAME']

 So the question is, how would he get that last variable. It becomes
 complicated when using a shared hosting environment, because server
 names and IPs aren't a 1:1 mapping. An IP may represent numerous actual
 site names. This was part or all of the reason why the http protocol was
 revised from 1.0 to 1.1-- in order to accommodate all the domains, which
 because of the cramped IP space of IPv4, had to share IPs. So in the
 HTTP 1.1 protocol, there is additional information passed about the name
 of the domain.


In the scenario painted, it's explicitly stated that one server acts
as a client in trying to access a resource on another server. Could
you enlighten me as to where the domain name of a client is located in
the request header fields? Here's the RFC for HTTP 1.1
http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.3

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about $_SERVER

2010-08-30 Thread Paul M Foster
On Mon, Aug 30, 2010 at 09:53:46PM +0200, Peter Lind wrote:

 On 30 August 2010 21:32, Paul M Foster pa...@quillandmouse.com wrote:
  On Sun, Aug 29, 2010 at 06:04:23PM +0200, Per Jessen wrote:
 
  Jason Pruim wrote:
 
   My understanding of how shared hosting works would make this near
   impossible... Basically Apache grabs a header that is sent at the
   initial connection which includes the destination hostname and from
   there it translates it to the proper directory on the shared host.
  
   All the IP's though are based off of the parent site's server...
  
   Now with dedicated hosting where you have the entire machine you can
   do what you are looking at because the IP address will always
   translate back to your website.
 
  AFAICT, Tedd was not asking about the server, he's asking about the
  client.
 
  No, he's talking about the server. But the server he's using may offload
  the processing of a script to another machine. So
 
  $_SERVER['SERVER_ADDR'] and $_SERVER['SERVER_NAME']
 
  both relate to the server which the client is originally communicating
  with. But he wants to know if he can get the same information about a
  different remote server which is processing a script for him. The
  problem is that we have:
 
  $_SERVER['REMOTE_ADDR']
 
  but no
 
  $_SERVER['REMOTE_NAME']
 
  So the question is, how would he get that last variable. It becomes
  complicated when using a shared hosting environment, because server
  names and IPs aren't a 1:1 mapping. An IP may represent numerous actual
  site names. This was part or all of the reason why the http protocol was
  revised from 1.0 to 1.1-- in order to accommodate all the domains, which
  because of the cramped IP space of IPv4, had to share IPs. So in the
  HTTP 1.1 protocol, there is additional information passed about the name
  of the domain.
 
 
 In the scenario painted, it's explicitly stated that one server acts
 as a client in trying to access a resource on another server. Could
 you enlighten me as to where the domain name of a client is located in
 the request header fields? Here's the RFC for HTTP 1.1
 http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.3

From http://www8.org/w8-papers/5c-protocols/key/key.html:

=== EXCERPT ===

Internet address conservation

Companies and organizations use URLs to advertise themselves and their
products and services. When a URL appears in a medium other than the Web
itself, people seem to prefer ``pure hostname'' URLs; i.e., URLs without
any path syntax following the hostname. These are often known as
``vanity URLs,'' but in spite of the implied disparagement, it's
unlikely that non-purist users will abandon this practice, which has led
to the continuing creation of huge numbers of hostnames.

IP addresses are widely perceived as a scarce resource (pending the
uncertain transition to IPv6 [DH95]). The Domain Name System (DNS)
allows multiple host names to be bound to the same IP address.
Unfortunately, because the original designers of HTTP did not anticipate
the ``success disaster'' they were enabling, HTTP/1.0 requests do not
pass the hostname part of the request URL. For example, if a user makes
a request for the resource at URL http://example1.org/home.html, the
browser sends a message with the Request-Line

GET /home.html HTTP/1.0

to the server at example1.org. This prevents the binding of another HTTP
server hostname, such as exampleB.org to the same IP address, because
the server receiving such a message cannot tell which server the message
is meant for. Thus, the proliferation of vanity URLs causes a
proliferation of IP address allocations.

The Internet Engineering Steering Group (IESG), which manages the IETF
process, insisted that HTTP/1.1 take steps to improve conservation of IP
addresses. Since HTTP/1.1 had to interoperate with HTTP/1.0, it could
not change the format of the Request-Line to include the server
hostname. Instead, HTTP/1.1 requires requests to include a Host header,
first proposed by John Franks [Fra94], that carries the hostname. This
converts the example above to:

GET /home.html HTTP/1.1
Host: example1.org

If the URL references a port other than the default (TCP port 80), this
is also given in the Host header.

Clearly, since HTTP/1.0 clients will not send Host headers, HTTP/1.1
servers cannot simply reject all messages without them. However, the
HTTP/1.1 specification requires that an HTTP/1.1 server must reject any
HTTP/1.1 message that does not contain a Host header.

The intent of the Host header mechanism, and in particular the
requirement that enforces its presence in HTTP/1.1 requests, is to speed
the transition away from assigning a new IP address for every vanity
URL. However, as long as a substantial fraction of the users on the
Internet use browsers that do not send Host, no Web site operator (such
as an electronic commerce business) that depends on these users will
give up a vanity-URL IP address. The transition, 

Re: [PHP] Questions about $_SERVER

2010-08-30 Thread Peter Lind
On 30 August 2010 22:34, Paul M Foster pa...@quillandmouse.com wrote:
 On Mon, Aug 30, 2010 at 09:53:46PM +0200, Peter Lind wrote:

 On 30 August 2010 21:32, Paul M Foster pa...@quillandmouse.com wrote:
  On Sun, Aug 29, 2010 at 06:04:23PM +0200, Per Jessen wrote:
 
  Jason Pruim wrote:
 
   My understanding of how shared hosting works would make this near
   impossible... Basically Apache grabs a header that is sent at the
   initial connection which includes the destination hostname and from
   there it translates it to the proper directory on the shared host.
  
   All the IP's though are based off of the parent site's server...
  
   Now with dedicated hosting where you have the entire machine you can
   do what you are looking at because the IP address will always
   translate back to your website.
 
  AFAICT, Tedd was not asking about the server, he's asking about the
  client.
 
  No, he's talking about the server. But the server he's using may offload
  the processing of a script to another machine. So
 
  $_SERVER['SERVER_ADDR'] and $_SERVER['SERVER_NAME']
 
  both relate to the server which the client is originally communicating
  with. But he wants to know if he can get the same information about a
  different remote server which is processing a script for him. The
  problem is that we have:
 
  $_SERVER['REMOTE_ADDR']
 
  but no
 
  $_SERVER['REMOTE_NAME']
 
  So the question is, how would he get that last variable. It becomes
  complicated when using a shared hosting environment, because server
  names and IPs aren't a 1:1 mapping. An IP may represent numerous actual
  site names. This was part or all of the reason why the http protocol was
  revised from 1.0 to 1.1-- in order to accommodate all the domains, which
  because of the cramped IP space of IPv4, had to share IPs. So in the
  HTTP 1.1 protocol, there is additional information passed about the name
  of the domain.
 

 In the scenario painted, it's explicitly stated that one server acts
 as a client in trying to access a resource on another server. Could
 you enlighten me as to where the domain name of a client is located in
 the request header fields? Here's the RFC for HTTP 1.1
 http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.3

 From http://www8.org/w8-papers/5c-protocols/key/key.html:

 === EXCERPT ===

 Internet address conservation

 Companies and organizations use URLs to advertise themselves and their
 products and services. When a URL appears in a medium other than the Web
 itself, people seem to prefer ``pure hostname'' URLs; i.e., URLs without
 any path syntax following the hostname. These are often known as
 ``vanity URLs,'' but in spite of the implied disparagement, it's
 unlikely that non-purist users will abandon this practice, which has led
 to the continuing creation of huge numbers of hostnames.

 IP addresses are widely perceived as a scarce resource (pending the
 uncertain transition to IPv6 [DH95]). The Domain Name System (DNS)
 allows multiple host names to be bound to the same IP address.
 Unfortunately, because the original designers of HTTP did not anticipate
 the ``success disaster'' they were enabling, HTTP/1.0 requests do not
 pass the hostname part of the request URL. For example, if a user makes
 a request for the resource at URL http://example1.org/home.html, the
 browser sends a message with the Request-Line

    GET /home.html HTTP/1.0

 to the server at example1.org. This prevents the binding of another HTTP
 server hostname, such as exampleB.org to the same IP address, because
 the server receiving such a message cannot tell which server the message
 is meant for. Thus, the proliferation of vanity URLs causes a
 proliferation of IP address allocations.

 The Internet Engineering Steering Group (IESG), which manages the IETF
 process, insisted that HTTP/1.1 take steps to improve conservation of IP
 addresses. Since HTTP/1.1 had to interoperate with HTTP/1.0, it could
 not change the format of the Request-Line to include the server
 hostname. Instead, HTTP/1.1 requires requests to include a Host header,
 first proposed by John Franks [Fra94], that carries the hostname. This
 converts the example above to:

    GET /home.html HTTP/1.1
            Host: example1.org

 If the URL references a port other than the default (TCP port 80), this
 is also given in the Host header.

 Clearly, since HTTP/1.0 clients will not send Host headers, HTTP/1.1
 servers cannot simply reject all messages without them. However, the
 HTTP/1.1 specification requires that an HTTP/1.1 server must reject any
 HTTP/1.1 message that does not contain a Host header.

 The intent of the Host header mechanism, and in particular the
 requirement that enforces its presence in HTTP/1.1 requests, is to speed
 the transition away from assigning a new IP address for every vanity
 URL. However, as long as a substantial fraction of the users on the
 Internet use browsers that do not send Host, no Web site operator (such
 as an 

Re: [PHP] Questions about $_SERVER

2010-08-30 Thread Paul M Foster
On Mon, Aug 30, 2010 at 10:34:42PM +0200, Peter Lind wrote:

 On 30 August 2010 22:34, Paul M Foster pa...@quillandmouse.com wrote:
  On Mon, Aug 30, 2010 at 09:53:46PM +0200, Peter Lind wrote:
 

snip

   $_SERVER['REMOTE_NAME']
  
   So the question is, how would he get that last variable. It becomes
   complicated when using a shared hosting environment, because server
   names and IPs aren't a 1:1 mapping. An IP may represent numerous actual
   site names. This was part or all of the reason why the http protocol was
   revised from 1.0 to 1.1-- in order to accommodate all the domains, which
   because of the cramped IP space of IPv4, had to share IPs. So in the
   HTTP 1.1 protocol, there is additional information passed about the name
   of the domain.
  
 
  In the scenario painted, it's explicitly stated that one server acts
  as a client in trying to access a resource on another server. Could
  you enlighten me as to where the domain name of a client is located in
  the request header fields? Here's the RFC for HTTP 1.1
  http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.3
 
  From http://www8.org/w8-papers/5c-protocols/key/key.html:

snip

 
  My mistake, though: this change was by no means the only reason for the
  creation of HTTP 1.1
 
 Not only that, it has nothing whatsoever to do with the case at hand.
 The Host header field specifies the domain you're asking a resource
 from, not the the domain of the client. Hence, it cannot be used in
 any fashion to provide identification of the client doing the request,
 which is what Tedd wanted.

Tedd was looking for the server name for the remote server, as seen from
the perspective of the asking server. In his example, he was looking for
a variable which would tell him Slave's name from Master's
perspective. That's why he was asking if there was anything like
$_SERVER['REMOTE_NAME'] as a known PHP server variable.

Of course, you're correct in that the HTTP 1.1 spec I cited wouldn't help
him. I just mentioned it as being of tangential interest.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about $_SERVER

2010-08-30 Thread Paul M Foster
On Mon, Aug 30, 2010 at 05:13:59PM -0400, Paul M Foster wrote:

 On Mon, Aug 30, 2010 at 10:34:42PM +0200, Peter Lind wrote:
 
  On 30 August 2010 22:34, Paul M Foster pa...@quillandmouse.com wrote:
   On Mon, Aug 30, 2010 at 09:53:46PM +0200, Peter Lind wrote:
  
 
 snip
 
$_SERVER['REMOTE_NAME']
   
So the question is, how would he get that last variable. It becomes
complicated when using a shared hosting environment, because server
names and IPs aren't a 1:1 mapping. An IP may represent numerous
 actual
site names. This was part or all of the reason why the http
 protocol was
revised from 1.0 to 1.1-- in order to accommodate all the domains,
 which
because of the cramped IP space of IPv4, had to share IPs. So in the
HTTP 1.1 protocol, there is additional information passed about
 the name
of the domain.
   
  
   In the scenario painted, it's explicitly stated that one server acts
   as a client in trying to access a resource on another server. Could
   you enlighten me as to where the domain name of a client is located in
   the request header fields? Here's the RFC for HTTP 1.1
   http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.3
  
   From http://www8.org/w8-papers/5c-protocols/key/key.html:
 
 snip
 
  
   My mistake, though: this change was by no means the only reason for the
   creation of HTTP 1.1
 
  Not only that, it has nothing whatsoever to do with the case at hand.
  The Host header field specifies the domain you're asking a resource
  from, not the the domain of the client. Hence, it cannot be used in
  any fashion to provide identification of the client doing the request,
  which is what Tedd wanted.
 
 Tedd was looking for the server name for the remote server, as seen from
 the perspective of the asking server. In his example, he was looking for
 a variable which would tell him Slave's name from Master's
 perspective. That's why he was asking if there was anything like
 $_SERVER['REMOTE_NAME'] as a known PHP server variable.

I'm mistaken here. He's looking for the name of the server making the
request, which doesn't appear to be transmitted anywhere.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about $_SERVER

2010-08-29 Thread Jim Lucas

tedd wrote:

At 12:15 AM +0200 8/29/10, Peter Lind wrote:

On 28 August 2010 23:45, tedd tedd.sperl...@gmail.com wrote:

  So, I'm trying to figure out a compliment to 
$_SERVER['SERVER_NAME'] such as

 something like $_SERVER['REMOTE_NAME'].


  Is there such a beast?

You're not making any sense. For the script on your local host to be
able to connect and communicate with the remote host, it would need to
know the name of the remote host. Hence, the local host already knows
the name and has no reason to ask the remote host for a name by which
to contact it.
 That's what I get from your description of the problem. You probably
want to clarify some things.

Regards
Peter


Peter:

Sorry for not making sense. But sometimes you have to confirm the 
players (both server and remote) in communications.


Try this -- place this script on your site:

?php
print_r($_SERVER);
?

You will note that:

[SERVER_NAME] = is the domain name of your site.

Also:

[SERVER_ADDR] = is the IP of your site. If you are on a shared host, 
then it will still be the IP of the main host.


Please note:

[REMOTE_ADDR] = is the IP of the remote server. It *will be* the IP of 
the remote main host regardless of if the requesting script is running 
on the remote main host OR is running under a remote shared host.


Here's an example:

My site http://webbytedd.com is running on a shared host.

The server address reported for this site is: 74.208.162.186

However, if I enter 74.208.162.186 into a browser, I do not arrive at 
webbytedd.com, but instead go to securelayer.com who is my host.


Now, if webbytedd.com was the requesting script, how could the original 
script know what domain name the request came from? As it is now, it can 
only know the main host ID, but not the domain name of the requesting 
script. Does that make my question any clearer?


So my questions basically is -- how can I discover the actual domain 
name of the remote script when it is running on a shared server?


Their is not existing variable (if you would) that your server, when 
connecting to a remote server, would be sending.  So, to have the remote 
end be able to identify the initiating host identity, the initiating 
side would have to add some something to the headers or pass it along in 
the body of the request itself.


What type of service are you trying to create on your server?  And what 
protocol would it be using to connect to the remote server?  If you are 
using cURL, you could add something to the headers before you send the 
request.  But, if you are using something like fopen or 
file_get_contents, you are stuck.  You would not be able to modify the 
headers being sent in the request.


If you are in need of identifying the initial server from the second 
server, then I would suggest using cURL and adding something unique to 
the headers before you send the request to the remote server.


Hope that is clear as mud.



I hope that makes better sense.

Cheers,

tedd




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about $_SERVER

2010-08-29 Thread Peter Lind
On 29 August 2010 08:08, Jim Lucas li...@cmsws.com wrote:

*snip*

 Their is not existing variable (if you would) that your server, when
 connecting to a remote server, would be sending.  So, to have the remote end
 be able to identify the initiating host identity, the initiating side would
 have to add some something to the headers or pass it along in the body of
 the request itself.


+1. Let the requestion script send through identification/authentification.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about $_SERVER

2010-08-29 Thread tedd

At 10:56 AM +0200 8/29/10, Peter Lind wrote:

On 29 August 2010 08:08, Jim Lucas li...@cmsws.com wrote:

*snip*


 Their is not existing variable (if you would) that your server, when
 connecting to a remote server, would be sending.  So, to have the remote end
 be able to identify the initiating host identity, the initiating side would
 have to add some something to the headers or pass it along in the body of
 the request itself.



+1. Let the requestion script send through identification/authentification.

Regards
Peter


To all:

My post about SERVER globals was simply an observation that the 
SERVER global report of host and remote was not symmetric -- for 
example you could obtain both the IP and Domain Name of the host, but 
only the IP of the remote. Sorry for any confusion I may have caused 
in my post.


As to the reason why I was asking, please review my next post, namely 
Secure Communication?


Cheers,

tedd

--
---
http://sperling.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about $_SERVER

2010-08-29 Thread Jason Pruim


On Aug 29, 2010, at 10:55 AM, tedd wrote:


At 10:56 AM +0200 8/29/10, Peter Lind wrote:

On 29 August 2010 08:08, Jim Lucas li...@cmsws.com wrote:

*snip*


Their is not existing variable (if you would) that your server, when
connecting to a remote server, would be sending.  So, to have the  
remote end
be able to identify the initiating host identity, the initiating  
side would
have to add some something to the headers or pass it along in the  
body of

the request itself.



+1. Let the requestion script send through identification/ 
authentification.


Regards
Peter


To all:

My post about SERVER globals was simply an observation that the  
SERVER global report of host and remote was not symmetric -- for  
example you could obtain both the IP and Domain Name of the host,  
but only the IP of the remote. Sorry for any confusion I may have  
caused in my post.


As to the reason why I was asking, please review my next post,  
namely Secure Communication?


Cheers,

tedd



Hey tedd,

My understanding of how shared hosting works would make this near  
impossible... Basically Apache grabs a header that is sent at the  
initial connection which includes the destination hostname and from  
there it translates it to the proper directory on the shared host.


All the IP's though are based off of the parent site's server...

Now with dedicated hosting where you have the entire machine you can  
do what you are looking at because the IP address will always  
translate back to your website.


Now hopefully my understanding of shared hosting isn't flawed but if  
it is I'm sure someone will nicely point out why :)




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about $_SERVER

2010-08-29 Thread tedd

At 11:54 AM -0400 8/29/10, Jason Pruim wrote:

On Aug 29, 2010, at 10:55 AM, tedd wrote:


To all:

My post about SERVER globals was simply an observation that the 
SERVER global report of host and remote was not symmetric -- for 
example you could obtain both the IP and Domain Name of the host, 
but only the IP of the remote. Sorry for any confusion I may have 
caused in my post.



Hey tedd,

My understanding of how shared hosting works would make this near 
impossible... Basically Apache grabs a header that is sent at the 
initial connection which includes the destination hostname and from 
there it translates it to the proper directory on the shared host.


All the IP's though are based off of the parent site's server...

Now with dedicated hosting where you have the entire machine you can 
do what you are looking at because the IP address will always 
translate back to your website.


Now hopefully my understanding of shared hosting isn't flawed but if 
it is I'm sure someone will nicely point out why :)



Your understanding is the same as my understanding.

Cheers,

tedd

--
---
http://sperling.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about $_SERVER

2010-08-29 Thread Per Jessen
Jason Pruim wrote:

 My understanding of how shared hosting works would make this near
 impossible... Basically Apache grabs a header that is sent at the
 initial connection which includes the destination hostname and from
 there it translates it to the proper directory on the shared host.

 All the IP's though are based off of the parent site's server...
 
 Now with dedicated hosting where you have the entire machine you can
 do what you are looking at because the IP address will always
 translate back to your website.

AFAICT, Tedd was not asking about the server, he's asking about the
client. 


-- 
Per Jessen, Zürich (17.2°C)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about $_SERVER

2010-08-29 Thread Peter Lind
On 29 August 2010 18:04, Per Jessen p...@computer.org wrote:
 Jason Pruim wrote:

 My understanding of how shared hosting works would make this near
 impossible... Basically Apache grabs a header that is sent at the
 initial connection which includes the destination hostname and from
 there it translates it to the proper directory on the shared host.

 All the IP's though are based off of the parent site's server...

 Now with dedicated hosting where you have the entire machine you can
 do what you are looking at because the IP address will always
 translate back to your website.


The HTTP protocol does not provide a domain among the request header
fields - you need to implement idenfication/authentication in a
different manner (preferably in a way that does not rely upon IP
addresses, seeing as that doesn't provide any reliable sort of
identification).

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Questions about $_SERVER

2010-08-28 Thread tedd

Hi gang:

The server global:

   $_SERVER['SERVER_ADDR']

Provides the IP of the server where the current script is executing.

And, the server global:

   $_SERVER['REMOTE_ADDR']

Provides the IP of the server executing the script.

As such, you can enter the IP of either into a browser and see that 
specific domain.


However, that doesn't work when you are dealing with shared hosting. 
Doing that will show you to the parent domain, but not the child 
domain (i.e., alias).


So, how can I identify the exact location of the 'server_addr' and of 
the 'remote_addr' on shared hosting? Is that possible?


Thanks,

Cheers,

tedd

--
---
http://sperling.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about $_SERVER

2010-08-28 Thread Per Jessen
tedd wrote:

 Hi gang:
 
 The server global:
 
 $_SERVER['SERVER_ADDR']
 
 Provides the IP of the server where the current script is executing.
 
 And, the server global:
 
 $_SERVER['REMOTE_ADDR']
 
 Provides the IP of the server executing the script.

Yes, aka the client address. 

 As such, you can enter the IP of either into a browser and see that
 specific domain.

Huh?  If my server is 192.168.29.104 and my client is 192.168.29.114, I
might get the default website on the server address, and nothing on the
client (assuming it is not running a webserver).

 However, that doesn't work when you are dealing with shared hosting.
 Doing that will show you to the parent domain, but not the child
 domain (i.e., alias).
 
 So, how can I identify the exact location of the 'server_addr' and of
 the 'remote_addr' on shared hosting? Is that possible?

$_SERVER['SERVER_NAME'] will tell you the name of the virtual host - I
don't know if that is what you're after.



-- 
Per Jessen, Zürich (12.2°C)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about $_SERVER

2010-08-28 Thread tedd

At 9:41 PM +0200 8/28/10, Per Jessen wrote:

tedd wrote:
 

 So, how can I identify the exact location of the 'server_addr' and of
 the 'remote_addr' on shared hosting? Is that possible?


$_SERVER['SERVER_NAME'] will tell you the name of the virtual host - I
don't know if that is what you're after.

--
Per Jessen, Zürich (12.2°C)


Certainly, $_SERVER['SERVER_NAME'] will tell you 
the name of the virtual host, but what about the 
virtual remote?


You see, I can have a script on one server 
communicate with another script on a another 
server and the remote addresses reported on 
either will not translate back to their 
respective virtual hosts, but instead to their 
hosts.


So, I'm trying to figure out a compliment to 
$_SERVER['SERVER_NAME'] such as something like 
$_SERVER['REMOTE_NAME'].


Is there such a beast?

Cheers,

tedd

--
---
http://sperling.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about $_SERVER

2010-08-28 Thread Peter Lind
On 28 August 2010 23:45, tedd tedd.sperl...@gmail.com wrote:
 At 9:41 PM +0200 8/28/10, Per Jessen wrote:

 tedd wrote:
  

  So, how can I identify the exact location of the 'server_addr' and of
  the 'remote_addr' on shared hosting? Is that possible?

 $_SERVER['SERVER_NAME'] will tell you the name of the virtual host - I
 don't know if that is what you're after.

 --
 Per Jessen, Zürich (12.2°C)

 Certainly, $_SERVER['SERVER_NAME'] will tell you the name of the virtual
 host, but what about the virtual remote?

 You see, I can have a script on one server communicate with another script
 on a another server and the remote addresses reported on either will not
 translate back to their respective virtual hosts, but instead to their
 hosts.

 So, I'm trying to figure out a compliment to $_SERVER['SERVER_NAME'] such as
 something like $_SERVER['REMOTE_NAME'].

 Is there such a beast?


You're not making any sense. For the script on your local host to be
able to connect and communicate with the remote host, it would need to
know the name of the remote host. Hence, the local host already knows
the name and has no reason to ask the remote host for a name by which
to contact it.
 That's what I get from your description of the problem. You probably
want to clarify some things.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about $_SERVER

2010-08-28 Thread tedd

At 12:15 AM +0200 8/29/10, Peter Lind wrote:

On 28 August 2010 23:45, tedd tedd.sperl...@gmail.com wrote:

  So, I'm trying to figure out a compliment to 
$_SERVER['SERVER_NAME'] such as

 something like $_SERVER['REMOTE_NAME'].


  Is there such a beast?

You're not making any sense. For the script on your local host to be
able to connect and communicate with the remote host, it would need to
know the name of the remote host. Hence, the local host already knows
the name and has no reason to ask the remote host for a name by which
to contact it.
 That's what I get from your description of the problem. You probably
want to clarify some things.

Regards
Peter


Peter:

Sorry for not making sense. But sometimes you have to confirm the 
players (both server and remote) in communications.


Try this -- place this script on your site:

?php
print_r($_SERVER);
?

You will note that:

[SERVER_NAME] = is the domain name of your site.

Also:

[SERVER_ADDR] = is the IP of your site. If you are on a shared host, 
then it will still be the IP of the main host.


Please note:

[REMOTE_ADDR] = is the IP of the remote server. It *will be* the IP 
of the remote main host regardless of if the requesting script is 
running on the remote main host OR is running under a remote shared 
host.


Here's an example:

My site http://webbytedd.com is running on a shared host.

The server address reported for this site is: 74.208.162.186

However, if I enter 74.208.162.186 into a browser, I do not arrive at 
webbytedd.com, but instead go to securelayer.com who is my host.


Now, if webbytedd.com was the requesting script, how could the 
original script know what domain name the request came from? As it is 
now, it can only know the main host ID, but not the domain name of 
the requesting script. Does that make my question any clearer?


So my questions basically is -- how can I discover the actual domain 
name of the remote script when it is running on a shared server?


I hope that makes better sense.

Cheers,

tedd

--
---
http://sperling.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about $_SERVER

2010-08-28 Thread Tamara Temple
Sorry, forgot to include the mailing list email when I replied to this  
originally...


On Aug 28, 2010, at 8:28 PM, tedd wrote:

Sorry for not making sense. But sometimes you have to confirm the  
players (both server and remote) in communications.


Try this -- place this script on your site:

?php
print_r($_SERVER);
?

You will note that:

[SERVER_NAME] = is the domain name of your site.

Also:

[SERVER_ADDR] = is the IP of your site. If you are on a shared  
host, then it will still be the IP of the main host.


Please note:

[REMOTE_ADDR] = is the IP of the remote server. It *will be* the IP  
of the remote main host regardless of if the requesting script is  
running on the remote main host OR is running under a remote shared  
host.


Here's an example:

My site http://webbytedd.com is running on a shared host.

The server address reported for this site is: 74.208.162.186

However, if I enter 74.208.162.186 into a browser, I do not arrive  
at webbytedd.com, but instead go to securelayer.com who is my host.


Now, if webbytedd.com was the requesting script, how could the  
original script know what domain name the request came from? As it  
is now, it can only know the main host ID, but not the domain name  
of the requesting script. Does that make my question any clearer?


So my questions basically is -- how can I discover the actual domain  
name of the remote script when it is running on a shared server?


I hope that makes better sense.

Cheers,

tedd



I really don't understand what you mean by remote script -- most  
requests are made by clients. REMOTE_ADDR is the IP address of the  
*client* - i.e. the requesting system. It may or may not be a script.  
And it may or may not have an accessible hostname.


Is this a situation where you are establishing a service that is to be  
called by other servers, i.e, some form of API? If not, and if it is a  
case of a browser client calling a PHP script on your server, most  
browser clients aren't running on very useful hostnames for the  
outside world anyway. E.g. the hostname of my mac is paladin.local  
but it obviously can't be called by the outside world by that name.  
Maybe tell us what you are trying to accomplish by knowing the  
hostname of the calling machine? Maybe there's another way.


Are you trying to set up two-way communication between the two  
servers?  Normally, communication is established without regard for  
the calling machine's hostname, because it's going through the  
connection established by the web server. PHP just returns info along  
that connection to the calling machine. It seems you would only need  
to know the requesting system's hostname if you were going to  
establish some other channel of communication with it, i.e., if your  
original script was somehow going to call back the calling machine,  
webbytedd.com to do some other kind of activity. If that *is* what  
you're doing, I can probably guarantee there's a better way to do it.


However, if what you're after is *authenticating* that the requester  
is who they say they are, there are ways to do that as well without  
knowing the requesting host's name (and better than knowing the  
requesting host's name, you can establish authenticity and access  
control for a particular script which is much better than just  
establishing blanket authority for a particular hostname).


However, I'm really reaching here with trying to understand what you  
want to accomplish by knowing the requesting machine's hostname.


So, please, explain what you are trying to do and maybe we can help  
with that.


Tamara


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Really basic PHP questions -- newbie here!

2009-05-21 Thread O. Lavell
Ellen Heitman wrote:

 Hello! I would really appreciate some answers to a few basic questions.
 I have done some research online, but it would greatly help me to get
 direct answers.
 1. If my site needs to be available to many browsers, including those
 that may not be entirely up-to-date, is PHP a safe option? I mean, I
 know that Flash is something people have to have enabled on their
 browsers, but I thought I read that PHP is available to all recent
 browsers as long as the server the site is hosted on supports PHP. Is
 this true?

No, and it's not even wrong, either ;)

PHP is a programming language. You use it to create programs (more 
commonly called scripts) that run on a web server. When a script is 
requested by a browser, the PHP interpreter on the server runs the script 
and only the result is sent back to the browser.

This is a PHP script:

?php
for(i = 0; i  5; i++)
echo pHello world!/p\n;
?

This is what it looks like to the browser:

pHello world!/p
pHello world!/p
pHello world!/p
pHello world!/p
pHello world!/p

There is no need for a browser of any generation to understand PHP, 
because it will never get to see it. Of course, as the PHP programmer you 
must make sure that your scripts' output can be handled by the intended 
clients.

 2. How can I preview my PHP while I'm coding? I'm using TextWrangler. I
 have already followed the installation tutorial here:
 http://foundationphp.com/tutorials/php_leopard.php. The test PHP file
 does work in my Safari browser. However, when I try to preview my .php
 files created in TextWrangler with Safari it doesn't work.

You need to put your PHP files in the web server's home directory, 
probably the same folder where you placed the test file from that 
article, and access them through http. That would look like

http://localhost/yourscript.php

 3. I need something that functions as an iframe. I've been reading that
 include() serves this purpose.

No. Completely different things.

 However, I've found that I have the make
 the content in the iframe the main content and call the things around
 it. I want to do the reverse. I want the other content on the main html
 page in place, and just want to call the text in the frame box. Is this
 doable?

Of course, with include() you can include the content of a file into a 
script file *before* it gets interpreted. But what it looks like in the 
resulting output and whether there is a box or a frame is entirely up to 
you.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Really basic PHP questions -- newbie here!

2009-05-20 Thread Paul M Foster
On Wed, May 20, 2009 at 10:45:07AM -0500, Ellen Heitman wrote:

 Hello! I would really appreciate some answers to a few basic questions. I
 have done some research online, but it would greatly help me to get direct
 answers.
 1. If my site needs to be available to many browsers, including those that
 may not be entirely up-to-date, is PHP a safe option? I mean, I know that
 Flash is something people have to have enabled on their browsers, but I
 thought I read that PHP is available to all recent browsers as long as the
 server the site is hosted on supports PHP. Is this true?

PHP is *server-side* technology, so the browser doesn't matter. The web
server interprets the PHP and sends the result to the browser. That's
why, when you do Show Page Source or Display Page Source on a PHP
page, you won't see any PHP code, even if it's there.

 
 2. How can I preview my PHP while I'm coding? I'm using TextWrangler. I have
 already followed the installation tutorial here:
 http://foundationphp.com/tutorials/php_leopard.php. The test PHP file does
 work in my Safari browser. However, when I try to preview my .php files
 created in TextWrangler with Safari it doesn't work.

TextWrangler is a text *editor*, not a PHP *executor*. The tutorial you
mentioned just sets up your computer so that the Apache web server on it
recognizes PHP code, so as to interpret it.

If you're creating PHP files with TextWrangler, and they're not
displaying properly in Safari, there are a variety of reasons. Are you
putting the files in the right place, according to the tutorial? Are the
permissions on the file correct? Are you putting anything in the files
which would actually echo to the screen? When you say it doesn't work,
what exactly do you mean?


 
 3. I need something that functions as an iframe. I've been reading that
 include() serves this purpose. However, I've found that I have the make the
 content in the iframe the main content and call the things around it. I
 want to do the reverse. I want the other content on the main html page in
 place, and just want to call the text in the frame box. Is this doable?

Frames are a creature of HTML, not PHP. So setting this up is as easy as
configuring your HTML page properly. PHP is generally interspersed with
HTML to do the things that PHP can do and HTML can't.

Your questions indicate you don't understand how PHP works, and the way
PHP integrates with HTML. If you don't have a background in programming
in general, you've got quite a bit of work in front of you. I'd suggest
perusing the shelves of the best bookstore in your area for a PHP book
suitable for your level of understanding.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Really basic PHP questions -- newbie here!

2009-05-20 Thread Lists

Ellen Heitman wrote:

Hello! I would really appreciate some answers to a few basic questions. I
have done some research online, but it would greatly help me to get direct
answers.
1. If my site needs to be available to many browsers, including those that
may not be entirely up-to-date, is PHP a safe option? I mean, I know that
Flash is something people have to have enabled on their browsers, but I
thought I read that PHP is available to all recent browsers as long as the
server the site is hosted on supports PHP. Is this true?

2. How can I preview my PHP while I'm coding? I'm using TextWrangler. I have
already followed the installation tutorial here:
http://foundationphp.com/tutorials/php_leopard.php. The test PHP file does
work in my Safari browser. However, when I try to preview my .php files
created in TextWrangler with Safari it doesn't work.

3. I need something that functions as an iframe. I've been reading that
include() serves this purpose. However, I've found that I have the make the
content in the iframe the main content and call the things around it. I
want to do the reverse. I want the other content on the main html page in
place, and just want to call the text in the frame box. Is this doable?

Any suggestions?

Thanks!



Oh my. :-)

Ellen, respectfully, maybe it is best if you take a class of
some sort?  I think that would give you a great start on
how client-side vs. server-side, and Web Development in general
works. Do have that kind of resource in your area?

Donovan



--
  =o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o
  D. BROOKE   EUCA Design Center
   WebDNA Software Corp.
  WEB: http://www.euca.us  |   http://www.webdna.us
  =o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o
  WebDNA: [** Square Bracket Utopia **]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Really basic PHP questions -- newbie here!

2009-05-20 Thread Ellen Heitman
Hello! I would really appreciate some answers to a few basic questions. I
have done some research online, but it would greatly help me to get direct
answers.
1. If my site needs to be available to many browsers, including those that
may not be entirely up-to-date, is PHP a safe option? I mean, I know that
Flash is something people have to have enabled on their browsers, but I
thought I read that PHP is available to all recent browsers as long as the
server the site is hosted on supports PHP. Is this true?

2. How can I preview my PHP while I'm coding? I'm using TextWrangler. I have
already followed the installation tutorial here:
http://foundationphp.com/tutorials/php_leopard.php. The test PHP file does
work in my Safari browser. However, when I try to preview my .php files
created in TextWrangler with Safari it doesn't work.

3. I need something that functions as an iframe. I've been reading that
include() serves this purpose. However, I've found that I have the make the
content in the iframe the main content and call the things around it. I
want to do the reverse. I want the other content on the main html page in
place, and just want to call the text in the frame box. Is this doable?

Any suggestions?

Thanks!


Re: [PHP] Really basic PHP questions -- newbie here!

2009-05-20 Thread Raymond Irving
Hello Ellen,

I can see that you're new to PHP. You might want to check out this link to get 
some more information on how PHP works and what you need to get started:

http://www.php.net/getting-started
See also http://www.dailybits.com/getting-started-with-php-part-1-hello-world/

__
Raymond Irving
Create Rich Ajax/PHP Web Apps Today!
Raxan PDI - http://raxanpdi.com/



--- On Wed, 5/20/09, Ellen Heitman ellen.heit...@gmail.com wrote:

From: Ellen Heitman ellen.heit...@gmail.com
Subject: [PHP] Really basic PHP questions -- newbie here!
To: php-general@lists.php.net
Date: Wednesday, May 20, 2009, 11:45 AM

Hello! I would really appreciate some answers to a few basic questions. I
have done some research online, but it would greatly help me to get direct
answers.
1. If my site needs to be available to many browsers, including those that
may not be entirely up-to-date, is PHP a safe option? I mean, I know that
Flash is something people have to have enabled on their browsers, but I
thought I read that PHP is available to all recent browsers as long as the
server the site is hosted on supports PHP. Is this true?

2. How can I preview my PHP while I'm coding? I'm using TextWrangler. I have
already followed the installation tutorial here:
http://foundationphp.com/tutorials/php_leopard.php. The test PHP file does
work in my Safari browser. However, when I try to preview my .php files
created in TextWrangler with Safari it doesn't work.

3. I need something that functions as an iframe. I've been reading that
include() serves this purpose. However, I've found that I have the make the
content in the iframe the main content and call the things around it. I
want to do the reverse. I want the other content on the main html page in
place, and just want to call the text in the frame box. Is this doable?

Any suggestions?

Thanks!


Re: [PHP] Really basic PHP questions -- newbie here!

2009-05-20 Thread Lenin
If not following some classes. I'd suggest Ellen to watch the videos for a
quick overview from NETTUTS and KillerPHP.

www.killerphp.com also google for some vidoes.

And you need to understand the facts of  ServerSide, ClientSide, HTML,
WebServer, Permission of Files etc.


Re: [PHP] Questions regarding limits of processes launched by system, exec, passthru ...

2008-09-28 Thread Bastien Koert
On Sat, Sep 27, 2008 at 12:50 PM, Richard Lynch [EMAIL PROTECTED] wrote:

 memory_limit and time_limit are implemented down in the guts of the PHP
 interpreter; They are not magic.

 They can't do diddly when PHP is running some other binary...
 
 From: Thodoris [EMAIL PROTECTED]
 Sent: Saturday, September 27, 2008 8:24 AM
 To: [EMAIL PROTECTED]; php-general@lists.php.net
 Subject: Re: [PHP] Questions regarding limits of processes launched by
 system, exec,passthru ...

  Hello all,
 
  Is there a way to limit the memory consumption and / or the CPU
  consumption of processes launched by the php functions system,
  exec, passthru, proc_open and shell_exec?
 
  We use mod_php with an apache (mpm-prefork) on Linux.
 
  The following settings don't have any effect at all:
  PHP:
max_execution_time 30
memory_limit 8M
  Apache:
RLimitCPU 30 30
RLimitMEM 8388608 8388608
 
  The limits above do have effect on php-scripts (without system calls)
  and on CGIs (as well on processes launched by CGIs).
 
  Any Ideas?
 
  Kind Regards
  valli
 
 
  PS: I tested it with the following two scripts:
  system_memorytest.php
  =
  html
  head
titlephp-systemcall-memory test/title
  /head
  body
php-systemcall-memory testbr
... and here's the system call:br
pre
  ?php
 $cmd = '/usr/bin/perl -e \'
$| = 1;
print start of the systemcallbr\n;
$s = teststr_;
while (1) {
   print len=.length($s).br\n;
   sleep(1);
   $s .= $s;
}
 \'';
 print htmlspecialchars($cmd);
  ?
/pre
  ?php
ob_flush();
flush();
system($cmd);
  ?
  /body
  /html
 
 
  system_timeouttest.php
  ==
  html
  head
titlephp-systemcall-timeout test/title
  /head
  body
php-systemcall-timeout testbr
... and here's the system call:br
pre
  ?php
 $cmd = '/usr/bin/perl -e \'
$| = 1;
print start of the systemcallbr\n;
$i = 0;
while (1) {
   if (($i % 1000) == 0) {
  print i=.$i.br\n;
   }
   $i += 1;
}
 \'';
 print htmlspecialchars($cmd);
  ?
/pre
  ?php
ob_flush();
flush();
system($cmd);
  ?
  /body
  /html
 
 
 
 
 

 Well as far as I know there are already memory limits to every php
 process and you define this in php.ini. I recently made a script that
 used to exhaust all the given memory and I needed to increase the limit.

 memory_limit = 16M

 You can change this to whatever you wish to control.  You can also
 change these if you want to control execution time:

 max_execution_time = 30 ; Maximum execution time of each script, in
 seconds
 max_input_time = 60 ; Maximum amount of time each script may spend
 parsing request data


 I haven't seen a way to control disk access space but I guess there are
 two ways to do that. One is quota the space that php writes in or do
 this by the programming way (meaning that you may check the space before
 you write something).

 As for the CPU I think there are OS specific techniques to control
 resource usage in general but it depends on what *nix system you use
 (FreeBSD, Linux etc).


 
 Thodoris

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


 ___

 The  information in this email or in any file attached
 hereto is intended only for the personal and confiden-
 tial  use  of  the individual or entity to which it is
 addressed and may contain information that is  propri-
 etary  and  confidential.  If you are not the intended
 recipient of this message you are hereby notified that
 any  review, dissemination, distribution or copying of
 this message is strictly prohibited.  This  communica-
 tion  is  for information purposes only and should not
 be regarded as an offer to sell or as  a  solicitation
 of an offer to buy any financial product. Email trans-
 mission cannot be guaranteed to be  secure  or  error-
 free. P6070214

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


Assuming a linux hosted server, see about getting a user created with ulimit
(which limits the resources on calls to system) if you can use that user

-- 

Bastien

Cat, the other other white meat


Re: [PHP] Questions regarding limits of processes launched by system, exec, passthru ...

2008-09-27 Thread Thodoris



Hello all,

Is there a way to limit the memory consumption and / or the CPU
consumption of processes launched by the php functions system,
exec, passthru, proc_open and shell_exec?

We use mod_php with an apache (mpm-prefork) on Linux.

The following settings don't have any effect at all:
PHP:
  max_execution_time 30
  memory_limit 8M
Apache:
  RLimitCPU 30 30
  RLimitMEM 8388608 8388608

The limits above do have effect on php-scripts (without system calls)
and on CGIs (as well on processes launched by CGIs).

Any Ideas?

Kind Regards
valli


PS: I tested it with the following two scripts:
system_memorytest.php
=
html
head
  titlephp-systemcall-memory test/title
/head
body
  php-systemcall-memory testbr
  ... and here's the system call:br
  pre
?php
   $cmd = '/usr/bin/perl -e \'
  $| = 1;
  print start of the systemcallbr\n;
  $s = teststr_;
  while (1) {
 print len=.length($s).br\n;
 sleep(1);
 $s .= $s;
  }
   \'';
   print htmlspecialchars($cmd);
?
  /pre
?php
  ob_flush();
  flush();
  system($cmd);
?
/body
/html


system_timeouttest.php
==
html
head
  titlephp-systemcall-timeout test/title
/head
body
  php-systemcall-timeout testbr
  ... and here's the system call:br
  pre
?php
   $cmd = '/usr/bin/perl -e \'
  $| = 1;
  print start of the systemcallbr\n;
  $i = 0;
  while (1) {
 if (($i % 1000) == 0) {
print i=.$i.br\n;
 }
 $i += 1;
  }
   \'';
   print htmlspecialchars($cmd);
?
  /pre
?php
  ob_flush();
  flush();
  system($cmd);
?
/body
/html




  


Well as far as I know there are already memory limits to every php 
process and you define this in php.ini. I recently made a script that 
used to exhaust all the given memory and I needed to increase the limit.


memory_limit = 16M

You can change this to whatever you wish to control.  You can also 
change these if you want to control execution time:


max_execution_time = 30 ; Maximum execution time of each script, in 
seconds
max_input_time = 60 ; Maximum amount of time each script may spend 
parsing request data



I haven't seen a way to control disk access space but I guess there are 
two ways to do that. One is quota the space that php writes in or do 
this by the programming way (meaning that you may check the space before 
you write something).


As for the CPU I think there are OS specific techniques to control 
resource usage in general but it depends on what *nix system you use 
(FreeBSD, Linux etc).




Thodoris

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions regarding limits of processes launched by system, exec, passthru ...

2008-09-27 Thread Thodoris

O/H Thodoris έγραψε:



Hello all,

Is there a way to limit the memory consumption and / or the CPU
consumption of processes launched by the php functions system,
exec, passthru, proc_open and shell_exec?

We use mod_php with an apache (mpm-prefork) on Linux.

The following settings don't have any effect at all:
PHP:
  max_execution_time 30
  memory_limit 8M
Apache:
  RLimitCPU 30 30
  RLimitMEM 8388608 8388608

The limits above do have effect on php-scripts (without system calls)
and on CGIs (as well on processes launched by CGIs).

Any Ideas?

Kind Regards
valli


PS: I tested it with the following two scripts:
system_memorytest.php
=
html
head
  titlephp-systemcall-memory test/title
/head
body
  php-systemcall-memory testbr
  ... and here's the system call:br
  pre
?php
   $cmd = '/usr/bin/perl -e \'
  $| = 1;
  print start of the systemcallbr\n;
  $s = teststr_;
  while (1) {
 print len=.length($s).br\n;
 sleep(1);
 $s .= $s;
  }
   \'';
   print htmlspecialchars($cmd);
?
  /pre
?php
  ob_flush();
  flush();
  system($cmd);
?
/body
/html


system_timeouttest.php
==
html
head
  titlephp-systemcall-timeout test/title
/head
body
  php-systemcall-timeout testbr
  ... and here's the system call:br
  pre
?php
   $cmd = '/usr/bin/perl -e \'
  $| = 1;
  print start of the systemcallbr\n;
  $i = 0;
  while (1) {
 if (($i % 1000) == 0) {
print i=.$i.br\n;
 }
 $i += 1;
  }
   \'';
   print htmlspecialchars($cmd);
?
  /pre
?php
  ob_flush();
  flush();
  system($cmd);
?
/body
/html




  


Well as far as I know there are already memory limits to every php 
process and you define this in php.ini. I recently made a script that 
used to exhaust all the given memory and I needed to increase the limit.


memory_limit = 16M

You can change this to whatever you wish to control.  You can also 
change these if you want to control execution time:


max_execution_time = 30 ; Maximum execution time of each script, 
in seconds
max_input_time = 60 ; Maximum amount of time each script may spend 
parsing request data



I haven't seen a way to control disk access space but I guess there 
are two ways to do that. One is quota the space that php writes in or 
do this by the programming way (meaning that you may check the space 
before you write something).


As for the CPU I think there are OS specific techniques to control 
resource usage in general but it depends on what *nix system you use 
(FreeBSD, Linux etc).




Thodoris



Sorry for the mistake I misread the original question.

The fact is that if I am correct when you call something using system a 
different process is handling this so you can do this only using the OS. 
In this case php.ini has no effect.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Questions regarding limits of processes launched by system, exec, passthru ...

2008-09-27 Thread Richard Lynch
memory_limit and time_limit are implemented down in the guts of the PHP 
interpreter; They are not magic.

They can't do diddly when PHP is running some other binary...

From: Thodoris [EMAIL PROTECTED]
Sent: Saturday, September 27, 2008 8:24 AM
To: [EMAIL PROTECTED]; php-general@lists.php.net
Subject: Re: [PHP] Questions regarding limits of processes launched by system, 
exec,passthru ...

 Hello all,

 Is there a way to limit the memory consumption and / or the CPU
 consumption of processes launched by the php functions system,
 exec, passthru, proc_open and shell_exec?

 We use mod_php with an apache (mpm-prefork) on Linux.

 The following settings don't have any effect at all:
 PHP:
   max_execution_time 30
   memory_limit 8M
 Apache:
   RLimitCPU 30 30
   RLimitMEM 8388608 8388608

 The limits above do have effect on php-scripts (without system calls)
 and on CGIs (as well on processes launched by CGIs).

 Any Ideas?

 Kind Regards
 valli


 PS: I tested it with the following two scripts:
 system_memorytest.php
 =
 html
 head
   titlephp-systemcall-memory test/title
 /head
 body
   php-systemcall-memory testbr
   ... and here's the system call:br
   pre
 ?php
$cmd = '/usr/bin/perl -e \'
   $| = 1;
   print start of the systemcallbr\n;
   $s = teststr_;
   while (1) {
  print len=.length($s).br\n;
  sleep(1);
  $s .= $s;
   }
\'';
print htmlspecialchars($cmd);
 ?
   /pre
 ?php
   ob_flush();
   flush();
   system($cmd);
 ?
 /body
 /html


 system_timeouttest.php
 ==
 html
 head
   titlephp-systemcall-timeout test/title
 /head
 body
   php-systemcall-timeout testbr
   ... and here's the system call:br
   pre
 ?php
$cmd = '/usr/bin/perl -e \'
   $| = 1;
   print start of the systemcallbr\n;
   $i = 0;
   while (1) {
  if (($i % 1000) == 0) {
 print i=.$i.br\n;
  }
  $i += 1;
   }
\'';
print htmlspecialchars($cmd);
 ?
   /pre
 ?php
   ob_flush();
   flush();
   system($cmd);
 ?
 /body
 /html






Well as far as I know there are already memory limits to every php
process and you define this in php.ini. I recently made a script that
used to exhaust all the given memory and I needed to increase the limit.

memory_limit = 16M

You can change this to whatever you wish to control.  You can also
change these if you want to control execution time:

max_execution_time = 30 ; Maximum execution time of each script, in
seconds
max_input_time = 60 ; Maximum amount of time each script may spend
parsing request data


I haven't seen a way to control disk access space but I guess there are
two ways to do that. One is quota the space that php writes in or do
this by the programming way (meaning that you may check the space before
you write something).

As for the CPU I think there are OS specific techniques to control
resource usage in general but it depends on what *nix system you use
(FreeBSD, Linux etc).



Thodoris

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


___

The  information in this email or in any file attached
hereto is intended only for the personal and confiden-
tial  use  of  the individual or entity to which it is
addressed and may contain information that is  propri-
etary  and  confidential.  If you are not the intended
recipient of this message you are hereby notified that
any  review, dissemination, distribution or copying of
this message is strictly prohibited.  This  communica-
tion  is  for information purposes only and should not
be regarded as an offer to sell or as  a  solicitation
of an offer to buy any financial product. Email trans-
mission cannot be guaranteed to be  secure  or  error-
free. P6070214

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Questions regarding limits of processes launched by system, exec, passthru ...

2008-09-25 Thread Valentin Schmid - ICSurselva AG
Hello all,

Is there a way to limit the memory consumption and / or the CPU
consumption of processes launched by the php functions system,
exec, passthru, proc_open and shell_exec?

We use mod_php with an apache (mpm-prefork) on Linux.

The following settings don't have any effect at all:
PHP:
  max_execution_time 30
  memory_limit 8M
Apache:
  RLimitCPU 30 30
  RLimitMEM 8388608 8388608

The limits above do have effect on php-scripts (without system calls)
and on CGIs (as well on processes launched by CGIs).

Any Ideas?

Kind Regards
valli


PS: I tested it with the following two scripts:
system_memorytest.php
=
html
head
  titlephp-systemcall-memory test/title
/head
body
  php-systemcall-memory testbr
  ... and here's the system call:br
  pre
?php
   $cmd = '/usr/bin/perl -e \'
  $| = 1;
  print start of the systemcallbr\n;
  $s = teststr_;
  while (1) {
 print len=.length($s).br\n;
 sleep(1);
 $s .= $s;
  }
   \'';
   print htmlspecialchars($cmd);
?
  /pre
?php
  ob_flush();
  flush();
  system($cmd);
?
/body
/html


system_timeouttest.php
==
html
head
  titlephp-systemcall-timeout test/title
/head
body
  php-systemcall-timeout testbr
  ... and here's the system call:br
  pre
?php
   $cmd = '/usr/bin/perl -e \'
  $| = 1;
  print start of the systemcallbr\n;
  $i = 0;
  while (1) {
 if (($i % 1000) == 0) {
print i=.$i.br\n;
 }
 $i += 1;
  }
   \'';
   print htmlspecialchars($cmd);
?
  /pre
?php
  ob_flush();
  flush();
  system($cmd);
?
/body
/html




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Questions regarding limits of processes launched by system, exec, passthru ...

2008-09-25 Thread Richard Lynch
 -Original Message-
 Is there a way to limit the memory consumption and / or the CPU
 consumption of processes launched by the php functions system,
 exec, passthru, proc_open and shell_exec?

I suspect...

PHP pretty much releases control to the shell or whatever, and just waits 
around for it to finish.

You'll have to put limits into the called processes, I think

I could be wrong.



___

The  information in this email or in any file attached
hereto is intended only for the personal and confiden-
tial  use  of  the individual or entity to which it is
addressed and may contain information that is  propri-
etary  and  confidential.  If you are not the intended
recipient of this message you are hereby notified that
any  review, dissemination, distribution or copying of
this message is strictly prohibited.  This  communica-
tion  is  for information purposes only and should not
be regarded as an offer to sell or as  a  solicitation
of an offer to buy any financial product. Email trans-
mission cannot be guaranteed to be  secure  or  error-
free. P6070214


Re: [PHP] Questions regarding limits of processes launched by system, exec, passthru ...

2008-09-25 Thread Daniel Brown
On Thu, Sep 25, 2008 at 4:28 AM, Valentin Schmid - ICSurselva AG
[EMAIL PROTECTED] wrote:
 Hello all,

 Is there a way to limit the memory consumption and / or the CPU
 consumption of processes launched by the php functions system,
 exec, passthru, proc_open and shell_exec?

Since you're working on a *NIX system, check out PHP's pcntl_*
functions[1] and the *NIX `nice` function[2].

1: http://www.php.net/manual/en/ref.pcntl.php
2: http://www.manpagez.com/man/1/nice/

-- 
/Daniel P. Brown
More full-root dedicated server packages:
Intel 2.4GHz/60GB/512MB/2TB $49.99/mo.
Intel 3.06GHz/80GB/1GB/2TB $59.99/mo.
Intel 2.4GHz/320/GB/1GB/3TB $74.99/mo.
Dedicated servers, VPS, and hosting from $2.50/mo.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Questions about finding ranges

2008-07-24 Thread Aslan
You guys are just awesome! Thanks already for the help I really 
appreciate it!


My site is up on adslgeek.com/troubleshooter but I have a DNS problem 
that I have to fix over the weekend. :-(


The scenario is an input dashboard, with various settings that measure 
the quality of an ADSL line.
I have then mapped out all of the possible faults that I could think of 
that might fit those settings(did up a flowchart of questions that is huge).


So  for simplicity say the inputs are:
- X Noise on line
- X Distance from exchange
- X Disconnections per day
- Slow speed of x

Then I have a list of all the possible scenarios eg
1) Disconnections caused by noisy line 
2) Disconnections caused by distance

3) Slow due to noisey line
4) Slow due to distance

So how I have currently done this is heaps of nested if statements, but 
that is going to get so unmanageable, and the speed is going to become a 
factor.


What I had envisioned was input all the possible vars, and then SQL just 
finds the closest variable. It is kind of similar in logic to a search 
engine type script - if I had the strings disconnections and noisey 
of 52 then it just finds the closest record.


Does that make sense? Thanks heaps you guys have been so helpful.

Cheers,
Aslan

Micah Gersten wrote:

Here's the info on the weirdness of between:
http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_between

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com
  



VamVan wrote:

Hey,

For ranges you can also use Between in the mysql queries.

SELECT * FROM table WHERE Type= Attainable AND Min LIKE $var can be
written as

Select * from table where between min and max

Just remember that between acts a bit wierd with dates or else Jim's
solution would be perfect for you.

Thanks



On Wed, Jul 23, 2008 at 7:58 AM, Jim Lucas [EMAIL PROTECTED] wrote:

  

Aslan wrote:



Hey there,

I have a range of records that represent different faults and different
symptoms that I want to pull out of the database, and to find the records
that are the closest within each range.

I am currently doing it with a barrage of if statements, but I am sure
that this could be done faster and far more elegantly by using SQL

I have a range of conditions eg
Attainable rates:
0-500 KB/sec is very poor
500 - 1000 is marginal
1000- 3000 KB/sec is good

So the database may look like:
Type|Min|Max|Value
Attainable|0|500| This rate is very poor

and then SQL could go something like

SELECT * FROM table WHERE Type= Attainable AND Min LIKE $var


  

You're close, try this

SELECT   *
FROM table
WHEREType = Attainable
 ANDMin = $var
 ANDMax = $var


as long as your min and max do not overlap from row to row, you should only
get one result.  Make sure in your data that you have no overlap.

Row 1 =0 -  499
Row 2 =  500 -  999
Row 3 = 1000 - 1499




But that wouldn't work quite right I don't think.

But where it can get a bit more hairy is that I want to have a whole range
of variables that are input from an entry table, and then it just finds the
the vars that are the closest to what is searching for all the vars. The
closest code I have seen doing something similar is where there it is
finding if an IP is in a certain range.

Does that make sense? feel free to email me if you need more explanation.

It is kind of like a multi variable search engine, that is finding the
root cause of the symptoms that are the very best fit given the
multi-variables...

Thanks heaps for any assistance,
Aslan.



  

--
Jim Lucas

  Some men are born to greatness, some achieve greatness,
  and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
   by William Shakespeare



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





  



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



  1   2   >