-2

This may sound like a stupid question, but I have to know the answer. I have seen many sites that use URLs like the following: http://www.example.com/?p=1

What file is being accessed? I have always used something like http://www.example.com/somepage.php?p=1. When the "?" is there by itself, what does that mean?

I have recently installed phpList to handle my email campaigns, and the program uses this type of URL for the subscribe page. I cannot figure out what page it is accessing though. To see it in action you can go to https://www.mylittleblackebook.com/lists/?p=subscribe&id=3.

Thank you in advance for any light you can shed on this.

5
  • You are being downvoted because that's a beginner question, sorry for that. It can be 'index.html' or 'index.php'. The remote website may also use a custom route map (Example with ASP : asp.net/mvc/overview/older-versions-1/controllers-and-routing/…)
    – Apolo
    Nov 12, 2014 at 14:32
  • I've been developing websites for 6 years now, and I have only recently come across this particular way of writing a web address. Usually the question mark follows a file name and parameters are after the question mark.
    – Greg G
    Nov 12, 2014 at 14:36
  • httpd.apache.org/docs/2.2/mod/mod_dir.html#directoryindex. This has everything to do with the server and nothing to do with php.
    – Mike B
    Nov 12, 2014 at 14:39
  • @BreyndotEchse: don't link to w3fools. They're a crap resource that only exist because they've spent a lot of time/money on SEO, money that would've been put to better use putting up actually useful/accurate content.
    – Marc B
    Nov 12, 2014 at 14:40

3 Answers 3

1

It depends of the web server that you use. If you are on Apache, the DirectoryIndex property is what you are looking for.

Here is its default value :

DirectoryIndex index.html index.htm default.htm index.php index.php3 index.phtml index.php5 index.shtml mwindex.phtml

By default (IE. no page specifically called, as in your example), Apache will search every file listed above in the specified order, and use the first one found.

Parameters are handled the same way with a file name specified or not. The default file used will be able to read them.

4
  • I though that was the case also. I figured it would default to index.html or index.php. The problem is that there is no code to process the parameters in the index.html file, yet when you go to the page, it produces a full web page.
    – Greg G
    Nov 12, 2014 at 14:38
  • When you call a php page, this is nothing else than a script that finally outputs HTML (or something else, but you see my point). For the client web browser, there is no difference between calling index.php or index.html or blabliblu.test. The only thing that matters is the format of the response.
    – OlivierH
    Nov 12, 2014 at 14:41
  • I feel stupid now. I overlooked the index.php file. Everyone was correct about it. I apologize for wasting everyone's time. Thank you for responding though. I do appreciate the explanations.
    – Greg G
    Nov 12, 2014 at 14:41
  • If you got an issue with it, for example it calls index.html instead of index.php, just change your apache config.
    – OlivierH
    Nov 12, 2014 at 14:42
1

By default you are accessing index.*. So www.example.com is same as www.example.com/index.php.

To pass any arguments, you use ? for first argument and & for any other argument. Like www.emaple.com/index.php?p=1&r[0]=2&r[1]=5. Since you can omit index.* you can write www.example.com/?p=1&r[0]=2&r[1]=5.

So www.example.com/?p=1 is accessing index.* file (most likely it's index.php).

1
  • Thank you for your succinct explanation. i do appreciate it. I figured it was a newbie question, but I had not run across it until just very recently. Thank you for taking the time to explain it.
    – Greg G
    Nov 12, 2014 at 14:45
0

Read this for further information (about ?p1=v1&p2=v2 in url):

http://en.wikipedia.org/wiki/Query_string

Examples:

http://www.example.com/?p=1

means in server side:

print_r($_GET); //Array( p => 1)

https://www.mylittleblackebook.com/lists/?p=subscribe&id=3.

means in server side:

print_r($_GET); //Array( p => subscribe, id => 3)

What file will you get according to that parameters? Those parameters does not matter if there is no php redirection according to any $_GET value.

Read the .htaccess file first to figure out the server redirection. If there is no such file, this is the rule:

  • www.site.com --> index.php
  • www.site.com/page -> page.php
  • www.site.com/dir/page -> /dir/page.php

Note that any php file can contain redirection, it can be done using meta html tag and even using JavaScript.

When the "?" is there by itself, what does that mean?

It has no additional meaning. (It can be detected in $_SERVER['REQUEST_URI'] if you want)

1
  • The question isn't about the query string.
    – JJJ
    Nov 12, 2014 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.