Click here to Skip to main content
15,905,566 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a database, and that data is private but only on a special link(randomly generated) you can access that database on the website, so the data out the database is shown on the website under taht random generated link. The part of the random generated link is done:
PHP
<pre>  function randomURL($URLlength = 8) {
    $charray = array_merge(range('a','z'), range('0','9'));
    $max = count($charray) - 1;
    for ($i = 0; $i < $URLlength; $i++) {
        $randomChar = mt_rand(0, $max);
        $url .= $charray[$randomChar];
    }
    return $url;
}

$URL = randomURL($URLlength = 8);
echo "Jouw URL is: $URL.";


So is it possible to make out of this generated key an URL: mydomain.com/generated-key, in PHP?

Thanks, Sam

What I have tried:

I searched much of google. And wrote this code with the help of forums.
Posted
Updated 2-Jul-20 22:57pm

1 solution

No, not really.
A "database name" on the web is actually the name of a database server which allows remote connections to it. In order to use a "random name" you would have to continually change the name of the DB server instance to match it and that's not a trivial task.

A better idea would be to set up a web service[^] which handles the DB for you, and which your app connects to using your "random key"

I'm not at all sure what you think you would gain from doing this though - if you can access via any random key, then so can I - so it doesn't enhance security in any meaningful way.
 
Share this answer
 
Comments
Sam Vorst 3-Jul-20 5:05am    
Allright, Do you have info how I can do this? It has not to be super secure because the data shown out of the database is only a problem and a zip code. So it doesn't matter If you can look at it, because why would you? It has to be only a webpage based on a link that is randomly generated. A one time url is also good.
OriginalGriff 3-Jul-20 5:11am    
If you want to generate a webpage based on a link, then do that, don;t mess with databases!
Two easy ways to do it:
1) Add a query string to the page address:
mydomain.com/ShowMeAQuestion.php?qid=123456567890

Then process the query string in the page load event and you have your ID for the DB query.
2) Add a 404 error catcher to your site, and process the page there:
https://www.portent.com/blog/featured/create-a-great-404-page.htm
You can get the original URL in the handler page and use that to do your DB stuff / display a "page not found" error if it's invalid.
Sam Vorst 3-Jul-20 10:09am    
Allright, thanks! I don't know how to do this and can't find a simple and understandable example. The only thing I have to know is how I make an extra part of the URL. It has to be: mydomain.com/PHP/Data-show.php/name/code (code is a text I type there is has not be random generated.) And make of that a actual page which is not visible for normal guests only for people with a link.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900