PHP script to modify a dynamic website link and open a new tab


PHP script to modify a dynamic website link and open a new tab



This is my first question so if I am doing something wrong just let me know.
I currently maintain a webserver running unbuntu, php and mysql.


unbuntu


php


mysql



What I would like to do is add a new page to the site which shows a user a box where they can input text and when they click "Go" it modifies a URL and opens a new tab.



For example the URL would look like the below.


http://1.2.4.5/api.php?getServices={"account":"variable"}



If the person was to input 12345 into the box and select Go it would modify the link to:


12345


http://1.2.4.5/api.php?getServices={"account":"12345"}



I have attempted multiple different ways to implement this but had no luck so far and I can't seem to find any information about it online, could anyone give me a hand?



Thanks so much in advance.





Php can't modify a URL and open a new tab. It is a browser specification and should be deal with javascript.
– Saad Suri
Jun 29 at 9:44




2 Answers
2



You can use JavaScript for this as:


$(document).on('click', '#buttonid', function(){
var variable_name = $('#textboxid').val();
var url = 'http://1.2.4.5/api.php?getServices={"account":"'+variable_name+'"}';
window.open(url);
});



Or you can do it using PHP too. Add target="_blank" attribute in your <form> tag


target="_blank"


<form>


<form action="action.php" target="_blank" method="post">



And then write this PHP script on action.php


$url = 'http://1.2.4.5/api.php?getServices={"account":"'.$_POST['variable_name'].'"}';
header('location: '.$url);



You have to use AJAX for that, and javascript for new tab.
PHP is executed server side, you can't do it with






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift