how to do a URL pathing(?) & .php vs .html - php

".com/watch?v=M0IDGz0QKDw" I'm a beginner and I wanna know how to do this. Can someone point me out onto where I can learn this url pathing?
And also if .php is way better than .html because php is connected to the database then what is this ".com/messages" weren't it supposed to be ".com/messages.php"
note that messages gets all messages to the database.

First -> ".com/watch?v=M0IDGz0QKDw"
it is that there is v means some variable with unique number.
And watch means in MVC architecture we have route.config file there we will configure the watch.php file.So the routing URL is like that.
Second : Yes always better to use in MVC architecture .
So try to learn MVC architecture by some frameworks like laravel, Codeigniter etc.it may help you out.

".com/watch?v=M0IDGz0QKDw"
watch is actually watch.php or watch.html, file extension is hidden from URL display.
This setting is depends on framework or .htaccess setting.
You can refer to https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/
v=M0IDGz0QKDw
v is variable name, while M0IDGz0QKDw is value.
In this case, watch page is using $_GET method to collect data from URL.
You can learn that from https://www.w3schools.com/php/php_forms.asp
HTML and PHP are different language and serve different purpose.
In short, HTML handle display, while PHP handle business flow and logic.
I would suggest you learn how to manage data with PHP first, then only proceed to configure .htaccess for hiding file extension. It will be ease for you to do troubleshoot during coding.

Related

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

A Dynamic website using PHP

I am a beginner PHP programmer. I searched google for a "Dynamic PHP website tutorials". I found some stuff. They use $_GET variable to make the website dynamic, so the URL's appear like this:
example.com/?page=home
example.com/?page=about
example.com/?page=Downloads
and so on...
But most of the dynamic websites that I found on the internet has links like this:
example.com
example.com/about
example.com/download and so on....
So how do they do so ?? Have they got folders for all the catogories ?? And Also some websites have article URLs (eg : example.com/articles/posts/2010/article1.php). It would be a reall mess if they've got folders for all items. If not then How ?? Can someone give an example please ?
If you're using apache then read: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
If you're using IIS then read: http://www.iis.net/downloads/microsoft/url-rewrite
In order to use the $_GET variable, it must be in the query string (or being routed through some other means that isn't 'default').
For example, the URLs you're using would become.
example.com/?page=home
example.com/?page=about
example.com/?page=Downloads
Additionally, you can rewrite URLs using the .htaccess file (http://httpd.apache.org/docs/2.0/misc/rewriteguide.html)
You are interested in page routing.
htaccess and MVC routing may start you down the correct path :)
To echo everyone else, it's called a url rewite.
For example, the url
http://example.com/index.php?ext=blog&cat=news&date=12122012
can be rewritten as
http://example.com/blog/news/12-12-2012
This isn't automatic, it requires defining the patterns used for understanding the new URL in a file called .htaccess which usually resides in the servers root directory. Note that the preceding '.' in the filename makes it a hidden file.
When I was first getting used to PHP i found the site http://phpbuilder.com a great help. They have a lot of articles, and a forum that is fairly nice to noobies. http://devshed.com is a good site too, and has a large amount of information on subjects outside of PHP.
You can achieve that affect with folders, but most use rewrites (Apache). It's a bit too broad of a subject to go in to here, but if you just search for rewrite tutorials you'll find some pretty quickly.
The $_GET is only to get variables from the URL. While this can be used to make sites dynamic, this is a technique which is usually frowned upon.
With rewrites, you basically have a URL like /about, but the rewrite tells your server something like "act like this is actually ?page="about"), which you then use the $_GET to process.
Being PHP beginner I will not urge you to use .htaccess, As you will need to learn lot many things before you proceed further. You have 2 option to send a request one is GET and POST. You can get more information about same on internet.
Also you have an option to start your dynamic website using CMS and I will recommend you to use wordpress. CMS will have some in-built function which will help you to do your work faster. Also using their control panel you can update the URL format.
I will also urge you to go step by step and follow every tutorial that you will find on internet.
All the best
If you want to do this you have to use .htaccess file and have to load mod_rewrite in your apache server.
In you root directory create file named .htaccess
Then Write:
RewriteEngine On
RewriteRule ^(.*)\.php$ index.php?page=$1 [L,QSA]
And After that call a page
my-page.php
It will redirected as a index.php?page=my-page internally but in browser it will show as my-page.php

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!

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

Can I make a dynamic .htaccess file?

Can I make my .htaccess be generated with php?
I would like to use php to dynamicly create my htaccess file from information from the database.
It would save me the trouble of making a new .htaccess file whenever I change a bit of my code.
You can read and write files with the file system functions, for example:
$data = <<<EOF
RewriteEngine on
RewriteRule …
EOF;
file_put_contents('.htaccess', $data);
But it would be more flexible if you use one static rule that redirect the requests to your PHP file that then does the rest.
Can you? Sure. You can create files in the filesystem with PHP so long as you have permissions.
Should you? Well, if you are only using PHP in "command-line" mode, I suppose it's as good as another scripting language. If you are doing so from a website, I would say this is a bad idea for security reasons. Another technology might be more appropriate (if you originally had XML, then XSLT would come to mind, but you're using mysql, so you'll need some other kind of script).
You definitely can generate your .htaccess with PHP if you had a backend script to do it - say in your admin area. But it seems risky and potentially unnecessary? if something goes wrong, your site will be down until you fix it - that potentially means the page you're using to generate it. Why not just create an interface that generates the new rules for you from a database, then you can have a quick look over and copy them in?
What exactly is it that you're trying to update?

Categories