Php

Jim

New Member
I guess I can use this part to ask many many questions which i love to ask when learning php

q1) how can i hide the url so people dont see what subject they are on when they click a link

for example www.websitename.php .... and when they click on the website info nav bar, it still says websitename.php rather than website.php/index.php?subj=1 etc

more to come :D
 

chilly

New Member
Staff member
You can use rewriting to shorten/pretty the link a bit so instead of index.php?sub=foo you might have website.com/foo

Or you could use a frame so the headline URL in the browser never changes - however, unless you have an extremely good reason you probably should not use frames these days. They have their place but it's rarely in modern webpages.
 

Zarjazz

New Member
There are two basic ways to send arguments to a PHP page (lets keep things simple and ignore Cookies and Ajax).

The $_GET array contains the values passed via the URL request. These are visible to the user in their web browser.

The $_POST array contains the values passed via the HTTP headers. These are hidden from the user.

How you send the parameters is selected in the html form method element:

Code:
<form action="my_page.php" method="post">
Then your webpage sends the data when the user clicks the form submit button:

Code:
<input type="submit">
or maybe an image with some javascript:

Code:
<img src="nav.button.jpg" onclick="document.AddCode.submit();>"
 

chilly

New Member
Staff member
Its worth noting that moving arguments from GET to POST means it becomes almost impossible to bookmark a page properly.
 

Athan

New Member
Staff member
Or you could AJAX the thing up the wazoo so clicks don't actually take them to a new page but instead just change the content of the current one. Again, this breaks bookmarking.
 

Macca

New Member
You can use rewriting to shorten/pretty the link a bit so instead of index.php?sub=foo you might have website.com/foo
This. You can do it using mod-rewrite if you're using an Apache server that enables it. Check out http://httpd.apache.org/docs/2.0/misc/rewriteguide.html. This isn't a PHP thing, though, and I've never used anything /but/ Apache so I wouldn't be able to tell you any other methods to getting something similar done using other server software.

I don't understand why one would want the URL to remain the same no matter what page of a site you are viewing, though. This is really bad for SEO, bookmarking and proper navigation within a website... imagine someone views something interesting on your web page and wants to share it with someone else, if you just change the content without changing the URL, they would have to paste the base URL to their friend and tell them to 'click here, then click here...'. Very annoying. But yes, you can achieve that with frames, or what Ath said. Bad idea. Please don't get into the habit of doing this. :p

Apache's mod rewrite can easily be used to change a messy URL like mypage.com/article.php?id=blah into something neater like mypage.com/article/blah, if the problem is that you don't like the idea of someone seeing a horrible URL. :D
 

Deebs

New Member
Staff member
If the software is SEO aware, a quick and easy way to check is to see if you have urls like http://www.yoursitehere.com/index.php/this/is/a/seo/page/. Obvisously index.php is just an example but most webservers are configured to use index.php, surprisingly, as the index page.

If that is the case then the following would work:

Code:
for nginx:

        location / {
                try_files               $uri $uri/ @process;
        }
       # The above command says if $uri or $uri/ results in a real file then serve that file else send the request to the @process location

        location @process {
                rewrite ^(.*)   /index.php?$uri&$args last;
        }
      # Rewrite the uri and pass it to the index.php file located in the root file.
Code:
for lighttpd:

url.rewrite-once = (
"^/(.+)\?(.*)$" => "/index.php?$2",
"^/(.+)$" => "/index.php"
)
 
Top Bottom