I know you cannot have multiple headers in a section of code. But is there a way to make it work?

I require 1 header to refresh the page.

I require 1 header to open a new page.

Note: The refresh paged is not the new paged that is opened.

General idea is... I click a button, goes through php code, opens a new page and then refresh orginal page.

So any ideas?

Thanks, Regards X

Recommended Answers

All 12 Replies

General idea is... I click a button, goes through php code, opens a new page and then refresh orginal page.

You mean the 'new page' is a popup and 'original page' is the parent window ?

correct.

any ideas?

thanks again nav

you cannot open a new window with php. you have to use JS.

To open a new page in the same window use: header("Location: newpage.php");

If you want to open a popup and then refresh the page I'd prefer it to to it both in JS. first window.open("popup.php") [see manual for correct use] and then parent.location.href="newpage.php" to reload the parent window.

I have to use php as I require access to the mysql database operations and more.
For the record, you can use a combination of html/php to open up a new window.

Thanks anyways, I will keep javascript in mind.

Lets clarify something.
When u say popup window you mean new window? or a window that has been shortened?

As I require a new window. (which I am able to do).

I get a new window by using a form and setting the target="_blank" and then i use a switch statement based on php, runs php code, then the headers tangle (refresh and open window). But seperately they work fine but I require both.

There is nothing that can be figured out to allow both be done in php? Javascript the only solution?

Note: is is possible to send/declare php variables if i use javascript to open it?
Also if i use javascript can i use it with the switch statement when an input button is clicked? (remember nav a few threads ago i showed u what i use?)

Thanks nav, Regards X

Well, AFAIK, If you want the parent window to be refreshed, you can't do it using php. That can only be done using javascript.
You can declare a php variable in javascript. But you can't use it in javascript. But this works.

<script type='text/javascript'>
function test() {
<?php 
$x=1000;
?>
....
}
</script>

Ok thanks for the feedback, during the week if not tonight ill give it and whirl and let you know what I come up with.

On a side note pretty disappointed that php is so "useless" in this situation that it is not able to refresh a page and then open a new one. :(

Thanks again nav, keep you posted.

Hmm.. Well, how bout this. When you click on a button, call a javascript function, which opens a new window, window.reload the parent window ?
Maybe someone has an answer for this.

Cheers,
Naveen

Ok ill go with that idea.

Ill keep you posted, thanks for all the help nav once again. :)

PHP is not useless. PHP is just a server-script that cannot control the users browser. JS does. But therefore for instance you cannot access databases (at least not as easy as in PHP).

When you send a header, just one of the Location (I believe it is the first one) will be executed. The other one is ignored by the browser.

What you want to do is actually very simple. Just try to understand the followin logic:

You have a webpage and when clicking a button, a popup is created and the parent is refreshed. You can do it as follows.
<script language=javascript>
function popuprefresh()
newwin=window.open("popup.php?vars=...")
document.location.href="refresh.php?vars=...";
}
</script>

Now you want to parse variables to your php-script:
document.location.href="refresh.php?vars=hello%20OmniX"; (similar to popup)
In PHP you can access the variable $vars with the value "hello OmniX".

the otherway round (using php values in JS):
document.location.href="refresh.php?vars=<?echo $myphpvar?>";
which will look after the execution of the code like this:
document.location.href="refresh.php?vars=blablahblah";

If you still didn't get it, then try to post some of you code so that we can edit it.

Basically you can often link both languages very easily. Just sometimes when sending forms or multiple data with JS to PHP it gets a bit tricky.

Ok ive tried n tried n tried and now im lost (maybe due to the massive headache).

I want to copy and paste all the code so you can view but I dont think people will appericate 300 lines of code nor will it be helpful.

I have an idea.

Maybe someone can give me a small example using javascript & php & html.

Using the javascript to open/refresh and php to declare session variables/queries/headers and html to use form/input tags to activate it.

Then maybe I can try and understand the concept used and apply it to my scenario.

Thanks for all the help, were on the home stretch!

Regards, X

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.