php-general Digest 31 Oct 2008 10:47:38 -0000 Issue 5765
Topics (messages 282673 through 282693):
Sessions in object oriented code
282673 by: Ben Stones
282674 by: Yeti
282675 by: Ben Stones
282682 by: Ashley Sheridan
282686 by: Yeti
Re: PreReq Index
282676 by: Craige Leeder
Re: Mailing lists
282677 by: Robert Cummings
282678 by: Daniel P. Brown
282679 by: Shawn McKenzie
282680 by: Robert Cummings
282681 by: Ashley Sheridan
282683 by: Lupus Michaelis
282688 by: Richard Heyes
282689 by: Richard Heyes
282690 by: Richard Heyes
Invalid byte sequence for encoding UTF-8
282684 by: paragasu
282685 by: Lester Caine
282691 by: paragasu
Re: DOCTYPE, javascript and Firefox
282687 by: Ross McKay
282692 by: Arno Kuhl
VAT number validation
282693 by: Koenraad Vanden Daele
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
Hi,
Hope I can explain this as easily as possible, basically I am using both
cookies and sessions for my script, whereby the user is allowed to choose
which method they want to login with. Problem for me is removing the
registration form, etc., from those that are logged in. The thing is the
form is in its own method in a seperate file, and its called within HTML
code so obviously if I included session_start() in the seperate include file
where the methods/classes are, etc., I'd get a "headers already sent" error.
So is there a solution to this?
Thanks.
--- End Message ---
--- Begin Message ---
OK I guess it's somehow like this ..
<form>
<?php
if (isset($_POST['submit'])) {
include('sessions.php');
// include sessions.php
}
?>
<!-- form innerhtml -->
</form>
now this of course is something very bad to do and it wont work.
One way to prevent markup from being outputted is using ob_buffer() [1]
EXAMPLE:
<?php
$form = <<<FORM
<form>
<!-- form inner xml -->
</form>
FORM;
ob_start();
echo $form;
$output_buffer = ob_get_contents();
ob_end_clean();
var_dump(nl2br(htmlentities($output_buffer)));
?>
So what we do here is simply start the output buffer befor echoing $form.
ob_get_contents() returns the outputbuffer as it is right now.
By calling ob_end_clean() buffering is stopped and the buffer cache released.
Still keep in mind that headers will still be sent when buffering the output.
here is a more complex
EXAMPLE:
<?php
ob_start(); // starting the output buffer
?>
<html>
<body>
<!-- inner xml -->
{{replace_me}}
</body>
</html>
<?php
$output_buffer = ob_get_contents();
ob_end_clean();
session_start();
$_SESSION['test'] = time();
echo str_replace('{{replace_me}}', '<p>This is the replaced string.<br
/>SESSION[test] was set to: '.$_SESSION['test'].'</p>',
$output_buffer);
?>
Now we start the output buffer at the beginning of the script and the
session at the end.
It does not matter whether we close the PHP tag after starting the
ob_buffer. ( like with ?> )
As long as we do not flush_end or clean_end the output buffering
process it will continue caching the output (except headers).
So session_start should work after actually "outputting" markup.
Another method could be like we did above the str_replace() [2] ...
EXAMPLE:
<?php
$some_number = time();
$html = <<<HTML
<html>
<body>
<p>Time: $some_number</p>
<p>{{replace_me}}</p>
</body>
</html>
HTML;
echo str_replace('{{replace_me}}', 'This string was changed by PHP', $html);
?>
There is still plenty of other possible solutions. Keep on rocking
[1] http://in.php.net/manual/en/ref.outcontrol.php
[2] http://in.php.net/manual/en/function.str-replace.php
//A yeti
--- End Message ---
--- Begin Message ---
Hi,
I can't really understand that. Not sure if you understand my problem
properly (if I've not explained properly). Anyone can give me some solutions
please?
Thanks.
2008/10/31 Yeti <[EMAIL PROTECTED]>
> OK I guess it's somehow like this ..
>
> <form>
> <?php
> if (isset($_POST['submit'])) {
> include('sessions.php');
> // include sessions.php
> }
> ?>
> <!-- form innerhtml -->
> </form>
>
> now this of course is something very bad to do and it wont work.
> One way to prevent markup from being outputted is using ob_buffer() [1]
>
> EXAMPLE:
> <?php
> $form = <<<FORM
> <form>
> <!-- form inner xml -->
> </form>
> FORM;
> ob_start();
> echo $form;
> $output_buffer = ob_get_contents();
> ob_end_clean();
> var_dump(nl2br(htmlentities($output_buffer)));
> ?>
>
> So what we do here is simply start the output buffer befor echoing $form.
> ob_get_contents() returns the outputbuffer as it is right now.
> By calling ob_end_clean() buffering is stopped and the buffer cache
> released.
> Still keep in mind that headers will still be sent when buffering the
> output.
>
> here is a more complex
> EXAMPLE:
> <?php
> ob_start(); // starting the output buffer
> ?>
> <html>
> <body>
> <!-- inner xml -->
> {{replace_me}}
> </body>
> </html>
> <?php
> $output_buffer = ob_get_contents();
> ob_end_clean();
> session_start();
> $_SESSION['test'] = time();
> echo str_replace('{{replace_me}}', '<p>This is the replaced string.<br
> />SESSION[test] was set to: '.$_SESSION['test'].'</p>',
> $output_buffer);
> ?>
>
> Now we start the output buffer at the beginning of the script and the
> session at the end.
> It does not matter whether we close the PHP tag after starting the
> ob_buffer. ( like with ?> )
> As long as we do not flush_end or clean_end the output buffering
> process it will continue caching the output (except headers).
> So session_start should work after actually "outputting" markup.
>
> Another method could be like we did above the str_replace() [2] ...
>
> EXAMPLE:
> <?php
> $some_number = time();
> $html = <<<HTML
> <html>
> <body>
> <p>Time: $some_number</p>
> <p>{{replace_me}}</p>
> </body>
> </html>
> HTML;
> echo str_replace('{{replace_me}}', 'This string was changed by PHP',
> $html);
> ?>
>
> There is still plenty of other possible solutions. Keep on rocking
>
> [1] http://in.php.net/manual/en/ref.outcontrol.php
> [2] http://in.php.net/manual/en/function.str-replace.php
>
> //A yeti
>
--- End Message ---
--- Begin Message ---
On Fri, 2008-10-31 at 00:33 +0000, Ben Stones wrote:
> Hi,
>
> I can't really understand that. Not sure if you understand my problem
> properly (if I've not explained properly). Anyone can give me some solutions
> please?
>
> Thanks.
>
> 2008/10/31 Yeti <[EMAIL PROTECTED]>
>
> > OK I guess it's somehow like this ..
> >
> > <form>
> > <?php
> > if (isset($_POST['submit'])) {
> > include('sessions.php');
> > // include sessions.php
> > }
> > ?>
> > <!-- form innerhtml -->
> > </form>
> >
> > now this of course is something very bad to do and it wont work.
> > One way to prevent markup from being outputted is using ob_buffer() [1]
> >
> > EXAMPLE:
> > <?php
> > $form = <<<FORM
> > <form>
> > <!-- form inner xml -->
> > </form>
> > FORM;
> > ob_start();
> > echo $form;
> > $output_buffer = ob_get_contents();
> > ob_end_clean();
> > var_dump(nl2br(htmlentities($output_buffer)));
> > ?>
> >
> > So what we do here is simply start the output buffer befor echoing $form.
> > ob_get_contents() returns the outputbuffer as it is right now.
> > By calling ob_end_clean() buffering is stopped and the buffer cache
> > released.
> > Still keep in mind that headers will still be sent when buffering the
> > output.
> >
> > here is a more complex
> > EXAMPLE:
> > <?php
> > ob_start(); // starting the output buffer
> > ?>
> > <html>
> > <body>
> > <!-- inner xml -->
> > {{replace_me}}
> > </body>
> > </html>
> > <?php
> > $output_buffer = ob_get_contents();
> > ob_end_clean();
> > session_start();
> > $_SESSION['test'] = time();
> > echo str_replace('{{replace_me}}', '<p>This is the replaced string.<br
> > />SESSION[test] was set to: '.$_SESSION['test'].'</p>',
> > $output_buffer);
> > ?>
> >
> > Now we start the output buffer at the beginning of the script and the
> > session at the end.
> > It does not matter whether we close the PHP tag after starting the
> > ob_buffer. ( like with ?> )
> > As long as we do not flush_end or clean_end the output buffering
> > process it will continue caching the output (except headers).
> > So session_start should work after actually "outputting" markup.
> >
> > Another method could be like we did above the str_replace() [2] ...
> >
> > EXAMPLE:
> > <?php
> > $some_number = time();
> > $html = <<<HTML
> > <html>
> > <body>
> > <p>Time: $some_number</p>
> > <p>{{replace_me}}</p>
> > </body>
> > </html>
> > HTML;
> > echo str_replace('{{replace_me}}', 'This string was changed by PHP',
> > $html);
> > ?>
> >
> > There is still plenty of other possible solutions. Keep on rocking
> >
> > [1] http://in.php.net/manual/en/ref.outcontrol.php
> > [2] http://in.php.net/manual/en/function.str-replace.php
> >
> > //A yeti
> >
How are you currently including the external file that has the
session_start() call? What I always do is have a basic config include
that contains only code that should have no output, like config
variables, database connections, and the session initiation. As sessions
rely (in general but not always) on cookies, then you should be calling
them both at once, as the only way to create a cookie after the headers
have been sent is with the use of javascript, which shouldn't be relied
on for something as fundamental as what you are trying to do.
As long as you have no output prior to the session_start() call (and
that means not even a single space) then you should be fine, no matter
whether the call is made from an include file or not.
If this still is no help, maybe you can give us a code excerpt so that
we can see what is the problem?
Ash
www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
> I can't really understand that. Not sure if you understand my problem
> properly (if I've not explained properly). Anyone can give me some solutions
> please?
Well as long as you don not provide any code it's all just wild guesses.
What I tried was to show you a way of simply preventing the HTML from
being sent to the browser before you include the session and/or cookie
file. So you would just have to add the output buffering syntax to
your existing code without changing all the scripts.
--- End Message ---
--- Begin Message ---
I forgot to mention, the calls to setPreReq() would occur in each file
in place of an include() to get prerequisite components. IE:
html.php :
Ember::setPrereq( array('iOutput' => Ember::mciInterface) );
class html implements iOutput {
...
}
iOutput.php:
Ember::setPrereq( array('iIO' => Ember::mciInterface) );
interface iOutput implements iIO {
...
}
iIO.php:
interface iIO {
}
--- End Message ---
--- Begin Message ---
On Thu, 2008-10-30 at 15:48 -0500, Daniel P. Brown wrote:
> On Thu, Oct 30, 2008 at 3:44 PM, Ashley Sheridan
> <[EMAIL PROTECTED]> wrote:
> >
> > Called English for a reason you Yank ;)
>
> Hey, my forefathers, foremothers, fore-aunts and -uncles, et
> cetera, didn't spend the last two-hundred-thirty-two years butchering
> the language just for you to correct us, Sheridan! If you guys had
> gotten it right in the first place, we wouldn't have had to improve
> it! ;-P
Says the guy who's ancenstors also threw a King's ransom in tea into a
harbour... most people in the world call that idiocy... but then, didn't
your government just recently hand out a King's ransom to shoddy
businesses that got themselves into a spot of trouble over questionable
lending practices... some descendents never learn from their
forefathers' and mothers' mistakes.
;D
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
On Thu, Oct 30, 2008 at 8:57 PM, Robert Cummings <[EMAIL PROTECTED]> wrote:
>
> Says the guy who's ancenstors also threw a King's ransom in tea into a
> harbour... most people in the world call that idiocy... but then, didn't
> your government just recently hand out a King's ransom to shoddy
> businesses that got themselves into a spot of trouble over questionable
> lending practices... some descendents never learn from their
> forefathers' and mothers' mistakes.
.... chimes in the guy who has yet to give me his wife's shortbread recipe!
--
</Daniel P. Brown>
http://www.parasane.net/
[EMAIL PROTECTED] || [EMAIL PROTECTED]
Ask me about our current hosting/dedicated server deals!
--- End Message ---
--- Begin Message ---
Robert Cummings wrote:
> On Thu, 2008-10-30 at 15:48 -0500, Daniel P. Brown wrote:
>> On Thu, Oct 30, 2008 at 3:44 PM, Ashley Sheridan
>> <[EMAIL PROTECTED]> wrote:
>>> Called English for a reason you Yank ;)
>> Hey, my forefathers, foremothers, fore-aunts and -uncles, et
>> cetera, didn't spend the last two-hundred-thirty-two years butchering
>> the language just for you to correct us, Sheridan! If you guys had
>> gotten it right in the first place, we wouldn't have had to improve
>> it! ;-P
>
> Says the guy who's ancenstors also threw a King's ransom in tea into a
> harbour... most people in the world call that idiocy... but then, didn't
> your government just recently hand out a King's ransom to shoddy
> businesses that got themselves into a spot of trouble over questionable
> lending practices... some descendents never learn from their
> forefathers' and mothers' mistakes.
>
> ;D
>
> Cheers,
> Rob.
Yeah, at least we elected them... Oh wait...
--
Thanks!
-Shawn
http://www.spidean.com
--- End Message ---
--- Begin Message ---
On Thu, 2008-10-30 at 21:07 -0400, Daniel P. Brown wrote:
> On Thu, Oct 30, 2008 at 8:57 PM, Robert Cummings <[EMAIL PROTECTED]> wrote:
> >
> > Says the guy who's ancenstors also threw a King's ransom in tea into a
> > harbour... most people in the world call that idiocy... but then, didn't
> > your government just recently hand out a King's ransom to shoddy
> > businesses that got themselves into a spot of trouble over questionable
> > lending practices... some descendents never learn from their
> > forefathers' and mothers' mistakes.
>
> .... chimes in the guy who has yet to give me his wife's shortbread
> recipe!
Hmmpff.. I'll try and remember... there's a large divide between my desk
and the rest of reality.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
On Thu, 2008-10-30 at 21:36 -0400, Robert Cummings wrote:
> On Thu, 2008-10-30 at 21:07 -0400, Daniel P. Brown wrote:
> > On Thu, Oct 30, 2008 at 8:57 PM, Robert Cummings <[EMAIL PROTECTED]> wrote:
> > >
> > > Says the guy who's ancenstors also threw a King's ransom in tea into a
> > > harbour... most people in the world call that idiocy... but then, didn't
> > > your government just recently hand out a King's ransom to shoddy
> > > businesses that got themselves into a spot of trouble over questionable
> > > lending practices... some descendents never learn from their
> > > forefathers' and mothers' mistakes.
> >
> > .... chimes in the guy who has yet to give me his wife's shortbread
> > recipe!
>
> Hmmpff.. I'll try and remember... there's a large divide between my desk
> and the rest of reality.
>
> Cheers,
> Rob.
> --
> http://www.interjinn.com
> Application and Templating Framework for PHP
>
>
Sounds like my world, but substitute desk for head...
Ash
www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
Daniel Brown a écrit :
On Thu, Oct 30, 2008 at 3:06 PM, Richard Heyes <[EMAIL PROTECTED]> wrote:
Pink isn't my colour...
And there's no 'U' in 'color' either, you limey! ;-P
It depends on what english your are using, isn't it ?
--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org
--- End Message ---
--- Begin Message ---
> It depends on what english your are using, isn't it ?
Well I suppose there's real English, and then American English.
--
Richard Heyes
HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated October 25th)
--- End Message ---
--- Begin Message ---
> Hmmpff.. I'll try and remember... there's a large divide between my desk
> and the rest of reality.
You could say about a lot of peoples desks... :-)
--
Richard Heyes
HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated October 25th)
--- End Message ---
--- Begin Message ---
> we wouldn't have had to improve
> it! ;-P
Improuve? Thaut's nout whaut Iu'd caull iut...
--
Richard Heyes
HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated October 25th)
--- End Message ---
--- Begin Message ---
i am using php with postgresql. when i submit post query to the
server. i have the pg_exec error
<snip>
Warning: pg_query() [function.pg-query]: Query failed: ERROR: invalid
byte sequence for encoding "UTF8": 0x93 HINT: This error can also
happen if the byte sequence does not match the encoding expected by
the server, which is controlled by "client_encoding".
</snip>
is there any function to prevent this type of error. something i can
apply to any POST query
before i submit to pg_query() ?
thanks you.
--- End Message ---
--- Begin Message ---
paragasu wrote:
i am using php with postgresql. when i submit post query to the
server. i have the pg_exec error
<snip>
Warning: pg_query() [function.pg-query]: Query failed: ERROR: invalid
byte sequence for encoding "UTF8": 0x93 HINT: This error can also
happen if the byte sequence does not match the encoding expected by
the server, which is controlled by "client_encoding".
</snip>
is there any function to prevent this type of error. something i can
apply to any POST query
before i submit to pg_query() ?
You probably need to tell us which functions you are using to create/modify
the UTF8 string that you are sending as data. I does sound like a conversion
TO UTF8 is not being carried out somewhere. PHP5 requires that only multi-byte
string functions are used to handle UTF8 data
--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/lsces/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php
--- End Message ---
--- Begin Message ---
i do not use any function other that addslashes on the $_POST
On 10/30/08, Lester Caine <[EMAIL PROTECTED]> wrote:
> paragasu wrote:
>> i am using php with postgresql. when i submit post query to the
>> server. i have the pg_exec error
>> <snip>
>> Warning: pg_query() [function.pg-query]: Query failed: ERROR: invalid
>> byte sequence for encoding "UTF8": 0x93 HINT: This error can also
>> happen if the byte sequence does not match the encoding expected by
>> the server, which is controlled by "client_encoding".
>> </snip>
>> is there any function to prevent this type of error. something i can
>> apply to any POST query
>> before i submit to pg_query() ?
>
> You probably need to tell us which functions you are using to create/modify
> the UTF8 string that you are sending as data. I does sound like a conversion
> TO UTF8 is not being carried out somewhere. PHP5 requires that only
> multi-byte
> string functions are used to handle UTF8 data
>
> --
> Lester Caine - G8HFL
> -----------------------------
> Contact - http://lsces.co.uk/lsces/wiki/?page=contact
> L.S.Caine Electronic Services - http://lsces.co.uk
> EnquirySolve - http://enquirysolve.com/
> Model Engineers Digital Workshop - http://medw.co.uk//
> Firebird - http://www.firebirdsql.org/index.php
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
On Thu, 30 Oct 2008 15:45:55 +0200, Arno Kuhl wrote:
>[...]
>This code works fine in IE, Opera and Chrome, but gives a javascript error
>in FF when I click the radio button: "autostartlabel is not defined".
>However if I comment out the DOCTYPE line in the header it works fine in all
>browsers including FF. (Took ages to narrow it down to the DOCTYPE.) Does
>anyone know why, and how to fix it?
You aren't doing it the DOM way, and telling FF3 to use HTML 4.01 (or
XHTML) means you should be doing it the DOM way. IE, Opera and Chrome
are being lax; FF isn't.
<input type='radio' name='autostart' value='0'
onclick="document.getElementById('autostartlabel').className='disable';
document.getElementById('startdate').disabled=true;" >No
<input type='radio' name='autostart' value='1'
onclick="document.getElementById('autostartlabel').className='normal';
document.getElementById('startdate').disabled=false;" >Yes
<label id='autostartlabel'>Startdate</label>
<input type='text' name='startdate' id='startdate' disabled='disabled' >
Better would be to throw the actions into a function, e.g.
<script type="text/javascript">
function setStartDateDisabled(asDisabled) {
var autostartlabel = document.getElementById('autostartlabel');
if (autostartlabel)
autostartlabel.className = asDisabled ? 'disable' : 'normal';
var startdate = document.getElementById('startdate');
if (startdate)
startdate.disabled = asDisabled;
}
</script>
<input type='radio' name='autostart' id='autostart_0' value='0'
onclick="setStartDateDisabled(true);" >No
<input type='radio' name='autostart' id='autostart_1' value='1'
onclick="setStartDateDisabled(false);" >Yes
PS: pick HTML4 or XHTML; your sample code shows the latter, the DOCTYPE
says the former.
--
Ross McKay, Toronto, NSW Australia
"The lawn could stand another mowing; funny, I don't even care"
- Elvis Costello
--- End Message ---
--- Begin Message ---
-----Original Message-----
From: Andrew Ballard [mailto:[EMAIL PROTECTED]
Sent: 30 October 2008 05:15 PM
To: [EMAIL PROTECTED]
Cc: PHP - General
Subject: Re: [PHP] DOCTYPE, javascript and Firefox
The pragmatic approach says that you've already fixed it: just leave
the DOCTYPE out. :-)
I'm not sure what yours should be, but based on the snippet of HTML
you posted, yours should not be HTML 4.01. Since you are closing the
<input/> tags, you should probably be using one of the XHTML DOCTYPEs
(as long as the rest of your markup is consistent). I'm not sure that
would "fix" your issue, though.
As for why your page does that, I'm not really sure. If you leave the
DOCTYPE off the the browser will select the DOCTYPE it wants to use.
Perhaps since you declared the document to be HTML 4.01 Transitional,
Firefox is applying JavaScript rules where you can't refer to an
element in script simply using its ID attribute. You usually have to
use something like:
document.getElementById('autostartlabel').className = 'disable';
Andrew
--
Hi Andrew and Ross, thanks a lot - using getElementById sorted it out. As
for the DOCTYPE the scripts aren't consistent enough yet to use one of the
XHTML DOCTYPEs, but it's work in progress. Maybe starting that process
caused the problem because I remember testing this successfully in FF, the
reason I persevered so long was I knew it once worked.
As a matter of interest is there a way to see what DOCTYPE the browser chose
to use? The browser is obviously smarter than I am in selecting DOCTYPEs so
maybe I should follow its cue.
Thanks to everyone else who kindly responded as well, I really appreciate
it.
Cheers
Arno
--- End Message ---
--- Begin Message ---
Ther is a VAT number validation API.
http://isvat.appspot.com/
How to use this; integrate it in PHP to validate VAT-numbers without the
user experiencing anything?
--- End Message ---