Dynamically display content based on web address after '/'? - php

I am wondering if this is possible with PHP, or if not with ASP since it's relatively similar and I could pick it up quickly. Let's say I have a text input for a user to search a database; as an alternative to using the text field I want a user to be able to go to 'www.examplesite.com/SEARCHTERM'. Is this possible? I've seen it done, but I can't figure out how. Thanks!

You might have to look in to url rewriting based on the server you use.
URL Rewritting

This can be done:
1) Using $_GET
www.examplesite.com/?SEARCH=SerachTermHere
In the page you can get the search variable with $_GET['SEARCH']
2) Using URL Rewritting

Yes that's easily possible. For example if you have apache server then you can enable mod rewrite and write one rule to redirect all such requests to your script in a variable and it will then handle accordingly

It is possible, you have two options.
Using URL Rewritting in your server configuration.
Using $_GET global. Everything in URL after your actual page address is available through $_GET.
This goes a bit beyond your question but might prove to be very useful. Even though it is a framework, you might want to look at Symfony 2 routing for ideas how to implement it. Specifically at "Under The Hood" section. You can even explore their routing code on github. Applications made in it have exactly the form you are searching for (content displaying based on $_GET data).

Related

I like to change my id number to my post title in php

I am using this function in php
http://domain.com/page.php?do=post&id=124
but i wish to change this URL to
http://domain.com/page.php/this is first post.html
How can I change this URL?
You need to have knowledge of .htaccess to accomplish this.
What you need to achieve here is URL Rewriting.
What is "URL Rewriting"?
Most dynamic sites include variables in their URLs that tell the site
what information to show the user. Typically, this gives URLs like the
following, telling the relevant script on a site to load product
number 7.
http://www.pets.com/show_a_product.php?product_id=7 The problems with
this kind of URL structure are that the URL is not at all memorable.
It's difficult to read out over the phone (you'd be surprised how many
people pass URLs this way). Search engines and users alike get no
useful information about the content of a page from that URL. You
can't tell from that URL that that page allows you to buy a Norwegian
Blue Parrot (lovely plumage). It's a fairly standard URL - the sort
you'd get by default from most CMSes. Compare that to this URL:
http://www.pets.com/products/7/ Clearly a much cleaner and shorter
URL. It's much easier to remember, and vastly easier to read out. That
said, it doesn't exactly tell anyone what it refers to. But we can do
more:
You can find more information here.
You have to perform url rewriting. Its a technique for you you need to configure your .htaccess file.
Check this for Details

PHP - Getting information from link itself rather than GET parameters?

Consider a situation of a URL as:
www.example.com/softwares/download.php?f=firefox&v=13
It does not look as good as URL:
www.example.com/softwares/firefox/download?v=13
or same download.php used as:
www.example.com/softwares/chrome/download?v=20
How can I achieve this type of URL filtering in PHP?
Some point I want to covered here:
I don't need a folder-hierarchy here like having different folders for /firefox/ and different for /chrome/
There could be only two PHP files (as I wish to) for all products: /software/software-info.php and /software/download.php (already got here).
I am able to put and fetch information from database in PHP but just want to have different link for different product.
I am a Java Web Developer in which you have Filters to get information from a part of link and redirect the request accordingly.
I am new in PHP programming and if this question is already asked or obvious than please pardon me and provide that question link.
This is ideally what you should use url rewriting (mod-rewrite in .htaccess) for.
Your visitor navigates to:
www.example.com/softwares/firefox/download?v=13
or even
www.example.com/softwares/firefox/13/
but your server will understand it as:
www.example.com/softwares/download.php?f=firefox&v=13
You can use htaccess files to do URL rewriting. Essentially this would allow you to take the segments of the url after /software/ and pass them ass parameters to be controlled by the software script.
There are also a bunch of PHP frameworks which use 'routes'. They're based on a similar principal as URL rewriting. I'd recommend Codeigniter as a good starting point - it's a straightforward framework, which plenty of documentation and tutorials.
Good luck!

PHP CMS web page short URL?

I am buildiig a simple CMS and would like to know how to create short URLs (not the APACHE bit but the PHP bit).
example.com/?page=100
example.com/home/test
How would I interpret the ?page=100 into /home/test (Through select the database, but i couldn't figure out how) I can see if just one level /home/test because you probably can have a zoneID, but when it comes to /home/test/test. I become lost
And how do I parse back the /home/test to the page id.
Plus is there anyone can show a bit idea for the database design as well?
These resources can be useful to you:
https://stackoverflow.com/a/120411/370290
http://www.symfony-project.org/book/1_0/09-Links-and-the-Routing-System
http://codeigniter.com/user_guide/general/urls.html
http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/
You need some kind of mod_rewrite for your server side.
That will help you to send route data to index.php (or somewhere else) file without filename in adress string. Than some php file will analyze the route and give correct html.
ok i think you need to definitely need to look at the way you are going to do your routing (through mod_rewrite)..for example
1.you can rewrite the page www.example.com/test to ..www.example.com/index.php?page=test and implement a way of getting page by the page name..and returning an id if a page name exists ..if multiple entries exist then maybe the last modified will be given precedence over the otheers ..you can get the following book CMS Design Using PHP and jQuery helped me alot

how to tell if a site is made with cakephp

can you tell if a site is made with cakephp, how,
how to check it - to check any folders, initial pages , to see some specific queries ?
Maybe this CMS detector can help you. HTTP headers in many cases reveal a lot about technology used to power a site.
1) find a form on it, if it has values in the format data[Something][whatever] chances are its cake
2) url format is normally /something/anotherthing/id and a lot of times there will be some urls like /pages/something, also wont often find extentions in the url
3) check the name of the main css file, some people wont change it, cake.default.css iirc
4) try going to a random url and see what the error looks like, default cake will be something like "Error: The requested address '/sdfsdfsfsd' was not found on this server."
5) if the url is site.com/something/etc and you can go to site.com/index.php?url=/something/etc
obviously these can all be done on any system, but its a pretty good giveaway if the all/mostly work
You can use WhatWeb which is created for this purpose and has a plugin for cakephp.
You can use the tool I made called PageXray, it can detect CakePHP apps.
http://pagexray.com
It uses some quick Curl techniques to check if files exists, if some css or images are in webroot and also checks the page's header for some CakePHP signatures.
Then for a list of sites that was made with cakephp, check this out.
http://pagexray.com/technologies/php_cakephp.htm

Create Pages Automatically

Is there any method in Php by which I can create a page automatically based on a predefined template. Like if we create a new post in blogger it automatically creates page for that post with the name of that post, like this one:
http://learntoflash.blogspot.com/2009/12/exit-button-in-flash.html
Here Exit Button In Flash is the name of my post I have written and an automatic page is created for it.
Or like here on this website if we ask a question it automatically creates a page for that question. I want to know can I achieve this in Php or anything close to this ?
...here on this website if we ask a question it automatically creates a page for that question.
It sounds like you may believe an actual file is created when you post a question. My bet would be that this page is generated via the question id in the URL.
The only files created would be cached output, which may or may not resemble actual HTML pages.
You should use URL rewriting. This Apache module lets you define rules to rewrite web addresses in your desired way.
The process to make your web application ready for this, is not a short story so you should read more about it.
This article is a good starting point:
http://articles.sitepoint.com/article/guide-url-rewriting
This is acheived by using mod_rewrite. A good place to look for inspiration is the .htaccess used in Wordpress.
to something like that you have to grasp the very fundamental in php or any programming language at all, i mean the core of php is to create dynamical generated pages based on user/browser input.
You might need to take a quick tutorial about php might I suggest http://www.tizag.com/phpT/
good step for step tutorial
Edit:
if you're wondering how the websites seems to have created a html page for every question, the answer would be they're not they are probably using mod_rewrite as mentioned before to rewrite to url to print a little more user friendly url, the actual url could be something like this https://stackoverflow.com/index.php?post=4499289 in reality

Categories