简体   繁体   中英

PHP Get Id from Url .$_GET['id'];

How can I use the

.$_GET['id']; 

After Domain.com Like This

Domain.com/.$_GET['id']; 
($curl = curl_init('https://nombre.is/stream.php?mid=.$_GET['id']');) 

If I try to do it, it's contradictory to the page file.

<?php
  $curl = curl_init('https://nombre.is/stream.php?mid=.$_GET['id'];');
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
  $page = curl_exec($curl);
  if(curl_errno($curl)) // check for execution errors
  {
    echo 'Scraper error: ' . curl_error($curl);
    exit;
  }
  curl_close($curl);
?>

Has anyone an idea on how to fix this?

You should use string concatenation with the dot . operator, like so.

$curl = curl_init('https://nombre.is/stream.php?mid=' . $_GET['id']);

i am assuming you want to use id value from $_GET into string URL ?

  $id = $_GET['id'];
  $curl = curl_init("https://nombre.is/stream.php?mid=$id");

OR

  $curl = curl_init("https://nombre.is/stream.php?mid=" . $_GET['id']);

both will work

an other example as per your comment

$page_url = curPageURL();
$curl = curl_init('nombre.is/' . $page_url); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); 
$page = curl_exec($curl); 

or

$curl = curl_init('nombre.is/' . curPageURL()); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); 
$page = curl_exec($curl);

There's two ways of doing this! You can either use { } around the $_GET variable, which you should use when trying to pull a value from an array into a string, or you can use the concatenation operator . to join the two values together and append the $_GET['id'] to the end of the URL string.

Option 1:

$curl = curl_init("https://nombre.is/stream.php?mid=${_GET['id']});

Or using the . operator:

$curl = curl_init("https://nombre.is/stream.php?mid=" . $_GET['id']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM