open url from button using php
I need to make a button that:
- Send to php script variable pressed=true when its pressed
- open new tab with开发者_如何学运维 an adress
How can I do it without using java-script?
PHP can't cause events to happen in the client browser, you will need javascript for that. The button would have to submit the data to the PHP script, and then the script would display whatever output you like.
You could do this however
<FORM ACTION="phpscript.php" METHOD="POST" TARGET="_BLANK">
<BUTTON TYPE="submit" VALUE="1" name="pressed">Click</BUTTON>
</FORM>
This will open a new window(tab in FireFox at least)and you will have passed the value to your PHP script.
In your PHP script you check the value, and use a header to specify a new address:
if($_POST['pressed'] == 1 )
header("Location: http://www.whatever.com");
精彩评论