URL hiding in PHP - php

How do I display another url or main domain name instead of filename in php? For example suppose I am redirected to file http://example.com/myfolder/test.htm, then instead of specified url I want to display example.com in the address bar for such url. How can it be done?

you can do this with .htaccess here is a useful link.

Not with PHP, you can use Frames for that, but this isnĀ“t relay a good design I think...

This can not be done in php. PHP is server side language and the request sent is from user.
So if you want user to open http://www.example.com and show http://www.example.com/folder/script.php page use URL REWRITE.
But if you want a user who have opened http://www.example.com/folder/script.php to show http://www.example.com in address bar but still show script.php content.
On accessing script.php page redirect to http://www.example.com/ and in your index page check for referrer. If its script.php (within your own domain) just include that page.
It will be a long work but it depends what you need. Its just an idea.

Related

How to change the domain of url that the browser is showing in download page

I have a script which used to download files from my website, On downloading page of browser, it shows the url of sender. Like
If file is downloading from http://localhost/w/download.zip it shows the same url, But what I want to give is some fake domain or url, like http://www.example.com/download.zip.
Means I want to change the url or domain that the browser is reporting the download is from.
I know it can be done by this also
Download!
But it does not change the domain. And shows me another link from that my domain.
Question is : How do I do that?
If you want to show a different URL to the user when he hovers the mouse over, you could use JavaScript for it, Google itself does something similar. Here's a simple example:
Google?
The browser will show google.com when hovering over the link, but when clicked, JavaScript redirects to facebook.com and cancels the default behaviour.
Note that this won't work if JavaScript is disabled in the user's browser (very few cases nonetheless).
Demo: http://output.jsbin.com/pehehorune

How to remove path information from url?

How do I remove path inforation from a url?
For example in this url, http://stackoverflow.com/questions/ask, I want the user to only see http://stackoverflow.com. Is this possible to do?
I do a redirect in PHP from my root directory to path Foo. I don't want Foo to display in the URL.I also do a page reload of sorts using window.location.href = domain_name/foo. Similarly I don't want foo to display in the URL.
Is this possible to implment in Javascript or PHP or do I have to configure Apache to do this?
You cannot manipulate URLs in the browser's address bar using PHP or JavaScript. But you have guessed correctly, this is something that can be configured in Apache. For a primer on URL rewriting, take a look at this article.
I have seen websites that keep the user on the homepage and use AJAX to change the page content.
You should make yourself sober and then consider if you really want to hide anything and if your web site would work at all.
However, I can answer you already - it wouldn't.
We are using path information for the reason. And you'd better see it.
Read up on URL masking:
htaccess mask for my url
http://www.willmaster.com/library/web-development/URL-masking.php
etc... This cannot be handled in JS.
If you REALLY wanted to, you could do this in PHP: you would need to create an index.php page that was set up to handle the loading of other pages, and add a handler at the top of every page that detects the REQUEST_URI that sets any other link to redirect (header()) to the index page with the filepath stored in $_SESSION or another retrievable location. The index page would then render the requested page. However, this is ugly, wastes resources, and you're much better off with an apache level rewrite.

Get destiniation URL using PHP?

I'd like to redirect the user depending on the destination url and referrer url. Say I have a homepage url http://www.example.com/ and in that page there are a bunch of links that point to http://www.example.com/page/x/. When the user goes to http://www.example.com/page/ from http://www.example.com/ it should redirect to another page. But when the user goes to http://www.example.com/page/x/ via a link from http://www.example.com/ it should not redirect. In order to achieve this, the solution I am thinking is to get the destination url as well to correctly determine if the user comes from http://www.example.com/ but wants to view http://www.example.com/page/x/. Bottom line is I want to prevent access to http://www.example.com/page/ but not to its sub pages.
What you are trying to do here is scary bad.
You can't rely on the referer being returned by the browser (but it is a good indicator). You could use a generic javascript to rewrite every link on the page to append a CGI variable containing the URIencoded URL of the current page (but where javascript is enabled it won't work). Or you could put rewrite the output buffer to inject CGI vars into hrefs in PHP. Neither of these are trivial - and if they break your users will not be able to navigate.
But leaving aside the implementation for now - your solution seems to be rather absurd.
If the problem is to
prevent access to http://www.example.com/page/
but allow requests for
http://www.example.com/page/x/
Then create an index.php in http://www.example.com/page/ with something like....
<?php
header('Location: /', true, 301);
?>
Or disable auto-index on your webserver.
As it seems no one can access the example.com/page/, You can have a Header function in the http://www.example.com/page/ to redirect the page to some other page.

Avoiding cross site scripting

AM a newbie in php, i have seen some web applications that have only index.php showing on the browsers address path, when you put the mouse pointer, you would see that the links show with together with the variables required for the next page. However when you click on the link, the address bar would still show index.php. If one enters the variables directly on the address bar, then it takes you back to the home page.
How is this done?
A common way to do this is using AJAX or JQuery, allowing you to place content from other pages within an element of your mainpage, not causing a browser page refresh, while still having the same page in the url.
Using firebug extension of firefox, on the network tab, you can inspect what is send and how to the server.
This can be done with some success by checking the HTTP Referer header.
Here is a link of how to do it
Beautiful way to remove GET-variables with PHP also checke using htaccess

Is it possible to dynamically change the URL of a webpage?

I just wanted to know, is there any possible way to change the URL that appears in the address bar of a webpage dynamically? Like, maybe there are two buttons on the webpage, and when the user clicks one it will (or won't it does not matter) refresh the page and the url will be mysite.com/page1, or if the user clickes the second button, the url that appears in the address bar will be mysite.com/page2?
I do not need it to chaneg the domain, just the part after.
Just wanted to say, that I DO NOT want to go to another page. This must be done on one page. It does not matter if it is done with JS, PHP, or via the .htaccess file, but it must do this with only one page.
Outside of changing the .location you only really have control over the window.location.hash.
window.location.hash = "boo"; http://mysite.com -> http://mysite.com/#boo
This is the only way to not go to a new page while changing the URL. All other methods will refresh the page or redirect the page:
window.location redirects user when changed
window.location.pathname redirects user when changed
window.location.search redirects user when changed
window.location.hash does not redirect user when changed
You can also just change the non domain path by using a relative url:
window.location = "page1"; // include forward-slash if necessary
// goes to http://somesite.com/page1
You can definitely (and easily) serve the same page off both /page1 and /page2 and have the buttons navigate respectively to one and the other -- "refreshing the page", as you say (i.e. loading it up again from the server, or browser cache), and of course change accordingly what appears in the address bar, too. However, I don't see what's the point of doing that.
I don't quite understand what you want.
Is it that in both cases, you want the same page to be shown but with different urls ?
In that case, you could write a .htaccess file to redirect to the same page for both /link1 and /link2 and point the button to either of the links.
Just to update this question in case others come along.
This can now be handled via javascript using pushState(). There's a couple of libraries (such as History.js) that aim to ease implementation across different browsers currently without proper support. However, if you'd like see a simple usage example without the use of such libraries, feel free to check out the following article on Hawkee
Dynamically change URLs using Push and Popstate

Categories