• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.

Same URL

inept

Chevereto Member
i have asked this before.

http://chevereto.com/community/threads/same-link-url-bug-on-some-sites.3604/#post-20088

i dont know if its impossible to do.

but i would like to change the way links are created so its impossible for the same links to be made but with different cases on characters.

so

mysite/image/8U
and
mysite/image/8u

cannot happen.

i would like to keep the case sensitive links so i will get something like mysite/image/8u7YHs instead of mysite/image/8u7yhs like you said was a way to stop this from happening.

could you tell me what and where the code is located for the image ID upon upload?

and mainly where the code will check the ID's of previously uploaded images so its does not duplicate the ID for that image.
 
includes/functions.php

Code:
$base_chars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // DON'T REPEAT A SINGLE CHAR!

Moved to other section.
 
thanks rodolfo..

just so i understand this code

Code:
function chevereto_id($var, $action='encode') {
    $base_chars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // DON'T REPEAT A SINGLE CHAR!
   
    for ($n = 0; $n<strlen($base_chars); $n++) {
        $i[] = substr( $base_chars,$n ,1);
    }
 
    $passhash = hash('sha256',__CHV_CRYPT_SALT__);
    $passhash = (strlen($passhash) < strlen($base_chars)) ? hash('sha512',__CHV_CRYPT_SALT__) : $passhash;
 
    for ($n=0; $n < strlen($base_chars); $n++) {
        $p[] =  substr($passhash, $n ,1);
    }
 
    array_multisort($p, SORT_DESC, $i);
    $base_chars = implode($i);
   
    switch($action) {
        case 'encode':
            $string = '';
            $len = strlen($base_chars);
            while($var >= $len) {
                $mod = bcmod($var, $len);
                $var = bcdiv($var, $len);
                $string = $base_chars[$mod].$string;
            }
            return $base_chars[$var] . $string;
        break;
        case 'decode':
            $integer = 0;
            $var = strrev($var );
            $baselen = strlen( $base_chars );
            $inputlen = strlen( $var );
            for ($i = 0; $i < $inputlen; $i++) {
                $index = strpos($base_chars, $var[$i] );
                $integer = bcadd($integer, bcmul($index, bcpow($baselen, $i)));
            }
            return $integer;
        break;
    }
}

deals with BOTH the making of the id and making sure it does not duplicate the same id twice?

can you just point out to me what part of the code will check all ids already created to stop it duplicating that id?

i know im a pain in the arse but i really want to try find a way to allow ids to be case sensitive but not allowing the same ID with different case characters to be used.

i know you dont have time to do this for me and i know it can be done (maybe it would have to be a massive edit that would fuck up all old links) but if you could tell me where the code stops duplicate ids being created then with my extremely limited knowledge and a lot of google searching i might beable to find a edit or at least realize that im unable to do this myself and can move on.
 
Ids are NEVER duplicated, when you will understand that iu is not the same as iU? You can't have what you want. Period.
 
I totally understand that, I know I must be frustrating you. I'm sorry if I'm not seeing something obvious, as I said I'm very new at php. I can bodge edit my way through code but I'm useless when it comes to starting with a blank page.

I know

/image/Fp is diffrent to /image/fP

I do understand that.

The reason behind me not wanting that to happen is some sites don't understand the difference, Reddit.com for one. That will class /image/Fp and /image/fP as the same link. It's a pain and reddits problem but I would rather work with it than against it as if by luck of the gods your site would get on the front page it could drive millions of visitors to your site and having someone try to post that image of the gods to redid and get an error saying it's allready been submitted might stop them using your site again.

A smaller problem is you can change characters case and get other peoples images easily. If in future a private upload option is added so it won't be placed in gallery and Google then having someone beable to change case and get lucky and its a link to a private image that was not mention for anyone but uploader and people they shared it to is not so good for the user.


I want links to have upper and lower case so they become harder to guess. But I don't want the links to contain the same characters in the same order but in diffrent cases.

Do you understand? I know it's a small thing and I'm being a pain in the arse and i do apoligise for that but I think for the site and the end user a system like this would be better.
 
Then just use lowercase for the id, or use a mixture of lowercase and uppercase not repeating the same letter. I posted you the code to do that. But you keep trying to make things in your own way where you don't know about encryption or how the system works.

You want to have both lower and uppercase in the encryption algorithm but that if Fp exists fP should not exists. That is impossible. The encryption works by numeric ids that are encrypted to alpha using the available chars. Use Fp instead of fP is because for the system those are different chars.

The short id never was intend to add security, is to have a non direct continued guessable image id. If reddit can't understand case sensitive then just use lowercases.
 
I feel stupid now, I cannot believe I did not think of that, That is perfect. Thanks.

So if I put base chars as acegikmoqsuwy0123456789BDFHJLNPRTVXZ

That will fix my problem, That's amazing.

That will mess up every image uploaded already right?

I guess now I have to work out if there is a simple way to get old links to will still work.

Thanks for help.
 
Yes, old links wont work because you are changing the char order.

You can do something pretty simple: Create a function that will check if the id like fP correspond to that an image uploaded before certain date. If that is the case then you show the old image by its old id, otherwise you get the next translated id.

Just my 2 cents.
 
Thanks for your help.

I will get to work google searching to find out how I would do something like that.
 
I'm 100% this is wrong.

I'm just having a bit of trouble as im very new to php.

im guessing it has to be a If....Else statement.

can you take a look at this as I'm so bad i know its wrong, just want to know how wrong I am.

PHP:
function chevereto_id($var, $action='encode') {
    $base_chars = "bcgkmqsvwy0123456789DFHJLNPRTXZ"; // DON'T REPEAT A SINGLE CHAR!
   
    for ($n = 0; $n<strlen($base_chars); $n++) {
        $i[] = substr( $base_chars,$n ,1);
    }
 
    $passhash = hash('sha256',__CHV_CRYPT_SALT__);
    $passhash = (strlen($passhash) < strlen($base_chars)) ? hash('sha512',__CHV_CRYPT_SALT__) : $passhash;
 
    for ($n=0; $n < strlen($base_chars); $n++) {
        $p[] =  substr($passhash, $n ,1);
    }
 
    array_multisort($p, SORT_DESC, $i);
    $base_chars = implode($i);
   
    switch($action) {
        case 'encode':
            $string = '';
            $len = strlen($base_chars);
            while($var >= $len) {
                $mod = bcmod($var, $len);
                $var = bcdiv($var, $len);
                $string = $base_chars[$mod].$string;
            }
            return $base_chars[$var] . $string;
        break;
        case 'decode':
            $integer = 0;
            $var = strrev($var );
            $baselen = strlen( $base_chars );
            $inputlen = strlen( $var );
            for ($i = 0; $i < $inputlen; $i++) {
                $index = strpos($base_chars, $var[$i] );
                $integer = bcadd($integer, bcmul($index, bcpow($baselen, $i)));
            }
            return $integer;
        break;
    }
}
 
function chevereto_id1($var, $action='encode') {
    $base_chars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // DON'T REPEAT A SINGLE CHAR!
   
    for ($n = 0; $n<strlen($base_chars); $n++) {
        $i[] = substr( $base_chars,$n ,1);
    }
 
    $passhash = hash('sha256',__CHV_CRYPT_SALT__);
    $passhash = (strlen($passhash) < strlen($base_chars)) ? hash('sha512',__CHV_CRYPT_SALT__) : $passhash;
 
    for ($n=0; $n < strlen($base_chars); $n++) {
        $p[] =  substr($passhash, $n ,1);
    }
 
    array_multisort($p, SORT_DESC, $i);
    $base_chars = implode($i);
   
    switch($action) {
        case 'encode':
            $string = '';
            $len = strlen($base_chars);
            while($var >= $len) {
                $mod = bcmod($var, $len);
                $var = bcdiv($var, $len);
                $string = $base_chars[$mod].$string;
            }
            return $base_chars[$var] . $string;
        break;
        case 'decode':
            $integer = 0;
            $var = strrev($var );
            $baselen = strlen( $base_chars );
            $inputlen = strlen( $var );
            for ($i = 0; $i < $inputlen; $i++) {
                $index = strpos($base_chars, $var[$i] );
                $integer = bcadd($integer, bcmul($index, bcpow($baselen, $i)));
            }
            return $integer;
        break;
    }
}
 
/**
* encodeID
* Shorthand fot chevereto_id encode
*/
if ($id<"1000")
  {
function encodeID($var) {
    return chevereto_id1($var, "encode");
} 
  }
else
  {
function encodeID($var) {
    return chevereto_id($var, "encode");
} 
  }
 
/**
* decodeID
* Shorthand fot chevereto_id decode
*/
if ($id<"1000")
  {
function decodeID($var) {
    return chevereto_id1($var, "decode");
} 
  }
else
  {
function decodeID($var) {
    return chevereto_id($var, "decode");
} 
  }


does that code even make sense?
 
You need to use the same base chars in both functions.

Im trying to change the base chars without effecting the old links.

so i hoping that code would use

$base_chars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

as base chars if the image id was under "X" value

and if the image id was "X" value or over then use the new base chars which are


$base_chars = "bcgkmqsvwy0123456789DFHJLNPRTXZ"


and from now on the script would use


$base_chars = "bcgkmqsvwy0123456789DFHJLNPRTXZ"


as the base chars for creating links
 
Actually the best way for doing this is do an iteration. You have to see your db and say "ok, id 1 to 4230 are old ids" so you run the Chevereto function for creating alpha id from 1 to 4230 and store that results in your db. Then when someone access to an /old-id you have to check if there is in that table and if it doesn't exists then you have to search it in the current table.
 
Back
Top