i have a form that on post it runs a php page.But when the result is successful it opens a notification page. The problem is that it opens both the php page and the notification all I would like to do is to show the nofication page. php page runs the confirmation then if the result is successful then the nofication is used. I used "window.open" in javascript.Please can someone help

Dani AI

Generated

As observed, the behavior is about how the browser is instructed to navigate rather than PHP logic. Calling window.open creates a new window or tab while the original PHP output remains visible, so both pages appear. Two clean approaches avoid that: a server-side redirect after processing (preferred — Post/Redirect/Get) or a client-side replace of the current page instead of opening a new one.

Example server-side redirect (stop further output immediately after sending the header):

header('Location: /notification.php', true, 303);
exit;

Notes: header() must be sent before any output (no whitespace or BOM). The 303 status tells the browser to follow with a GET, avoiding form-resubmit issues.

If headers are already sent or the flow is client-driven (AJAX), replace the current page from JavaScript rather than opening a new window:

window.location.replace('notification.php');

replace() swaps the current document without creating a history entry; href would keep history. Avoid mixing server output that renders the original page and client code that opens another page — that combination is what produced the double display for . Also consider using output buffering, checking for accidental whitespace before header(), and returning JSON for AJAX forms so the client can decide whether to navigate.

Recommended Answers

All 2 Replies

Hi there,
This is definitely a javascript problem, not pHp. Please check my response on the Javascript forum.

Can be this be done in php just to open a web page in the same window if result is successful please can some one help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.