-1

I'm trying to make a tool that allows you to enter a word, press search and then 4 tabs open with YOURWORD facebook, YOURWORD twitter, YOURWORD instagram, YOURWORD soundcloud as search on Google.

I'm quite stuck on how to implement this with PHP so that's why I am posting this here, anyone got some tips for me on how to create this?

Thanks so much in advance for your help.

HiCT
  • 9
  • 2
  • 1
    At least try something, show some code and then we can help.. – chandresh_cool Jan 19 '17 at 11:45
  • I made a simple text field, but that's where I am getting stuck, how can i write code that makes a new link in a new tab.. – HiCT Jan 19 '17 at 11:47
  • You're not going to do this with PHP - tabs are part of the browser (client) environment, PHP runs on the server. JavaScript or a simple `target="_blank"` are your best bet. You can't, however, force it to be a tab rather than a window, that's down to user preferences : http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript – CD001 Jan 19 '17 at 11:52
  • Ah ok, I'll check it out! – HiCT Jan 19 '17 at 11:59

1 Answers1

0

It can't be done with PHP alone, you need a bit of JavaScript for the client-side operations (opening a new window).

<?php
function getPHPSelf() {
  if (isset($_SERVER['PATH_INFO']) && strlen($_SERVER['PATH_INFO'])> 0) {
    return substr($_SERVER['PHP_SELF'],0,(strlen($_SERVER['PHP_SELF']) - @strlen($_SERVER['PATH_INFO'])));
  }
  else {
    return $_SERVER['PHP_SELF'];
  }
}

if (isset($_POST['submit'])) {
  $search = $_POST['search'];

$fblink = "<script>window.open('https://www.google.com/webhp?q=".$search."+site:facebook.com', 'width=700,height=700,left=100,top=100')</script>";
$twlink = "<script>window.open('https://www.google.com/webhp?q=".$search."+site:twitter.com', 'width=700,height=700,left=100,top=100')</script>";
$iglink = "<script>window.open('https://www.google.com/webhp?q=".$search."+site:instagram.com', 'width=700,height=700,left=100,top=100')</script>";
$sclink = "<script>window.open('https://www.google.com/webhp?q=".$search."+site:soundcloud.com', 'width=700,height=700,left=100,top=100')</script>";

echo $fblink;
echo $twlink;
echo $iglink;
echo $sclink;
}
else {
  echo "<form enctype=\"multipart/form-data\" action=\"".getPHPSelf()."\" method=\"POST\">";
  echo "Search: <input type=\"text\" size=\"50\" name=\"search\">";
  echo "<input type=\"submit\" value=\"Search\" name=\"submit\">";
  echo "</table>";
  echo "</form>";
}
?>
Sienile
  • 186
  • 9