473,698 Members | 2,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using header("Locatio n:...". How to pass over array variable?

Hi there,

I have a php script that does some form input validation. As it verifies
each field if the field has incorrect data, it appends an error message to
an $error array. E.g.

if (an_error = true) {
$errors.="<tr>< td>You have note entered a surname. This is mandatory date
of birth incorrectly.</td></tr>";
}

Previously I had always had the HTML error page code contained within the
same script, but now I am moving it out to make maintenance easier.

When validation completes there is now a statement that says
if ($errors!="") {
header("Locatio n: ./error_page.php" );
}

However, how can I pass the errors array to the error_page. I want to be
able to list each error individually.

Forgive me if this is a silly easy question. I have only been doing PHP for
about a week.
Thanks in advance.

Kind regards

Dave

Jul 17 '05 #1
13 11801
"Dave Smithz" <SPAM FREE WORLD> wrote:
I have a php script that does some form input validation. As it
verifies each field if the field has incorrect data, it appends an
error message to an $error array. E.g.

if (an_error = true) {
$errors.="<tr>< td>You have note entered a surname. This is
mandatory date
of birth incorrectly.</td></tr>";
}
This looks like a string not an array.
Previously I had always had the HTML error page code contained within
the same script, but now I am moving it out to make maintenance
easier.

When validation completes there is now a statement that says
if ($errors!="") {
header("Locatio n: ./error_page.php" );
}

However, how can I pass the errors array to the error_page. I want to
be able to list each error individually.

Forgive me if this is a silly easy question. I have only been doing
PHP for about a week.
Thanks in advance.


Assuming it is actually an array, you can loop through it along the
lines of something like so:

$vars = '?';
for($i = 0; $i < sizeof($array); $i++) {
$vars .= "array[]=" . urlencode($arra y[$i]) . '&';
}

Then the receiving page will have an array $_GET['array'] filled with
elements.

If it's an associative array you can do this:

$vars = '?';
foreach($array as $name => $value) {
$vars .= $name . '=' . urlencode($valu e) . '&';
}

You can also use the serialize and unserialize functions to turn the
array into a string which you would then use urlencode make it url
safe.

Functions in the manual online here:

http://www.php.net/urlencode
http://www.php.net/serialize
http://www.php.net/unserialize
http://www.php.net/foreach

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #2

Thanks for that Chris. I did mean to put an array there.

Thanks for the info there, much appreciated.

Regards

Dave
Jul 17 '05 #3

Dave Smithz wrote:
Hi there,

I have a php script that does some form input validation. As it verifies each field if the field has incorrect data, it appends an error message to an $error array. E.g.

if (an_error = true) {
$errors.="<tr>< td>You have note entered a surname. This is mandatory date of birth incorrectly.</td></tr>";
}

Previously I had always had the HTML error page code contained within the same script, but now I am moving it out to make maintenance easier.

When validation completes there is now a statement that says
if ($errors!="") {
header("Locatio n: ./error_page.php" );
}

header("Locatio n: ./error_page.php? NAME=VALUE"); could be a way However, how can I pass the errors array to the error_page. I want to be able to list each error individually.

Forgive me if this is a silly easy question. I have only been doing PHP for about a week.
Thanks in advance.

Kind regards

Dave


Jul 17 '05 #4
Wouldn't it be easier to just serialise the array and pass it as a
value though get, then unseralise it.

Or even just include the error_page.php and pass it as a global and
then use the die() command to stop execution.

Jul 17 '05 #5
micha wrote:
header("Locatio n: ./error_page.php? NAME=VALUE"); could be a way


As I was told in this very group some weeks back (by you. :P) a
locationheader needs an absolute URL.

:-)

Regards,
Erwin Moller
Jul 17 '05 #6
Erwin Moller wrote:

micha wrote:
header("Locatio n: ./error_page.php? NAME=VALUE"); could be a way


As I was told in this very group some weeks back (by you. :P) a
locationheader needs an absolute URL.

:-)


No, it doesn't.
Jul 17 '05 #7
On Wed, 02 Feb 2005 14:42:57 +0100, Erwin Moller wrote:
locationheader needs an absolute URL.


Depends on the client, but yes.

To the OP: you could also use sessions. Put session_start() at the top
of both scripts, set $_SESSION['err'] = "My error message." in the first
one and echo $_SESSION['err'] in the second.
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #8
On 2005-02-02, Erwin Moller <si************ *************** *************** @spamyourself.c om> wrote:
micha wrote:
header("Locatio n: ./error_page.php? NAME=VALUE"); could be a way


As I was told in this very group some weeks back (by you. :P) a
locationheader needs an absolute URL.


But now we have:
http://www.ietf.org/rfc/rfc3986.txt
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #9
.oO(Anonymous)
Erwin Moller wrote:

As I was told in this very group some weeks back (by you. :P) a
locationheader needs an absolute URL.

No, it doesn't.


It does.

RFC 2616, section 14.30

Micha
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4438
by: Stijn Goris | last post by:
Hi all, I have a question regarding the header function. I send a browser to a certain page (eg first.php ) wich sends no output to the browser. This page sends the browser to another page (eg second.php) with the header("Location:") function. second.php doesn't either send any output to the browser. The browser is then send to another page also with the header() function. Now my problem: I have to send user and password data...
11
6070
by: Francisco Mendez | last post by:
I get the following message when trying to run my script: "Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/newcustomer.php:23) in /var/www/html/newcustomer.php on line 332" ....newcustomer.php:23 is where my script begins, at line 23. before that line, only comments.
6
2365
by: bissatch | last post by:
Hi, I am trying to use the following function: header("Location: http://www.mysite.co.uk/home/update/index.php"); ....but getting the following error: Warning: Cannot modify header information - headers already sent by (output started at
5
3217
by: Duderino82 | last post by:
I'm working on a very simple peace of php where basically there is a form and 3 buttoms. One refreshed the page, one posts the form, and another one (since this form contains values of a record) deletes the record. The sintax is this one: if ($delete) { header ("Location: $redirect?del=$code&table=$tab"); exit; }
1
2246
by: hemingvej45 | last post by:
Session variables set before a header("Location: whatever") are not being written. And yes, before the header() call, I have session_write_close() but the result is the same. This problem is with PHP 4.3.10 on my hosting providers' server (and obviously I wouldn't like the hassle of changing hosting providers), but it works OK on some other PHP 4 and PHP 5 servers. Is there any workaround?
3
2182
by: thomasg | last post by:
Hi, I am moving some scripts from a UNIX box to a Windows box. A data entry form calls a PHP script the updates the records from the form. After the script completes, The script redirects to anothe page. No headers have been sent, the script just does the database update. This works on the UNIX account: Header( "Location: http://www.new-url.com" ); It does not work on the IIS box.
4
9169
by: andre rodier | last post by:
Hello, I need to display or propose a jpeg image on a web page. When I need to display the image, I use this code : header("Content-Length: $fileSize") ; header("Content-Type: $type") ; header("Content-disposition: inline") ; header("Location: $imageURL"); And when I need to propose the image to save, I use this one :
5
11797
bilibytes
by: bilibytes | last post by:
hi, i am making a website with php OOP. i have a class called session: it has the attribues -logged_in; -user_name; -user_ip; -user_level;
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9027
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.