473,406 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

header issue

zorgi
431 Expert 256MB
Hi guys

Its me again :)
I have a small problem with redirecting using headers. When I do for example this

[PHP]
header('Location: index.php');
[/PHP]

Everything works fine. User gets redirected and looks at the page I wanted them except that if I had any code after that statement its still gonna be executed. I came up with somewhat sloppy solution of if else blocks and ... well as I said it doesn't look nice. Is there a better way.

Also one more question. Sometime when header like above doesn't work because of necessary outputs to the page I simply do this:

[PHP]
echo "<script language='javascript'>\n";
echo "window.open('".$redirect_url."', '_parent')";
echo "</script>\n";
[/PHP]

It works but also looks bit sloppy to me. Is there better solution to this problem. Thank you in advance for your input.
Oct 15 '08 #1
4 1044
Dormilich
8,658 Expert Mod 8TB
[PHP]header('Location: index.php');
exit;
# further code [/PHP]
Oct 15 '08 #2
zorgi
431 Expert 256MB
[PHP]header('Location: index.php');
exit;
# further code [/PHP]
Lovely. Thank you :)
Oct 15 '08 #3
Atli
5,058 Expert 4TB
As to your other question.

You can use Output Buffering to control exactly when the output is sent.

For example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo "Something very important";
  3. header("Location: index.php");
  4. ?>
  5.  
This would cause and error and remain on the same page.
But this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. ob_start();
  3. echo "Something very important";
  4. header("Location: index.php");
  5. ob_end_flush();
  6. ?>
  7.  
would redirect you to "index.php".

Technically the output would still be sent, but you would be redirected before you ever saw it.
Oct 15 '08 #4
zorgi
431 Expert 256MB
Thank you so much guys. I knew there must be better solution to this and now I know it.
Oct 15 '08 #5

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

Similar topics

31
by: Steven T. Hatton | last post by:
If a header is not necessarily a source file, and the sequences delimited by < and > in header names aren't necessarily valid source file names, what exactly is a header? -- p->m == (*p).m == p.m...
6
by: G*rd*n | last post by:
I have been using the HTTP "Location" reponse header to direct a symbolic request to a CGI program to an actual URL/file. For example, let us suppose the CGI program's table indicates xyz ->...
5
by: vthakur | last post by:
Hello: I have a Axis Web Service that sets the sessionid in the SOAP header for persisting the session. The client is a .Net client that processes the header as an Unknown Header. It sets the...
2
by: Kevin Eldridge | last post by:
Hi, I'm trying to call a java web service and i need some help in creating a custom SOAP header in c#. I need to access to a Web service that implements authorization policy, by using a session...
4
by: Joseph Geretz | last post by:
We use a Soap Header to pass a token class (m_Token) back and forth with authenticated session information. Given the following implementation for our Logout method, I vastly prefer to simply code...
2
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hello misters, In another post of the news, mister Manish Bafna, give me a reference: ...
7
by: Wei | last post by:
Hi all, I found out I can use the max function which is defined in STL <algorithmwithout including this header in my program. The compilers I used are GNU g++ 3.4.4 and Visual Studio C++ 2005. ...
5
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I have a sub in vb.net that adds extra headers to a gridview and it works very well. however, i tried to translate it to c# and i'm getting the header inserting itself over the first datarows and...
12
by: William Gill | last post by:
I am retooling my design habits, trying to get rid of some mental artifacts, and trying to "standardize" my starting point "templates" (both html and css). I am also trying to avoid "div-itis." I...
2
vijcbe
by: vijcbe | last post by:
Hello friends!! I am having an issue. I tried to remove the data cached in a page using the below header() functions. Code: header("Cache-control: no-store, no-cache, must-revalidate,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.