Skip to content
Advertisement

How to open link in php code being executed via command line

header("location:http;//")

Above line does not seem to work when executing PHP scripts from command line. How best can I open links via command line?

Advertisement

Answer

A very hastily and quickly tested method might be to use exec passing in the path to a known browser with the url as it’s argument – seemed to work ok.

<?php
    $url='https://www.google.co.uk';
    $cmd=sprintf( '%%userprofile%%AppDataLocalGoogleChromeApplicationchrome.exe %s', $url );
    exec( $cmd );
?>

Thanks to @Álvaro’s comment the above can be simplified further( on Windows at least )

<?php
    $url='https://www.google.co.uk';
    $cmd=sprintf( 'start %s',$url );
    exec( $cmd );
?>
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement