Passing URL (containing variables) as a string variable through URL - php

I know how to pass a simple URL as a string variable through a URL (i.e. http://example.com/?site=http://amazon.com), however I have a bit more of a complicated situation which I cannot figure out.... what if the url I want to be passing contains variables of its own? i.e. http://amazon.com/?ref=00112233&size=med ?
Background: I have a Wordpress site where I have a box to input an affiliate link, which is attached to a button that a user would click. Rather than just putting in the affiliate link so that they are sent directly to the site, I instead want to pass the affiliate link to a php script which would alter the affiliate link based on their geographic location, and then redirect them to the altered location. For example, my affiliate link is: http://amazon.com/?ref=00112233&size=med ... I want to pass that to my script, and then say if the user was from Canada it would alter the link to be http://amazon.ca/?ref=998877&size=med (switches domain and referral #) and send them to that location.
When I input the following URL to attach to my button, http://example.com/?site=http://amazon.com/?ref=00112233&size=med the redirect doesn't work..FF comes up with a msg saying the redirect is setup in a way that will never complete. The redirect works fine if the site value is something simple like 'http://amazon.com'... so I'm assuming it's because the affiliate link itself contains a ? already.
Any thoughts on how to get around this? I can't find anything that addresses this circumstance.
Hopefully that wasn't too confusing--let me know if any clarification is needed.
Thank you!

Related

How do I construct a Google Maps URL that displays street view if I don't know "viewpoint" or "pano" (only the address)?

I'm using PHP to construct a URL to google maps, a really simple little thing. I am doing it like this right now, which only falls short because it takes two clicks to get to street view (click once on link, then when arriving, click on the thumbnail of the streetview):
$map_link = '' . $name . '';
However, I'd really like the link to go straight to the default streetview in full screen without having to click the thumbnail. Looking here (https://developers.google.com/maps/documentation/urls/guide#street-view-action) they say I can use this:
https://www.google.com/maps/#?api=1&map_action=pano&parameters
where for parameters I need to include at least one or the other of viewpoint or pano. I'm not looking for a specific image, I just want the default view, so not going to be using pano. But I don't have this info. Google already knows the viewpoint (latitude/longitude) specific to an address, because it appends it to the URL automatically when you search by JUST the address! So why do they want ME to tell THEM the information THEY are the ones in possession of? Clearly there's got to be a simple way to do this without some complicated look-up process?
I feel like I should be able to obtain this view from google by passing only the address, since that is sufficient for Google to uniquely identify the address and they display the street view already on the page we land on, but I just want it to fill the screen, to save a click when arriving there. This is for an admin page, not to be accessed by end-user. If there's a way to do this not documented in the obvious place, please someone enlighten me! Thanks!
Use Maps Embed API instead which lets you place a Street View panorama on your website by simply specifying the address. To get you started, check this link and click on "Show Street View or a custom panorama" option: https://developers.google.com/maps/documentation/embed/start
NOTE: this will require a valid billing account and an API key to properly work

Php external link process

I'm building a site that that uses php and requires passing link id of each external link through the url and extracting the id using $_GET whenever a user clicks on any of the external links. Now, I need to rewrite the external url to momentarily point to my domain to enable me extract the link id before redirecting to the external destination, like what google does with search results before redirecting. Any help on how to do this will be highly appreciated.
I hope I understood what you were asking...
Have a database table of the conversions (or rather: the outside links) - the primary id can be the redirect "id".
Then have a file that you use for this outside-linking, eg "outsidelink.php".
Every link then needs to be written as outside.php?id=xxx and in the outsidelink.php you simply use the header() function to redirect the visitor (after you've recorded the fact of the request with all the details you want to; eg IP or userID, time, etc...)
Edit: oh, you first want to rewrite the external urls. I see. My bad.
Well, assuming the data where the external URL appears is some 'content' that comes from database, you need to scan the text before output for http://, compare the url (build a regex for this), if it looks like it's not matching the local host's url(s), then put it away in the aforementioned database, and rewrite the url to outsidelink.php?id=xxx
hope this time I got it right for you :)

Get top-frame (address bar in browser) URL in PHP?

I'm sorry for my English, it isn't so good...
I need help with a simple PHP program: if the page's URL contain a specific word, the content is showed. If there isn't it, the entire page redirects. I would use this to prevent me from frames that other webmasters make to "steal" my website contents.
For this is ok.. But a friend of mine need to make a black list of specific words, not a white list. So if the URL contain a word, the entire page redirects. I tried using *$_SERVER['HTTP_REFERER']* but if the "thief" put the frame on an external website that is not in the black list and after he make a frame of the frame, the content is showed and the page doesn't redirect..
So I think it's like that: *$_SERVER['HTTP_REFERER']* could read just 1st level frame and not the main page (top frame).
I really need help with this, I can't make it with Javascript because we want to keep the code not visible.
If it is not possible, is there a method to pass a JS variable value to a PHP variable for my case?
Thank you in advance!
This is only possible by javascript if and only if the top level domain is the same as yours. If that is the case, you could make an ajax call to the server, passing along the url and then the server could determine whether or not to redirect.
Instead of showing what the code would look like, I'm much more inclined to persuade you against this approach. If you have content that you don't want people to steal, you should make your site non-public (i.e. users must login). If that is not possible, the content that you are worried about sounds like it shouldn't be on the internet.

Bookmarking Ajax pages

Let's say I have a URL: http://example.com/person/list
This website will display a list of people. The list of people get very long, so eventually I build in pagination. Let's say 10 people per page. The URL looks something like this:
http://example.com/person/list?page=2
If I click the next page link, I will be taken to page 3:
http://example.com/person/list?page=3
This is good because if I copy and paste the URL to a friend, she will be directed to page 3 immediately.
Let's say that I now incorporate AJAX, and the page requests are ajax calls using jQuery. The original URL is http://example.com/person/list and when a user clicks on the next page link, the URL in the address bar doesn't change.
This is bad because if I'm on page 3, the URL in the address bar doesn't reflect this anymore.
There are multiple jQuery history plugins which will change the URL, however, these will ONLY change the portion of the URL which is after the hash mark #. Information after the hash mark is not sent to the server.
If I'm using a history plugin, the URL can be changed to http://example.com/person/list#page=2
My problem with this approach is: If someone copies and pastes this URL to a friend, when the friend requests this URL, I have no idea which page the user is intending to look at. Therefore, my best approach is to load all of the people entries onto the page, and have javascript select which page to display based on the information after the hash mark. This is a problem because I started to paginate the pages to reduce the amount of information being pulled back from the server in the first place!
What options do I have, such that I can have the back button be usable with Ajax, but also have bookmarkable links which do not require me to get all info from the server.
As I recently learned from my question you have to check the hash-part of the url after the 'friend' opened the link and fetch the content using ajax.
Or you can rewrite it on the server-side to http://example.com/person/list?page=2
You could not list anything until the page loads and then have ajax load the appropriate page.
Another option would be to load the first page as normal and then have javascript check the page hash to load the appropriate page.
For very small loads (and I assume loading 10 people is 'fast'), the second option is probably the best as it shouldn't cause too much disruption of the UI.
Option one has a downside as far as SEO goes, as search engines won't index the content if it's not loaded.

JavaScript - Basic URL rewrite + creating record in history

Here's the situation.
I have a site where clicking hyperlinks within a certain div makes a jQuery function get the content of a div from a separate page. Because of this, the URL don't change. I need it to change as well as writing an entry in history.
My pages are setup like this (not sure this is the smartest way of going though)
access.php (main logon)
new-user.php
forgot-pass.php
index.php
controlpanel.php
etcetc. Now, all of these pages are reachable on their own and are mainly identical and all contain a div called "container". When clicking links, the content from this div gets erased and the content from the coresponding div (container) gets loaded from the file of the URL (href). I'm terrible at explaining..
So basically, what I need is some javascript that picks up the href link address and just pastes it in the url bar at the same time as it creates an entry in history so the back and forth buttons work.
I plan on extending this in a while as well, translating query strings as well. But there are a few constant static pages I need to take care of first. Any help would be very appreciated! :)
You are not allowed to change the entire URL by JavaScript but you can use URL hashes. I recommend you the browser history plug-in. You can simply register a handler to react on URL changes and load your corresponding content via ajax.
Have you looked at the jquery address plugin? Look at the examples. Is this similar to what you want?
It's not possible with "normal urls" (we must wait for a new generation of browsers...)
But there is a "trick": playing with anchors.
A link like "same_page.php#anchor" does not reload the page, but act on both the history and the adress bar.
So, if instead of having url like "page.php?param=lorem", you could have "page.php#param=lorem", you have your solution :)

Categories