php-general Digest 5 Jan 2011 07:54:26 -0000 Issue 7116
Topics (messages 310489 through 310497):
Re: Two forms on one page
310489 by: Jim Lucas
310490 by: Jim Lucas
310492 by: Paul M Foster
310493 by: Jim Lucas
Re: session_id() is not passed to the next page
310491 by: Al
Unload/reload included class
310494 by: Patrik Pomichal
mysqli fetch-fields returns blob for text
310495 by: Mari Masuda
Two forms on one page - THE ANSWER
310496 by: Ethan Rosenberg
[SOLVED] Re: session_id() is not passed to the next page
310497 by: Michelle Konzack
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 ---
On 1/4/2011 7:53 AM, Ethan Rosenberg wrote:
> At 03:45 AM 1/4/2011, you wrote:
>> Ethan,
>>
>> Ok, I would do this with what I would call wizard steps...
>>
>> On 1/3/2011 3:17 PM, Ethan Rosenberg wrote:
>>> Oooops - left out the text that was supposed to be in the quotes.
>>>
>>> Dear List -
>>>
>>> I would like to have two(2) forms in one PHP script. I would like to
>>> have the forms appear sequentially; ie, that the first form would
>>> appear, the data would be entered, and then the second form would
>>> appear, the data would be entered, and the script would exit.
>>>
>>> The code below displays both forms simultaneously. After the data is
>>> entered for the first form, the second form appears again. After the
>>> data is entered for the second form, the script displays the statement
>>> "Enter your date of birth, in mm/dd/yyyy format: " from the first form.
>>>
>>> Would you please help me correct the script so that it will perform as
>>> required.
>>>
>>> Thanks.
>>>
>>> Here is the code:
>>> ============
>>
To go back to what I originally wrote. I found 1 error in the second form.
Here is the corrected form.
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><body>
<?php
switch ( @$_POST['next_step'] )
{
case 'step3':
if ( empty($_SESSION['dob']) )
die('DOB was not set in session...');
$dateArr = explode('/', @$_SESSION['dob']);
// calculate timestamp corresponding to date value
$dateTs = strtotime($_POST['dob']);
// calculate timestamp corresponding to 'today'
$now = strtotime('today');
// check that the value entered is in the correct format
if ( sizeof($dateArr) != 3 )
die('ERROR: Please enter a valid date of birth');
// check that the value entered is a valid date
if ( !checkdate($dateArr[0], $dateArr[1], $dateArr[2]) )
die('ERROR: Please enter a valid date of birth');
// check that the date entered is earlier than 'today'
if ( $dateTs >= $now )
die('ERROR: Please enter a date of birth earlier than today');
// calculate difference between date of birth and today in days
// convert to years
// convert remaining days to months
// print output
$ageDays = floor(($now - $dateTs) / 86400);
$ageYears = floor($ageDays / 365);
$ageMonths = floor(($ageDays - ($ageYears * 365)) / 30);
echo "You are approximately $ageYears years and $ageMonths months old.";
break;
case 'step2':
$_SESSION['dob'] = @$_POST['dob'];
echo <<<FORM
<form method="post" action="">
<input type="hidden" name="next_step" value="step3" />
Enter your kitten's name: <br />
<input type="text" name="cat" />
<input type="submit" name="submit" value="Submit Kitten" />
</form>
FORM;
break;
case 'step1':
default:
echo <<<FORM
<form method="post" action="">
<input type="hidden" name="next_step" value="step2" />
Enter your date of birth, in mm/dd/yyyy format: <br />
<input type="text" name="dob" />
<input type="submit" name="submit" value="Submit" />
</form>
FORM;
}
?>
</body></html>
If this isn't it, I think you should explain (in sudo code) exactly the steps
you are expecting things to.
Example sudo code
1. display form 'A'
2. Person enters dob and presses submit
3. processing script stores dob submitted
4. display form 'B'
5. person enters name of kitten and presses submit
6. processing script retrieves dob previously stored
7. calculate age
8. display age
...
10. What happen to the kitten???
Form 'A':
<form method="post" action="">
<input type="hidden" name="next_step" value="step2" />
Enter your date of birth, in mm/dd/yyyy format: <br />
<input type="text" name="dob" />
<input type="submit" name="submit" value="Submit" />
</form>
Form 'B':
<form method="post" action="">
<input type="hidden" name="next_step" value="step3" />
Enter your kitten's name: <br />
<input type="text" name="cat" />
<input type="submit" name="submit" value="Submit Kitten" />
</form>
Anyways, that is the idea.
Let us know.
Jim
> Please correct my errors.
>
> Thanks again.
>
> Ethan
> +++++++
>
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
>
--- End Message ---
--- Begin Message ---
Sorry for top posting!
FYI: You might want to check the math in your calculations. It says that I am
41 when my birthday is tomorrow and I will be 36...
On 1/4/2011 10:08 AM, Jim Lucas wrote:
> On 1/4/2011 7:53 AM, Ethan Rosenberg wrote:
>> At 03:45 AM 1/4/2011, you wrote:
>>> Ethan,
>>>
>>> Ok, I would do this with what I would call wizard steps...
>>>
>>> On 1/3/2011 3:17 PM, Ethan Rosenberg wrote:
>>>> Oooops - left out the text that was supposed to be in the quotes.
>>>>
>>>> Dear List -
>>>>
>>>> I would like to have two(2) forms in one PHP script. I would like to
>>>> have the forms appear sequentially; ie, that the first form would
>>>> appear, the data would be entered, and then the second form would
>>>> appear, the data would be entered, and the script would exit.
>>>>
>>>> The code below displays both forms simultaneously. After the data is
>>>> entered for the first form, the second form appears again. After the
>>>> data is entered for the second form, the script displays the statement
>>>> "Enter your date of birth, in mm/dd/yyyy format: " from the first form.
>>>>
>>>> Would you please help me correct the script so that it will perform as
>>>> required.
>>>>
>>>> Thanks.
>>>>
>>>> Here is the code:
>>>> ============
>>>
>
> To go back to what I originally wrote. I found 1 error in the second form.
> Here is the corrected form.
>
> <?php session_start(); ?>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html><body>
> <?php
>
> switch ( @$_POST['next_step'] )
> {
> case 'step3':
>
> if ( empty($_SESSION['dob']) )
> die('DOB was not set in session...');
>
> $dateArr = explode('/', @$_SESSION['dob']);
>
> // calculate timestamp corresponding to date value
> $dateTs = strtotime($_POST['dob']);
>
> // calculate timestamp corresponding to 'today'
> $now = strtotime('today');
>
> // check that the value entered is in the correct format
> if ( sizeof($dateArr) != 3 )
> die('ERROR: Please enter a valid date of birth');
>
> // check that the value entered is a valid date
> if ( !checkdate($dateArr[0], $dateArr[1], $dateArr[2]) )
> die('ERROR: Please enter a valid date of birth');
>
> // check that the date entered is earlier than 'today'
> if ( $dateTs >= $now )
> die('ERROR: Please enter a date of birth earlier than today');
> // calculate difference between date of birth and today in days
> // convert to years
> // convert remaining days to months
> // print output
> $ageDays = floor(($now - $dateTs) / 86400);
> $ageYears = floor($ageDays / 365);
> $ageMonths = floor(($ageDays - ($ageYears * 365)) / 30);
> echo "You are approximately $ageYears years and $ageMonths months old.";
>
> break;
> case 'step2':
> $_SESSION['dob'] = @$_POST['dob'];
> echo <<<FORM
> <form method="post" action="">
> <input type="hidden" name="next_step" value="step3" />
> Enter your kitten's name: <br />
> <input type="text" name="cat" />
> <input type="submit" name="submit" value="Submit Kitten" />
> </form>
> FORM;
>
> break;
> case 'step1':
> default:
>
> echo <<<FORM
> <form method="post" action="">
> <input type="hidden" name="next_step" value="step2" />
> Enter your date of birth, in mm/dd/yyyy format: <br />
> <input type="text" name="dob" />
> <input type="submit" name="submit" value="Submit" />
> </form>
> FORM;
> }
> ?>
> </body></html>
>
> If this isn't it, I think you should explain (in sudo code) exactly the steps
> you are expecting things to.
>
> Example sudo code
>
> 1. display form 'A'
> 2. Person enters dob and presses submit
> 3. processing script stores dob submitted
> 4. display form 'B'
> 5. person enters name of kitten and presses submit
> 6. processing script retrieves dob previously stored
> 7. calculate age
> 8. display age
> ...
> 10. What happen to the kitten???
>
> Form 'A':
> <form method="post" action="">
> <input type="hidden" name="next_step" value="step2" />
> Enter your date of birth, in mm/dd/yyyy format: <br />
> <input type="text" name="dob" />
> <input type="submit" name="submit" value="Submit" />
> </form>
>
> Form 'B':
> <form method="post" action="">
> <input type="hidden" name="next_step" value="step3" />
> Enter your kitten's name: <br />
> <input type="text" name="cat" />
> <input type="submit" name="submit" value="Submit Kitten" />
> </form>
>
>
> Anyways, that is the idea.
>
> Let us know.
>
> Jim
>
>> Please correct my errors.
>>
>> Thanks again.
>>
>> Ethan
>> +++++++
>>
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>
>>
>
--- End Message ---
--- Begin Message ---
On Tue, Jan 04, 2011 at 10:08:47AM -0800, Jim Lucas wrote:
[snip]
> If this isn't it, I think you should explain (in sudo code) exactly the steps
> you are expecting things to.
>
> Example sudo code
>
[snip]
Normally I wouldn't comment on this (sorry, Jim), but for the foreigners
on the list, "sudo" is a command under Unix/Linux which allows one to
function as the root user. I suspect what Jim meant to write was
"pseudo" (pronounced the same way as "sudo" in English), which means
"fake" or "pretend".
English is one of those languages which is afflicted by lots of
homonyms-- words which sound the same but are spelled differently and
mean different things, even though they sound the same.
Paul
--
Paul M. Foster
http://noferblatz.com
--- End Message ---
--- Begin Message ---
On 1/4/2011 12:53 PM, Paul M Foster wrote:
> On Tue, Jan 04, 2011 at 10:08:47AM -0800, Jim Lucas wrote:
>
> [snip]
>
>> If this isn't it, I think you should explain (in sudo code) exactly the steps
>> you are expecting things to.
>>
>> Example sudo code
>>
>
> [snip]
>
> Normally I wouldn't comment on this (sorry, Jim), but for the foreigners
> on the list, "sudo" is a command under Unix/Linux which allows one to
> function as the root user. I suspect what Jim meant to write was
> "pseudo" (pronounced the same way as "sudo" in English), which means
> "fake" or "pretend".
>
> English is one of those languages which is afflicted by lots of
> homonyms-- words which sound the same but are spelled differently and
> mean different things, even though they sound the same.
>
> Paul
>
Paul,
Thanks for pointing that out. I sometimes write too fast...
Jim
--- End Message ---
--- Begin Message ---
On 1/3/2011 11:46 PM, Michelle Konzack wrote:
Hello,
I am rewriting currently a login script and I encountered a problem with
sessions. While reading the two pages
<http://php.net/manual/de/function.session-start.php>
<http://bugs.php.net/bug.php?id=14636>
I have not found a solution for my problem:
----8<------------------------------------------------------------------
function fncLogin($user, $pass, $redirect, $type='pam') {
if ($user != '' and $pass != '') {
$TEXT = "<FONT size=\"+2\" color=\"red\"><B>Error</B></FONT><br />\n";
$TEXT .= "<HR size=\"3\" noshade=\"noshade\">\n";
$TEXT .= "The username does not exist or the password is wrong.<p />\n";
$TEXT .= "<p />\n";
$TEXT .= "Please go<a href=\"" . $_SERVER['HTTP_REFERER'] . "\">back</a> and
try it again.\n";
if ($type == 'pam') {
if (pam_auth($user, $pass,&$PAM_ERR) === FALSE) {
fncError('2', $TEXT, $errpage='false');
exit();
}
} elseif ($type == 'shadow') {
$shadow_file = DIR_HOST . "/.shadow";
if (is_file($shadow_file)) {
$SHADOW = exec("grep \"^" . $user . ":\" " . DIR_HOST . "/.shadow |cut -d:
-f2");
if (empty($SHADOW)) {
}
$SALT=exec("grep \"^$user:\" " . DIR_HOST . "/.shadow |cut -d: -f2 |cut -d$
-f1-3");
$ENCRYPTED=crypt($pass, $SALT);
if ($SHADOW != $ENCRYPTED) {
fncError('2', $TEXT, $errpage='false');
exit();
}
} else {
$TEXT = "<FONT size=\"+2\" color=\"red\"><B>Error</B></FONT><br />\n";
$TEXT .= "<HR size=\"3\" noshade=\"noshade\">\n";
$TEXT .= "This is a system error. I can not authenticate du to a missing
config.\n";
$TEXT .= "<p />\n";
$TEXT .= "Please inform the<a href=\"" . SYSAMIN . "\">sysadmin</a> and
try it later again.\n";
fncError('1', $TEXT, $errpage='false');
exit();
}
}
session_register('sess_user');
session_register('sess_timeout');
$sess_user = $user;
$sess_timeout = time() + 900;
session_write_close();
header("Location: " . $redirect);
}
exit();
}
----8<------------------------------------------------------------------
which call the following page correctly, but the two vars $sess_user and
$sess_timeout are empty.
Can someone please tell me how to do this?
Thanks, Greetings and nice Day/Evening
Michelle Konzack
Firefox has a great add-on that lets you see the server/client handshaking
headers httpFox e.g., Cookie: PHPSESSID=fc310ca5f2c708988bf456f691cc58c2
Thus you can easily see if PHPSESSID is set and returned to the server.
--- End Message ---
--- Begin Message ---
Hi there,
I trying to create CLI php application. It running continuously (server)
and it will has a plugins. I want load, unload and reload plugins on
the fly, without stop the application.
Loading plugin is easy, when my app found new file in plugins dir,
include and register it. But if i change the plugin source i must
restart the app to reload it.
Have anyone idea, how i can unload included (loaded) class?
Thank you for every response. Best regards.
Patrik Pomichal
PHP developer
Slovakia
--- End Message ---
--- Begin Message ---
Hello,
On http://www.php.net/manual/en/mysqli.constants.php there are some predefined
constants for MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_MEDIUM_BLOB,
MYSQLI_TYPE_LONG_BLOB, and MYSQLI_TYPE_BLOB. Through some experimentation I
have found that fields in my MySQL database that are declared as 'text' in
MySQL are categorized by PHP as 'blob' when I compare the above constants to
the field's type using
http://www.php.net/manual/en/mysqli-result.fetch-fields.php.
In the MySQL documentation http://dev.mysql.com/doc/refman/5.1/en/blob.html in
the second paragraph it states:
---
BLOB values are treated as binary strings (byte strings). They have no
character set, and sorting and comparison are based on the numeric values of
the bytes in column values. TEXT values are treated as nonbinary strings
(character strings). They have a character set, and values are sorted and
compared based on the collation of the character set.
---
I was wondering if PHP's interpretation of 'text' as 'blob' could cause me any
trouble down the road and what the workarounds are, if any. Thank you.
Mari
--- End Message ---
--- Begin Message ---
Jim -
Much thanks to you for solving a problem with which I have been
struggling for the last two weeks.
Here is the code:
===========
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
switch ( @$_POST['next_step'] )
{
case 'step1':
echo 'Your kittens name is '.htmlspecialchars($_POST['cat']);
echo <<<FORM
<form method="post" action="">
<input type="hidden" name="next_step" value="step2" />
<br />Enter your date of birth, in mm/dd/yyyy format: <br />
<input type="text" name="dob" />
<input type="submit" name="submit" value="Submit" />
</form>
FORM;
break;
case 'step2':
if ( empty($_POST['dob']) )
die('DOB was not set in session...');
if ( !preg_match('!^\d{2}/\d{2}/\d{4}$!', $_POST['dob'], $m) )
die('DOB was not properly formated, please try again.');
// calculate timestamp corresponding to date value
$dateTs = strtotime($_POST['dob']);
// calculate timestamp corresponding to 'today'
$now = strtotime('today'); $dateArr = explode('/', @$_POST['dob']);
// check that the value entered is a valid date
if ( !checkdate($dateArr[0], $dateArr[1], $dateArr[2]) )
die('ERROR: Please enter a valid date of birth');
// check that the date entered is earlier than 'today'
if ( $dateTs >= $now )
die('ERROR: Please enter a date of birth earlier
than today');
// calculate difference between date of birth and today in days
// convert to years
// convert remaining days to months
// print output
$ageDays = floor(($now - $dateTs) / 86400);
$ageYears = floor($ageDays / 365);
$ageMonths = floor(($ageDays - ($ageYears * 365)) / 30);
echo "You are approximately $ageYears years and $ageMonths
months old.";
break;
case 'step1':
default:
echo <<<FORM
<form method="post" action="">
<input type="hidden" name="next_step" value="step1" />
Enter your kitten's name: <br />
<input type="text" name="cat" />
<input type="submit" name="submit" value="Submit Kitten" />
</form>
FORM;
}
?>
=========
Ethan
MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)]
--- End Message ---
--- Begin Message ---
Hello Daniel Molina Wegener,
Am 2011-01-04 07:43:46, hacktest Du folgendes herunter:
> Did you tried working with error_reporting(E_ALL) and looking if you have
> the well known warning "headers already sent"?. Try to work with
> error_reporting(E_ALL), instead of hiding errors. If you get that warning
> or error means that the cookie for session id was not written, so you can't
> handle the session id on the next page...
Yes, and it is clean
> Try using session_start() as the very first call or session.auto_start = 1
> in your php.ini (which is not recommended).
I have already found the error.
If my 00_main.inc is read in, I check first some required vars, then for
the existence of three config files and then I output errors if
something is wrong and if all is fine I contine and do session_start().
I have overseen that there is an include which was read before
session_start() and created the problem...
This is one reason, WHY I rewrite my scripst from the last 10 years.
They where transformed in unreadable spagetti code.
However, now I can use my login script with PAM, Shadow Passwords and
One-Time Passwords which use a 8 letter TAN list.
One-Time Passwords are very handy, if you have to access your website
from unknown computers like in internet cafes or such.
Thanks, Greetings and nice Day/Evening
Michelle Konzack
--
##################### Debian GNU/Linux Consultant ######################
Development of Intranet and Embedded Systems with Debian GNU/Linux
itsyst...@tdnet France EURL itsyst...@tdnet UG (limited liability)
Owner Michelle Konzack Owner Michelle Konzack
Apt. 917 (homeoffice)
50, rue de Soultz Kinzigstraße 17
67100 Strasbourg/France 77694 Kehl/Germany
Tel: +33-6-61925193 mobil Tel: +49-177-9351947 mobil
Tel: +33-9-52705884 fix
<http://www.itsystems.tamay-dogan.net/> <http://www.flexray4linux.org/>
<http://www.debian.tamay-dogan.net/> <http://www.can4linux.org/>
Jabber [email protected]
ICQ #328449886
Linux-User #280138 with the Linux Counter, http://counter.li.org/
signature.pgp
Description: Digital signature
--- End Message ---