473,326 Members | 2,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

how to hide file name (.php)

hi,
I see that it's easy to create a navigation like index.php?id=1, index.php?id=2... then you can hide the current part you are in. But I need a further step (as I've seen many), hope it's easy enough, that how can hide the file name index.php so that the above links become simple "?id=1, ?id=2... if so, that'd be great :)
Dec 26 '07 #1
14 3621
Markus
6,050 Expert 4TB
Ok lets use
[php]
www.example.com/index.php?id=1
[/php]
for the demonstration url.

If you want to hide the 'index.php' name just cut it out

i.e:
[php]
www.example.com/?id=1
[/php]
Remeber to keep the forward slash - / - in there.

Note, this will only work for index pages as index pages are the default catch pages for browsers.

[php]
www.example.com/some_directory/index.php?id=1
//becomes
www.example.com/some_directory/?id=1
[/php]
So on and so forth.

Hope this helped :)
Dec 26 '07 #2
nathj
938 Expert 512MB
hi,
I see that it's easy to create a navigation like index.php?id=1, index.php?id=2... then you can hide the current part you are in. But I need a further step (as I've seen many), hope it's easy enough, that how can hide the file name index.php so that the above links become simple "?id=1, ?id=2... if so, that'd be great :)
Hi,

There is a realy neat and easy way to do this without loading loads and loads of directories that you don't wan't. The directories don't really hide where the visitor is they simply move it.

If you check out www.just10northeast.org.uk you will see the following outline in operation.

Every link calls a JavaScript function via the onclick method. This is instead of a normal href property.

The function takes a number of parameters, the first is the main control parameter which is used by the function to determine where the required page is defined. The second is anything the page definition requires and the third is the ID of a div on the main page.

Then using the first parameter the relevant page is determined and this is accessed using the XMLHTTP object with the secind paratmter in the query string which returns the definition and the JS function then writes this return to the div whose ID was supplied as the third parameter.

So this uses AJAX to solve the problem and it means that the URL is always the same and the site never reloads a full page but only part of it making it quite swift.

The key term for research here is AJAX.

If you want some more specific help then let me know and I'll happily look over any code for you and even help with a bit of development.

Cheers
nathj
Dec 26 '07 #3
hi,
I see that it's easy to create a navigation like index.php?id=1, index.php?id=2... then you can hide the current part you are in. But I need a further step (as I've seen many), hope it's easy enough, that how can hide the file name index.php so that the above links become simple "?id=1, ?id=2... if so, that'd be great :)
Along with the first answer, you can also use a neat trick called mod_rewrite. It's a little bit advanced, but if you want to try it you can go to http://www.workingwith.me.uk/articles/scripting/mod_rewrite
And make sure that in httpd.conf (apache config file) AllowOverride is set to "All", so the line containing AllowOverride (without a # sign before it) should say "AllowOverride All".
Hope that helped.
Dec 26 '07 #4
thanks for all, you guys are so kind :)

if it's to work only then one of the above is enough of course, but I want to discover something new so the method involved AJAX would be great. if u don't mind, so tell me how?

again, thanks for your great help :D
Dec 27 '07 #5
realin
254 100+
why not try URL rewriting, if i understood your problem correctly.
Also you can edit .htaccess to hide the technology you write the files in. You can rename your file as index.pl and then some editing in .htaccess will treat .pl as .php , resulting files will compile as php files

If i misunderstood you then i am sorry

Cheers !!
Dec 27 '07 #6
nathj
938 Expert 512MB
thanks for all, you guys are so kind :)

if it's to work only then one of the above is enough of course, but I want to discover something new so the method involved AJAX would be great. if u don't mind, so tell me how?

again, thanks for your great help :D
Hi,

It's always good to learn something new so I've no porblem explaining the way I achieved this.

First of all you need a few JavaScript Functions.
Expand|Select|Wrap|Line Numbers
  1.  
  2. /*------------------------------------------------------------
  3.     GENERAL AJAX FUNCTIONS
  4. ------------------------------------------------------------*/    
  5. function writeResponse(poXMLHTTP, pcEmelentID) 
  6. {        
  7.     if (poXMLHTTP.readyState==4 || poXMLHTTP.readyState=="complete")
  8.     { 
  9.         if (poXMLHTTP.status == 200)
  10.         {
  11.             document.getElementById(pcEmelentID).innerHTML=poXMLHTTP.responseText ;  
  12.         }
  13.     } 
  14.  
  15. function GetXmlHttpObject()
  16.     if (window.XMLHttpRequest)
  17.     {
  18.         loXMLHTTP=new XMLHttpRequest() ;
  19.     }
  20.     else if (window.ActiveXObject)
  21.     {
  22.         loXMLHTTP=new ActiveXObject("Microsoft.XMLHTTP") ;
  23.     }     
  24.     if (loXMLHTTP==null)
  25.     {
  26.         alert ("Browser does not support HTTP Request")    ;
  27.          return    ;
  28.     }
  29.     return loXMLHTTP ;
  30.  
  31. function submitXMLHTTP(poXMLHTTP, pcIDToWriteTo, pcOpenMethod, pcURL, plOpen, pcSendData)
  32. {                                                                                        
  33.     poXMLHTTP.onreadystatechange = function() 
  34.     { 
  35.         // use of ghost function enables the system to execute each item in the correct order
  36.         writeResponse(poXMLHTTP, pcIDToWriteTo); 
  37.     };
  38.     poXMLHTTP.open(pcOpenMethod,pcURL,plOpen) ;
  39.     poXMLHTTP.send(pcSendData) ; 
  40.  
  41.  
  42.  
  43. /*------------------------------------------------------------
  44.     MENU/DISPLAY HANDLING FUNCTIONS
  45. ------------------------------------------------------------*/    
  46. function menuHandler(pnType, pnMenuID, pcWriteToID)
  47. {                                                  
  48.     if(trim(pcWriteToID) == "")
  49.     {
  50.         pcWriteToID = "mainContent" ; // default value
  51.     }
  52.  
  53.     // instantiate the XMLHTTP object
  54.     loXMLHTTP = GetXmlHttpObject() ;
  55.  
  56.     lcBaseURL = "pagedefinition/" ; // this is the directory where all the page definition files are stored
  57.  
  58.     // determine which URL we are loading to handle this menu selection
  59.     switch(pnType)
  60.     {
  61.         case 1: // Main content  
  62.             lcURL = lcBaseURL + "maincontent.php?page=" + pnMenuID ; // I then use the ID from the query string to select data out of a table. This may not be necessary if each page is static 
  63.             break ;
  64.         case 4: // downloads                   
  65.             lcURL = lcBaseURL + "download.php" ; // not all pages need this query string but the call to this function would still requie the middle parameter
  66.             break ;
  67.     } 
  68.     /* this is just a sample, I have about 9 different definitions in here. Most pages however use the first case as the page is fully definied in my database. As this is a switch statement you can add as many as you like*/
  69.  
  70.     submitXMLHTTP(loXMLHTTP, pcWriteToID, "GET", lcURL, true, null) ;
  71.  
Then in you html file - index.html you would have a section, I use <div> with the ID that is submitted as the third parameter, in my case this is mainContent

An example link would look like:
[html]
<a title="Link tool tip" onmousever="this.style.cursor='pointer';" onclick="menHandler(1, 1, 'mainContent');">Link Text</a>
[/html]


The advantage of this system is that because the output section is a parameter you can use to retreive the definition of any section on your page. Also because the page definition file is located based on and paramter this is fully customisable. The middle parater can then be used to get an exact record from a database and so if you have a database you can use one file to define multiple pages by having the pages defined in the database.

Well there you have it. I've given away some code for you so I hope this will help you ti understand what is going on.

Have a play around with this and if you have any further questions just let me know.

Cheers
nathj
Dec 27 '07 #7
why not try URL rewriting, if i understood your problem correctly.
Also you can edit .htaccess to hide the technology you write the files in. You can rename your file as index.pl and then some editing in .htaccess will treat .pl as .php , resulting files will compile as php files

If i misunderstood you then i am sorry

Cheers !!
I already said that, mod_rewrite.
Dec 27 '07 #8
hi,
I did have some tries and find mod_rewrite definitely useful, but I still wonders:

if the browser understands, say, www.site.com/page/download as www.site.com/index.php?id=5 so how can we still use the value $_GET['id']?, for which we have another purpose?

the second question, we change site.com/index.php?page=download into site.com/download, so how about site.com/index.php?page=download&action=get, for example?
Dec 28 '07 #9
Markus
6,050 Expert 4TB
To answer your second question
using the same technique you used for mod_rewrite previously, make the url: www.site.com/download/action/get

Not sure about your first question

what are these 'other purposes' you spoke of?
Dec 28 '07 #10
Hi, if you are looking for something like this where the id is dynamically generated at runtime:

site.com/page/download/action/get/id/4875
which would translate to:
site.com/index.php?page=download&action=get&id=4875

To do this try something like this in your htaccess:
Expand|Select|Wrap|Line Numbers
  1. RewriteEngine on
  2. RewriteRule ^page/download/action/get/id/(.*) index.php?page=download&action=get&id=$1
  3.  
Then in your php script that generates the link just do something like:

Expand|Select|Wrap|Line Numbers
  1. <a href="page/download/action/get/id/<?= $some_id ?>">Download</a>
  2.  
From here you can simply access the url segments from the $_GET array
Expand|Select|Wrap|Line Numbers
  1. <?= $_GET['action'] ?> or <?= $_GET['id'] ?>
  2.  
One last thing. If you need totally dynamic urls just write a rule to point everthing but images, js files, css etc to index.php and then you can split the url on the forward slash and access the segments that way.

I hope that helps you out
Dec 28 '07 #11
Markus
6,050 Expert 4TB
RewriteEngine on
RewriteRule ^page/download/action/get/id/(.*) index.php?page=download&action=get&id=$1
[/code]
I believe, if you wanted the url's appearence to stay the same, you'd have to add [L] to the end of the Rule

i.e.
Expand|Select|Wrap|Line Numbers
  1. RewriteEngine on
  2. RewriteRule ^page/download/action/get/id/(.*)
  3. index.php?page=download&action=get&id=$1 [L]
  4.  
:)
Dec 28 '07 #12
I believe, if you wanted the url's appearence to stay the same, you'd have to add [L] to the end of the Rule

i.e.
Expand|Select|Wrap|Line Numbers
  1. RewriteEngine on
  2. RewriteRule ^page/download/action/get/id/(.*)
  3. index.php?page=download&action=get&id=$1 [L]
  4.  
:)
That is just to let apache know that it is the last rule. The code works fine. I may be missing something, could you explain what you mean by "if you wanted the url's appearence to stay the same".
Thanks
Dec 28 '07 #13
Markus
6,050 Expert 4TB
To keep the url from changing from www.site.com/action/get/id/3223 to www.site.com/?action=get&id=3223

The best example is myspace
www.myspace.com/user_name this is how the url looks but essentially its www.myspace.com/?user=user_name


Sorry.. im tired. hha. :)
Dec 28 '07 #14
To keep the url from changing from www.site.com/action/get/id/3223 to www.site.com/?action=get&id=3223

The best example is myspace
www.myspace.com/user_name this is how the url looks but essentially its www.myspace.com/?user=user_name


Sorry.. im tired. hha. :)
Thanks markusn00b, I'm not an expert with mod rewrite :)
Dec 28 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Els | last post by:
If I use <? include "file.html"; ?> in the html of my document, do I _have_ to change the extension of that document to .php, or would it still work and be valid if I let it remain .html? --...
4
by: thehuby | last post by:
How do you get the name of the currently execting script? By this I mean the name of the include file that is being executed: File: include.php <?php //Call some function to display...
18
by: walterbyrd | last post by:
I am trying to develop an app where: the same file, in the same place, will be uploaded, and then processed. Everything I can find about uploading a file, uses a form that requires the user to...
6
by: Olumide | last post by:
Hello - This has probably been asked before, but I would like to know when its best to name a file with either extension. Thanks, - Olumide
5
kamill
by: kamill | last post by:
I need to hide name of web pages from URL, I need to show only domain name of web site, and want to hide the name of web pages after slash. Example insteade of www.mysiteabc.com/anyfile.php, i...
0
by: aris1234 | last post by:
how to rename file name in DB..??? this my code, but this code only save image to folder, can't rename file in DB : <?php //Сheck that we have a file $folder = "../property/$spid";...
1
by: crazychrisy54 | last post by:
Hi there Using an XML file containing customer elements: <customers> <customer> <namebob </name> </customer> .... ... </customers>
4
by: liberty1 | last post by:
Hi everyone. I appreciate your effort at helping newbies like me. I have the following problems and will appreciate urgent help. PROBLEM NUMBER 1: Using PHP and MySQL, I am able to upload...
12
by: impin | last post by:
this is my upload.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.