I'm creating a feature for a game and came up with a problem I can't solve on my own. I made an image generator to show the top dogs of guilds from a JS based Discord bot, the script which generates the image is made with PHP and it's on my server. I'd like to be able to call this script, without the resulting URL showing all the details - at the moment it looks like this after a call:
http://www.scam.fi/aow/im.php?m=NBA_-_TOP_3&b=ArkA&c=lenipeni&d=Sandwich&1=7334&2=6978&3=6682
(Don't be afraid of the domain name, I named my Internet storage unit badly). While all those variables are visible, that creates a problem for me since the results are pretty easily modified by anyone. Is there some way I could hide the variables with MOD rewrite or is there some other way?
Is there some way I could hide the variables with MOD rewrite
No. The data, with the approach you are taking, needs to get into the script from the browser.
or is there some other way?
Store the data in a database. Associate it with an ID. Put the ID in the URL.
Related
I have a specific requirement and am looking for suggestions on the best possible way to achieve that. I would start by apologizing if I sound too naïve. What I am trying to achieve in here is:
A) I have a parent site, say, www.abc.com.
B) I am planning to enable multisite option for it. This parent site has a area map with a number of location images overlayed. All of these images, when clicked, should lead to a subsite.
C) This subsite (has already been coded) is totally dynamic and every single information being displayed on it is being extracted from the database. It uses a session variable, which for now has been hard-coded at the very beginning of the header. This variable also decides on which database to refer to. So it will display information for different locations, based on the location selected on the parent site. Even the URL should appear per that. Say if Location ‘A’ was clicked on parent-site then the session variable needs to set to ‘LocA’ on the sub-site and the URL should be something like www.abc.com/LocA and if the Location ‘B’ was clicked then the session variable should be set to ‘LocB’ and the URL should appear as www.abc.com/LocB etc.. Trying to figure out how to achieve this. [It will have one front-end for all the locations but different databases for each location.]
I am an entrepreneur with some programming experience from my past (but none related to website designing). Because of the help from all you geniuses and the code samples lying around, I was able to code the parent site and the sub-site (using html, php, js, css ). Now the trouble is how to put it all together and make it work in correlation. Though it will still be a week or two before I get to try it but I am trying to gather insights so that I am ready by the time I reach there. Any help will be deeply appreciated.
I think the fundamental thing to understand before you get deeper is what a URL is. A URL is not part of the content that you display to the user; nor is it the name of a file on your server. A URL is the identifier the user sends your server, which your server can use to decide what content to serve. The existence of "sub-sites", and "databases", and even "files" is completely invisible to the end user, and you can arrange them however you like; you just need to tell the server how to respond to different URLs.
While it is possible to have the same URL serve different content to different users, based on cookies or other means of identifying a user, having entire sites "hidden" behind such conditions is generally a bad idea: it means users can't bookmark that content, or share it with others; and it probably means it won't show up in search results, which need a URL to link to.
When you don't want to map URLs directly to files and folders, the common approach involves two things:
Rewrite rules, which essentially say "when the user requests URL x, pretend they requested URL y instead".
Server-side code that acts as a "front controller", looking at the (rewritten) URL that was requested, and deciding what content to serve.
As a simple example:
The user requests /abc/holidays/spain
An Apache server is configured with RewriteRule /(...)/holidays/(.*) /show-holidays.php?site=$1&destination=$2 so expands it to /show-holidays.php?site=abc&destination=spain
The show-holidays.php script looks at the parameter $_GET['site'] and loads the configuration for sub-site "abc"
It then looks at $_GET['destination'] and loads the appropriate content
The output of the PHP script is sent back to the user
If the user requests /def/holidays/portugal, they will get different content, but the same PHP script will generate it
Both the rewrite rules and the server-side script can be as simple or as complex as you like - some sites have a single PHP script which accepts all responses, looks at the real URL that was requested, and decides what to do; others have a long list of mappings from URLs to specific PHP scripts.
I am using PHP script to set up a website which sells book.
Let say my website is hosted at www.sell-book-example.com.
I want to allow accessing to a book detail page by navigating to www.sell-book-example.com/book/2121.html where 2121 is the book id.
Keep in mind that book/2121.html should not exist in the document root of the web server.
As in I do not want to pre-create many book detail pages in a book folder.
I have checked some other website which are able to do that with PHP.
If anyone can provide me some sample or link, that would be great.
Thank you.
This approach is known as Dynamically generating of pages by php scripting.
You have to create a script.php file where your dynamic code will be scripted and from the url you have to catch the code and according to the code you have to generate the book detail page. All this should be done by scripting.
The url will be like these
www.sell-book-example.com/script.php?id=2121
www.sell-book-example.com/script.php?id=2122
www.sell-book-example.com/script.php?id=2123
This urls will not show in website. To make it pretty as you need like
www.sell-book-example.com/book/2121.html
You have to redirect in .htaccess file i.e. to map the urls.
For example if some one is trying to call www.sell-book- example.com/book/2121.html url than internally it will be call www.sell-book-example.com/script.php?id=2121 url and produces your book details page of 2121.
I'm building a site that that uses php and requires passing link id of each external link through the url and extracting the id using $_GET whenever a user clicks on any of the external links. Now, I need to rewrite the external url to momentarily point to my domain to enable me extract the link id before redirecting to the external destination, like what google does with search results before redirecting. Any help on how to do this will be highly appreciated.
I hope I understood what you were asking...
Have a database table of the conversions (or rather: the outside links) - the primary id can be the redirect "id".
Then have a file that you use for this outside-linking, eg "outsidelink.php".
Every link then needs to be written as outside.php?id=xxx and in the outsidelink.php you simply use the header() function to redirect the visitor (after you've recorded the fact of the request with all the details you want to; eg IP or userID, time, etc...)
Edit: oh, you first want to rewrite the external urls. I see. My bad.
Well, assuming the data where the external URL appears is some 'content' that comes from database, you need to scan the text before output for http://, compare the url (build a regex for this), if it looks like it's not matching the local host's url(s), then put it away in the aforementioned database, and rewrite the url to outsidelink.php?id=xxx
hope this time I got it right for you :)
Let me know if this question needs more clarification.
I am a front-end developer, and I usually use Wordpress with lots of custom fields to put together a CMS for clients.
A current client wants a design portfolio site that initially presents a grid of images that link to projects, but instead of loading a new page on click, the new content loads and fades in smoothly.
I figure the simplest way to do this kind of thing is to load everything up front on one page with ajax (a loading screen is OK), and then just show/hide/move content with jQuery.
The request I am having trouble with is being able to have specific URL's for different projects and images. The client wants a URL scheme like here:
http://collins1.com/work/bp-helios-house/3
Where the number at the end causes a specific image to load in the given project. It seems like this would be simple enough using php variables where like:
http://www.whatever.com?project=3&image=2
And using those to manipulate the initial AJAX load.
But how is this accomplished using a more traditional (pretty) URL structure like the example? If I am building the site as one page loading content, won't the browser attempt to load that as a page and just come up with a 404?
Bonus: How do you change the URL in the address bar to create these links as the user navigates the site without reloading the page?
Thanks!
what you see there, is called url routing. Basically, some server rule that rewrites the url in a proper way, depending on server and scripting language used.
for example, the url
http://server.com/foo/bar
MAY be redirected to
http://server.com/index.php?foo=bar
If you need a lightweight framework to handle this, take a look at www.slimframework.com
If you want real pretty urls you are going to need a server-side framework for url routing and will require you to get into php or ruby on rails. If you want a pure front end solution you can fake it in javascript using hash fragments. For how to do this see
http://backbonejs.org/#Router
http://www.asual.com/jquery/address/
http://benalman.com/projects/jquery-hashchange-plugin/
I am building a website for sharing links and pictures for php experience. Currently, each post has a page where users can comment on it. Every post also has an id that is stored in a database with it. What would be the easiest way to make this id the url of the post? For example:
For the question that has an id of 4a3cd5, I would want the url for that question to be post.com/posts.php/4a3cd5. thanks for your answers.
In the HTAccess page (.htaccess), write the following code:-
Options +FollowSymLinks
RewriteBase /
RewriteRule ^posts/(.*)/$ /posts.php?id=$1
So now, in the Address Space, if you write http://localhost/posts/4a3cd5, the user will be shown a page corresponding to the post ID of 4a3cd5. Internally, the URL which will get processed is this one http://localhost/posts.php?id=4a3cd5. This whole technique is being done by HTAccess, and this way of showing URLs to users is called SEF URLs.
More on the HTAccess tips & tricks can be found here.
Now in the page "posts.php", you can write all the logic which you want using the PHP GET Superglobal Array "$_GET['id']".
NP: A special note - please try to avoid this type of coding. Instead try using any of the available standard PHP MVC Frameworks.
That would involve a lot, maybe you should just have URL's like /posts.php/?post=4a3cd5.
Overall this would be much more practical. You can just GET the post variable and connect to your SQL database.