How about this one? Add it to an include for the site and use it whenever
you have an error check.
function goBack($newSite,$errMsg)
{
$send = "";
foreach($_GET as $key=>$value)
{
$send = $send."&".$key."=".$value;
}
$goTo = urlencode($newSite."?errMsg=".$errMsg.$send);
header("Location: $goTo");
die();
}
if(there is a problem with the data)
{
$errorMessage = "some error";
goBack($HTTP_REFERER,$errorMessage);
}
I'd have to test the $HTTP_REFERER part, but I don't see why it wouldn't
work. I like the die() in there so I can just use an if statement at the
beginning without having to indent the rest of the script. Especially if
you have a lot of error checks.
-----Original Message-----
From: Chris W [mailto:[EMAIL PROTECTED]
Sent: Monday, December 29, 2003 12:02 PM
To: [EMAIL PROTECTED]
Subject: [PHP] urlencoding.
Let me give a quick background. I am a very experienced programmer but
I haven't done much php and only a little web development in perl. I am
now creating a web site with Apache, php and MySQL.
I am having the user fill out a form and then save the data in MySQL.
Before I save the data I do a few checks and if there is a problem I do
a redirect back to the form and send all the data back so they don't
have to fill out the whole form again. Here is some sample code I use
to build my redirect url....
$UserID = $_POST['UserID'];
$Password1 = $_POST['Password1'];
$Password2 = $_POST['Password2'];
$Email = $_POST['Email'];
$FName = $_POST['FName'];
$LName = $_POST['LName'];
do checking of data here.
if(there is a problem with the data){
$ErrorMsg = "some error";
$redirectStr = "$httpHost/CreateAccount.php?";
$redirectStr .= "UserID=" . urlencode(stripslashes($UserID));
$redirectStr .= "&Password=" . urlencode(stripslashes($Password));
$redirectStr .= "&Email=" . urlencode(stripslashes($Email));
$redirectStr .= "&FName=" . urlencode(stripslashes($FName));
$redirectStr .= "&LName=" . urlencode(stripslashes($LName));
$redirectStr .= "&ErrorMsg=" . urlencode($ErrorMsg);
header("Location: $redirectStr");
exit;
}
My problem is that any field that contains a double quote, all data
after the first double quote is missing from the form field. When I
look at the long URL I do see a %22 where the " are supposed to be, and
all other data is there too.
Any Ideas? If there is a better way to do this feel free to suggest a
change in my whole method here. Just as a note validation of the UserID
has to be done on the server side, to check for duplicates in the MySQL db.
I would also welcome insight on standard techniques to make sure the
user isn't trying to break the code by sending bogus data. I am already
checking that the data isn't longer than I am expecting.
Chris W
--
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