Reputation: 127
I want something similar like JavSacript's window.open()
method, which I can use to open a particular URL, for example, https://www.google.com/.
Is there a way in pure PHP
where I can do the same thing?
I know we can do that using selenium in python. I think guzzle
might be of some help but I can not find anything useful on the web on that. Thanks in advance.
Upvotes: 5
Views: 76525
Reputation: 547
Why did not use simplest way:
$page = fopen('http://www.example.com/filename.html');
or $page = file_get_contents('http://www.example.com/filename.html');
and return like echo $page;
?
Upvotes: 4
Reputation:
echo
JavaScript somewhere in your page, which contains code to open a new window to the desired location.
<?php
echo '<script type="text/javascript">
window.open("http://google.com");
</script>';
?>
Upvotes: 4
Reputation: 5622
If you are just talking about REDIRECTING than there are many ways:
header("location:ur url");
OR echo"<a href='ur url'></a>";
OR form submit
OR using JS
in php function :
<?php
function open_window($url){
echo '<script>window.open ("'.$url.'", "mywindow","status=0,toolbar=0")</script>;
}';
// test:
open_window('http://www.google.com');
?>
PHP can make any code run... it depends on you how you use PHP.
Upvotes: 2
Reputation: 569
Although you can not open a new window through PHP directly, you can use:
header("Location: <LOCATION_TO_REDIRECT>");
To redirect the current browser window to the specified URL.
Upvotes: 6