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

Home Posts Topics Members FAQ

header('Locatio n: ...') is not giving immediate redirect

103 New Member
I'm using Win2k with Apache 2, PHP 5.2 for my local test server.

My problem is that I think the header('Locatio n ...') function isn't sending the header immediately and the rest of my script is running before the page redirects.

I am using a $_SESSION array to transfer messages from one page to the next. I want the message available only once, then it should be deleted. I had been using the technique something like this:

Expand|Select|Wrap|Line Numbers
  1. if (isset($_POST['form_submitted'])) {
  2.   //handle_form
  3.   $_SESSION['message']=$errorMessages;
  4.   header('Location: http://www.thissite.com/new_page.php');
  5. }
  6. if (isset($_SESSION['message'])) {
  7.   $showMessage = $_SESSION['message'];
  8.   unset($_SESSION['message']);
  9. }
  10. echo $showMessage;
  11. echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post"><input type="hidden" name="form_submitted" value="v" /></form>
  12.  
//What I want:
The form is submitted, the page reloads to itself. The form checks everything and records any errors to $errorMessages. It transfers these to the $_SESSION array and it reloads to a new page.

//What seems to happen:
As before... but after the form check, it seems to run the rest of the script, and as the $_SESSION['message'] variable is now set, it goes into the part which unset()s that variable. THEN after this it redirects. Now of course the $_SESSION['message'] is unset and I get no message!

Does this make any sense? It's a bit convoluted. This is a highly simplified version of my page just to illustrate the process. Any help is very much appreciated!

Thanks in advance!!

Henry
Jul 12 '07 #1
4 3120
pbmods
5,821 Recognized Expert Expert
Heya, henryrhenryr.

Thanks for using CODE tags! Did you know that you can specify a language for your CODE tags to make your source code easier to read?

You will still need to use [/code] to close your code blocks, regardless of the language, but you can the use one of these tags to open your code block:

[code=html]
[code=javascript]
[code=php]

and so on.

Thanks!

MODERATOR
Jul 12 '07 #2
pbmods
5,821 Recognized Expert Expert
Heya, henryrhenryr.

Call exit() after you set the redirect header:

Expand|Select|Wrap|Line Numbers
  1. header( ... );
  2. exit();
  3.  
Jul 12 '07 #3
henryrhenryr
103 New Member
Hello pbmods!

I can't believe I didn't think of that! Genious. Thanks so much!

Henry
Jul 17 '07 #4
pbmods
5,821 Recognized Expert Expert
Heya, Henry.

Hello pbmods!

I can't believe I didn't think of that! Genious. Thanks so much!

Henry
Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Jul 17 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2415
by: jock | last post by:
A script i'm working on is behaving real strange. It is more or less the same as dozens of others that work aok. Info is posted from one script to another, the second script does some work (nothing too taxing, just checks the input and updates/moves a couple of files) then redirects to the first script. Its one of these second scripts I'm having trouble with. As I was writing it, instead if redirecting to the initial script I would...
4
6257
by: Jeff | last post by:
I've been able to find this question on a Google group search but not the answer. Plus I'm a late convert to php transferring over from ASP. I hope this isn't too many strikes against me. When I issue a "header(Location:/myscript.php?key1=value1&key2=value2);" the redirect happens just fine but the url in the address field keeps the previous url instead of the url I passed in the header call. This seems to happen only with I.E....
10
5655
by: Margaret MacDonald | last post by:
I'm seeing a problem that has me flummoxed. The only thing I can think of is that I'm violating some rule I don't know about. I have some code that does some processing and then does a header('Location: ...) jump to page A on success or falls through to the jump to page B. This is the code: if ( mysql_query( 'LOCK TABLES tableX WRITE', $link ) ) { mysql_query( $q, $link ) ; // store the record
3
2950
by: Bob Bedford | last post by:
From my record insertion page I do, in some cases, this: header("Location: http://$SERVER_NAME/mainpage.php?SID"); problem is that the mainpage.php doesn't takes new datas. I've to refresh the page to see the new inserted record. doing this: header("Refresh: 0; URL=http://".$_SERVER."/mainpage.php?SID);
6
5453
by: P-Rage | last post by:
Hello everyone, I was wondering what could possibly cause Internet Explorer 6 to loop a page usging a header(Location:) statement. For example, a page called 'page1.php': if((isset($_POST)) && ($name='valid')){ // insert some data into MySQL.
5
6128
by: One | last post by:
Hi guys - I have a problem after a client clicks a Confirm button on a form - the form processes the data, inserts into a database, and then redirects using header Location. I have tested this on two different Linux/Apache servers. One works perfectly, the other takes about 90 seconds to redirect. Has anyone seen this issue before ? It uses a function like this :
8
39272
by: php newbie | last post by:
I have a simple php page in which I use header("Location: http://www.example.com/"); to redirect the user to another php page. The php script works on my local machine but when I upload it to the web server for hosting the redirection does not work. Instead on one server it gives the standard header error Warning: Cannot modify header information - headers already sent
1
1651
by: lister | last post by:
Hi all, Just wondering whether there was any standard way of serving up a new page to the browser when the user has submitted the current page. Currently I: 1) Process any user submitted data in the current page 2) Send a header('location') redirect to the browser, which then requests the new page.
8
39903
by: pedalpete | last post by:
I thought this should be simple, but i can't seem to get it to work. I'm trying to do a simple redirect to a page, but need to pass a variable. I've tried a few things, but nothing seems to work. here's what I've tried header('Location: edit.php?sid=$sid');
0
8680
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
9030
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...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6528
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
4371
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...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
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.