• Welcome to PHPVIBE Forums. Please log in.

[ Video Sharing CMS v4 ] Hashing Video Id value in URL

Started by Hersh,

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

HershTopic starter

Alexander, @Mario,

I was trying to hash the video URL Id's so that it appears like YouTube but I'm having some difficulty. I edited functions.php to achieve this but when I pass the $id value through the hashing function, it evaluates to a null value. Is there some place where this is getting sanitized or something that is causing this to happen?

Here is the hashing script fyi:

http://hashids.org/php/

I can successfully do it in a separate test PHP file so I know there is no problem with the script itself. Any help would be appreciated.

Thanks
  •  

AHStudioOfficial

Quote from: Hersh on
Alexander, @Mario,

I was trying to hash the video URL Id's so that it appears like YouTube but I'm having some difficulty. I edited functions.php to achieve this but when I pass the $id value through the hashing function, it evaluates to a null value. Is there some place where this is getting sanitized or something that is causing this to happen?

Here is the hashing script fyi:

http://hashids.org/php/

I can successfully do it in a separate test PHP file so I know there is no problem with the script itself. Any help would be appreciated.

Thanks

Can i look at your website? I want to check out your custom template
  •  

PHPVibe A.

I assume you know in index.php you need to change the regex to accept the token (not id):

$router->map(get_option('video-seo-url','/video/:id/:name'), 'video', array('methods' => 'GET', 'filters' => array('id' => '(\d+)')));


Then com/com_video.php has

$v_id = token_id();


defined in lib/Routed.php

Let me know what it returns after then regex change, I assume it should be:

$router->map(get_option('video-seo-url','/video/:id/:name'), 'video', array('methods' => 'GET', 'filters' => array('id' => '(.*)')));

HershTopic starter

Yes, I already tried making that change in index.php but it made no difference. The URL's continue to appear as www.site.com/video/*empty*

That's why I'm confused, thought maybe I was missing a step.

It's almost as if it is being passed through a number_format() function. That would make sense I guess since the hash is essentially a string, it will return null in number format. But I don't see anywhere where that is happening.
  •  

HershTopic starter

Okay so it seems to work when I replace the $id variable with a number value in functions.php, but it does not work when I plug in the variable instead.

I can't figure out why it works for one but not the other. This is what I added to the video_url function in functions.php:
    global $hashids;
    $hashids = new hashids('*my salt string here*');
    $id = $hashids->encrypt($id);


Have I missed something?
  •  

HershTopic starter

Nevermind. Silly mistake. I forgot to call for the intval($id). Realized it while taking a nap. lol

I don't know why I thought number_format would even be relevant here given that it merely adds commas. I probably just needed sleep after 18 hours.


Now I just need to fix
$v_id = token_id();



After that, I will need to redirect any URL using the old format to the new one. Alexander, if you have some pointers for that, let me know.

Thanks
  •  

HershTopic starter

Sweet! Everything is working now. Just had to decode the token on com_video, strip the slash, and specify the array position.

Thanks for your help Alexander. Now I just need to figure out if I should redirect /video/12345 to the hashed version or just leave it be.
  •  

PHPVibe A.

Glad you figured it out.
Share your change for the others, else I'm sure they will buzz you on private messaging :)

Similar topics (7)