Forum Moderators: coopster

Message Too Old, No Replies

Redirect to page without opening a new tab

         

thanasisdev

7:43 am on Jan 29, 2009 (gmt 0)

10+ Year Member



Hello there to the forum from a new member

I'm developing a custom-based inventory/clients/orders desktop application in php. Because of the nature of these kind of applications being desktop, i currently have many problems programming the whole thing to act like a desktop one. One of my problems is the following:

I have a form which submits data to a process.php. The process.php listens for a hidden post variable so it can know which form is being processed. Everything goes fine - the correct method is called but here is where the problem comes.

After sucessfull run of the mysql queries, the user must be redirected to a success page. I have used header in doing that and it works perfect. The only problem i have is that the page that the user is being redirected opens in a NEW TAB on firefox. How can i do it so it will open in the same tab ?

Best Regards,
thanasisdev

PHP_Chimp

8:37 am on Jan 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What header code are you using?
Something like:

header('Location: /some_page.php');

Or something different?

thanasisdev

8:41 am on Jan 29, 2009 (gmt 0)

10+ Year Member



yes i use

header('Location: create_new_customer.php');

henry0

12:26 pm on Jan 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanasisdev, welcome to WebmasterWorld!
I believe that your solution to make it desktop like
should be using ajax request.
it will serve any request from the same original page.

PHP_Chimp

4:50 pm on Jan 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am assuming that you are using localhost as the host, or have you set up a specific ip address for your desktop application to use?

I am also making the assumption that you are using the traditional client server model, albeit you are running both on the same machine.

From the manual:


Note: HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself:

<?php
/* Redirect to a different page in the current directory that was requested */
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'mypage.php';
header("Location: http://$host$uri/$extra");
exit;
?>


So it may be that there is a confusion as to exactly what page you are trying to connect to.
Try the full address, or try using an absolute address--rather than your relative one--to see if you get a different result.

As if you can do it through ajax then you should be able to do it through the more traditional approach...seeing as they are both http requests.

thanasisdev

9:53 pm on Jan 29, 2009 (gmt 0)

10+ Year Member



Hey there

Thanks all for your replies.

I'm using a VMWARE virtual machine for the application.
My local machine listens on 0.3 and the VMWARE (the application) listens on 0.11.

I tried supplying the full path as parameter to the header but it does not work. It still redirects me to the page that i want but it opens the page with a new tab.

Is there a way to achieve this kind of functionality by using the header() or should i look somewhere else ? (ajax request maybe?)

Best Regards,
A.Emmanouilidis

thanasisdev

10:44 pm on Jan 29, 2009 (gmt 0)

10+ Year Member



Hello there,

I really don't understand the nature of this problem.
I just now checked out my code and i see i use header() successfully in another method on the Process.php file that i have. It redirects the user to a page but in the same window.

Any suggestions ?

PHP_Chimp

11:15 pm on Jan 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I dont understand why your application is opening a new tab on this occasion, especially if it is working correctly in another place.

While ajax would sort your problem, it is not really a solution. As it is just covering up the issue.

There is something different about this use of header. Exactly what that is I cant say. You need to look through all of your code to try and find that difference.

Is everything done over http or https, are you mixing protocols?

I would expect an anchor with the target="_blank" attribute to open a link in another tab/window, however these dont involve the header function. So I am obviously missing something.

You may need to post some larger chunks of code. Maybe both those where it is working correctly and where it isnt.

penders

12:25 am on Jan 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have a form which submits data to a process.php. ....

I would expect an anchor with the target="_blank" attribute to open a link in another tab/window...

Or

target="anything"
on your FORM element?

As far as I'm aware there is nothing that can be sent back from the server (ie. from PHP) that could trigger the browser to open a new tab / window. This sounds like a client-side issue... either an HTML target attribute or possibly JavaScript. Try disabling JS (easy to do in FF) to rule out the JS.

thanasisdev

1:49 am on Jan 30, 2009 (gmt 0)

10+ Year Member



Hi

I just can't figure out a solution. I have tried almost everything that i could think.

I tested the page in Internet Explorer and it opens the page in a new window!

I disabled the javascript in the Firefox and same behaviour happens ! The page is loaded in a new tab !

Really, i have run out of ideas. Help into this matter will be highly appreciated !

thanasisdev

1:56 am on Jan 30, 2009 (gmt 0)

10+ Year Member



hi there

Just did it. Thank you soooo much. I spend almost 24 full hours for this ! :-) The problem was a target="_blank" on my code. I'm not still finished with my problems, but i will post my other problem in a new post ;-)

best regards,
thanasisdev