M
M
midarovrk2016-10-01 09:55:32
PHP
midarovrk, 2016-10-01 09:55:32

How to fix script to not cut title after # in PHP ucoz?

Hello everyone, are there any experts in PHP Yukoz ?
There is a script that shows what page the user last viewed.
First, a get request occurs:

<script type="text/javascript">$.get('/php/user_mn/index.php?n='+document.title);</script>

PHP file content:
<?php 
$___notjson = 1;
$id = ucoz_getinfo("SITEUSERID");
$getid = $_REQUEST['i'];
$n = $_REQUEST['n'];
$name = explode('?', $n);
$url = $_SERVER['HTTP_REFERER'];

if(empty($name[0])){
  if(!empty($getid) && file_exists('data/'.$getid.'.dat')){
    header('Content-Type: text/html; charset=utf-8');
    $file = file_get_contents('data/'.$getid.'.dat');
    echo $file;
  }else{
    echo 'Нет данных...';
  }
}else{
  $f = fopen('data/'.$id.'.dat', 'w+');
  fwrite($f, '<a href="'.$url.'" target="_blank">'.$name[0].'</a>');
  fclose($f);
}
?>

The following information is displayed in this block:
<div class="udtb"><div class="udtlb">Последний раз был:</div> <span id="whtl">Загрузка...</span></div>   
<script type="text/javascript">$('#whtl').load('/php/user_mn/index.php?i=$_USER_ID$');</script>

The problem is that if there is # in the title, then it is displayed only up to this grid.
For example, the title looks like this Guardians of the Galaxy (Vol. 2): #2 / Guardians of the Galaxy (Vol. 2): #2
And the script outputs Guardians of the Galaxy (Vol. 2):
Everything up to the bars.
Who can tell why this is happening?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hoarywolf, 2016-10-01
@midarovrk

I guess encodeURIComponent will save the day

<script type="text/javascript">$.get('/php/user_mn/index.php?n='+encodeURIComponent(document.title));</script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question