-1

I have a mp3 player using php script. when they click the link it will play. the problem is when the link is open a new tab it will automatically downloaded the mp3 song. or when they copy the url link. I want to prevent direct access to that page or open new tab. I want is when they open new tab there is an error page.

in my index.php where they click the link it will play.

echo '<li class="active"><a href="play.php?id='.base64_url_encode($item).'&cid='.$today.'"><img src="./images/song.png" alt="" style="width:20;height:20;border:0;" data-method="post"> ' . $filename . '</a></li>'.PHP_EOL;

the play.php?id=Li9tdXNpYy9NdXNpY3MyL05ldyBGb2xkZXIvTmV3IEZvbGRlci9IYW1ib2cgTmcgU2FncHJvIEtyZXctQWxhYWxhIE5hbGFuZyBmdC4gTFVOIChMeXJpY3MpLm1wMw,,

that "play.php?id=" is I want to prevent from opening in new tab or direct access. only mp3 player can interact to play.php?id=.

I tried to create a session but not working, I tried $_SERVER["HTTP_REFERER"] not working too.

I need a code that is constant in index.php and when the code from index.php is not equal to the code in play.php it will got an error. I tried a time stamp the problem is when it cannot equal the time stamp to the index and to the play.php. any idea? I need a validator from index.php to another page play.php. thanks in advance!

I tried this code for hiding the real url of play.php the problem is the mp3 file will load instead of playing to the player

<a href="index.php" onclick="javascript:$('#myDiv').load('play.php?id=');return false;">Link</a>
<div id="myDiv"></div>
djsoda
  • 25
  • 1
  • 9

1 Answers1

0

Have you tried on the part of your link, instead of using:

<a href="play.php?id='.base64_url_encode($item).'&cid='.$today.'"><img src="./images/song.png" alt="" style="width:20;height:20;border:0;" data-method="post"> ' . $filename . '</a>

Which, from the looks of things, you have a list on your page with various base64 encoded URLs as links called to display alongside a 20px by 20px little (also linked/clickable) thumbnail of the album artwork, and then a text display next to it of the filename, called dynamically by $filename - before you close the link HTML tag out with the closing </a>

Have you tried in the beginning <a href="your base64 encoded URL goes here", after the closing double quotation mark (") to contain the URL, to add in exactly this, including the space:

<a href="your base64 encoded URL goes here" target="_self">

That should force the clicked-upon link to be force-loaded within the existing page. Like the old-school but still valid 'target="_blank"' would cause a link to open in a new tab (or window, depending upon your particular browsers' settings). Simple fix, but it just might work.

  • not working. when I open new tab it will download the mp3. – djsoda Jan 18 '19 at 07:57
  • the link is clickable and the thumbnail. when it click it will play on the music player without any page visiting only to pages the index.php where the player is in and the play.php?id=' – djsoda Jan 18 '19 at 08:16
  • I'm kind of confused, why are you even using a play.php page? Especially if you're only using a stylized/built-in (display-on-page, embedded) kind of audio player, perhaps it'd be easier to use one of the many available CSS-based or even a javascript based free open source audio players that'll allow you to call the various items in the playlist from a specified playlist file. Most of these have a built-in protection to keep any people from snooping around at your playlists' source URLs within the code itself. Might be worth taking a look at it. – itsamystery Jan 18 '19 at 09:20