Вот что я пытаюсь сделать. В моем файле file.php есть функция, которая загружает внешний файл. Я хочу добавить идентификатор пользователя в URL. Этот скрипт загружает содержимое файла:
public function setExternalSolutionScriptsToBuffer() {
// Get dictionary
$externalSolutions = file_get_contents($this->getExternalTargetingSolutionsJsUrl());
// Composer the ouput buffer
$this->outputBuffer .= "\n";
$this->outputBuffer .= $externalSolutions;
$this->outputBuffer .= "\n";
}
Существует также функция ID:
public function setExposureOfUserIdScriptToBuffer() {
$user_id = $this->visitor->getOnlineId();
}
Мне нужно передать эту переменную во внешний файл и прикрепить ее к концу URL-адреса этого скрипта:
(function () {
if (location.protocol.substr(0,5)==='http:') {
try {
(function () {
var d = document;
var e = d.createElement('script');
e.type = 'text/javascript';
e.src = 'http://example.com/some.js?uid=' + ***user_id***;
e.async = true;
(d.head || d.body || d.firstChild).appendChild(e);
})();
} catch (e) {}
}
})();
Таким образом, переменная будет добавлена к URL-адресу, а src будет выглядеть так: " http://example.com/some.js?uid=4234234324 "
быстро и грязно - если предположить, что $ externalSolutions является src JS
$userID = 1234;
$externalSolutions = file_get_contents(..js-file..);
$externalSolutions = str_replace('***user_id***', $userID, $externalSolutions);
echo "<script>\n",$externalSolutions,"\n</script>\n";
file_get_contents
иstr_replace
на***user_id***