PHP CMS web page short URL? - php

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

Related

IIS 8 URL rewrite: possible to return different results in one rule?

Windows Server 2012, IIS 8; running a combination of Classic ASP and PHP.
I think I already know the answer to this one, but just in case I'm not as smart as I think I am...
I've got a car dealership client who has created a separate page for every make/model combination they offer, ~48 pages. They would like each one pointed to with a friendly URL, e.g.
theirSite.com/shop-chevrolet-camaro-inventory
=
index.php?p=123.
This means creating 48 separate rewrite rules, and while there's nothing inherently wrong with that, it bugs me to death. Had they consulted me, first, I would have advised them to create each of these as a template file, and I would have written a program to load them dynamically, using one page and one rewrite rule.
So, it is possible for the rewrite rule to somehow dictate a piece of the rewrite result? Taking
/shop-chevrolet-camaro
where camaro translates to page 123; corvette translates to page 124; cruze translates to 125; and so on? For SEO purposes, I can't point to an intermediate page and introduce a redirect, we have to hit the destination page directly as a rewrite.
Am I out of luck?
I think that you probably still can go with your idea here of just one page and one .htaccess redirect; Just a little different approach.
You can probably use include to bring their data from one of the 48 pages and display it on your "master" page. Now, to figure out which page to pull in, I wrote an answer to a similar question here:
https://stackoverflow.com/a/21714410/3293987
Hopefully this helps you. The basic premise is to take the "friendly" name (as it is appearing in the .htaccess and pass that to the script instead of the id number. Then, in your script, you'd do a lookup by the "friendly" name instead of the id. Then you can programmatically find which page needs loaded and use PHP's include to pull in the data.
As far as your concern of having an intermediate page for the redirect, you should not need to do a redirect with this solution; You can just load the data from the existing "peripheral" page on to the "master" page.
I hope that answer helps you.

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

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).

Serving different XML content on the same web

I don't know if this is the suitable place to ask this question, so I am sorry if I am doing it wrong. I think this is not a duplicate question. If it is, I am sorry too.
Currently, I have a web app which takes its content from a unique XML document. The URL is "http://webapp.com/"
The problem is that now I have to create a second version of the web which uses a new different XML document, so I have to put them different URLs, something like the following:
http://webapp.com/activities
http://webapp.com/stages
How can I have all my sources on just one directory on server-side (I suppose it's better to maintain, the resources are cached better, etc...) but with these 2 URLs pointing to the folder and making the PHP loades the XML depending on the URL?
I suppose I have to change the .htaccess file to redirect to that folder, but how can I tell what XML I must load? And the user must see on the search bar the URL he used, for example "http://webapp.com/activities"
Can anybody help me please?
Thanks for all
You can use a .htaccess rule to redirect a URL like http://webapp.com/{anything} to http://webapp.com/?q={anything}. Then in your script you can write conditions based on $_GET['q'] and load different XML. That is if I understand your question right.

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