Pass URL parameter to link - php

how can I pass a parameter in a URL to a link on the page. So we have this link setup for all visitors from Facebook.
http://www.domain.com/event?source=facebook
We need to pass the source to the end of a link on the page which leads to a booking engine and registers as a conversion so that
http://www.bookingengine.com/tickets/1234/?ticket=567&event=8910
becomes
http://www.bookingengine.com/tickets/1234/?ticket=567&event=8910&source=facebook

Use <?php echo get_permalink($post_ID)."&source=".$yoursource;?> as your link, or something to that effect.

Related

How do I remove special characters in URL codeigniter

How do I remove special characters in URL codeigniter. I really confuse why this codeigniter getting the "#" or other ('Special Characters) in href and putting it in URL.
for example:
Company
<a href='company'> Add company </a>
URL shows:
localhost/app/home/#company
Any help? thanks
Load your helper url. Like this $this->load->helper('url');
then use
url_title()
Takes a string as input and creates a human-friendly URL string. This
is useful if, for example, you have a blog in which you'd like to use
the title of your entries in the URL.
Example:
$title = "What's wrong with CSS?";
$url_title = url_title($title);
// Produces: Whats-wrong-with-CSS
# is called hash.
You click on 1 link, the hash adds to your url.
You click on 2 link, it tries to go to url#company, browser will recognize anything after # symbol as hash.
Try to avoid this by putting onClick() javascript event on button and returning false.
The change you need to make is in the company url.
Add company
The # in a url identifies a fragment within a document.

Carry over arguments to new URL

I am working with some anchor tags in HTML where i need to carry over some arguments from the first url to the second url
My Link
My current URL is - oldpage.html?arg=value
But the "My Link" redirects to -
newpage.html
and not
newpage.html?arg=value
How do i carry over the value of arg ?
If you want to just copy a known variable over, it's as simple as
<?php echo "My Link" ?>
and then oldpage.html?arg=value would produce a link to newpage.html?arg=value.
However, if you want to pass over the entire query string, you can achieve this with the $_SERVER["QUERY_STRING"] variable.
<?php echo "My Link" ?>
This will propagate the entire query string to the new page. So if you accessed the current page with oldpage.html?arg=value&color=green, the link would point to newpage.html?arg=value&color=green.
Alternatively you could use http_build_query, allowing you to add extra parameters or modify the existing query string as you see fit.
<?php echo "My Link" ?>
Using this, navigating to the current page as oldpage.html?arg=value would produce a link to newpage.html?arg=value&foo=bar.
My Link
Or you could do this:
My Link
But that is only if your server allows you to use SERVER variables.

url change without anchor tag and refresh using ajax

As per my client need , redirect the page without anchor tag and refresh page ,
and change the URL as per page appearance. I don't know any idea about this.
I can use ajax for page content. but I don't know the URL change option without
page refresh or redirect. how can I do this with ajax j-query. Any one guide me for this issue.thanks advance
sample url
www.samplesite.com/contact.php -> without anchor tag. and page refresh this url need to work on php.
I think you are looking for info about the new HTML5 History API ( pushstate ), this link has a detailed tutorial.
http://diveintohtml5.info/history.html
You can do this using below function.
if(pageurl!=window.location){
window.history.pushState({path:pageurl},'',pageurl);
}
You can use the following javascript functions
window.location.assign('http://www.samplesite.com/contact.php'); // keeps the current page in browser history
window.location.replace('http://www.samplesite.com/contact.php'); // replaces the current page in browser history
window.location = 'http://www.samplesite.com/contact.php'; // the same as assign() and is backward compatible even with the oldest browsers
jsfiddle

How to make a window pop up from a link using javascript

I am making a bookmarklet for my url shortener. What it does is it shortens the current url of a page when you click on the bookmarklet, so you don't have to go to a site to shorten a url, but what I need is for the bookmarklet to return a pop-up window with the shortened url listed below.
What I've done so far is this:
javascript:u=encodeURIComponent(location.href);s='http://n1x.co.uk/create.php?url='+u;window.open(s,'shortened','location=no,width=400,height=300');
If you have bookmarked this, you will notice when you click on it, it does shorten the url of the current page, but it also shows the url shortener webpage, and what I only need is plain text and a link to copy it.
Please help!
Edit: Sorry I'm that bad at php, but how can I make a parameter "responseType"? Thanks
What is shown in the popup is what is returned by http://n1x.co.uk/create.php. You will have to modify the php to return only the shortened url in plain text. If the php is being used by the shortener site also, what you can do is pass a parameter to create.php that tells it whether to return the whole page like it does now or to return only the plain text url. For example a parameter called 'responseType'. You can modify the create.php to say that when responseType = 'plainurl', return simply the shortened url and not the whole page.
javascript:u=encodeURIComponent(location.href);s='http://n1x.co.uk/create.php?url='+u + '&responseType=plainurl';window.open(s,'shortened','location=no,width=400,height=300');

Pass complex URL as parameter in PHP

I'm trying to pass a complex URL as a url parameter but the problem occurs if the url contains & for example I want to pass the following link as a parameter
http://www.google.ps/search?hl=en&client=firefox-a&hs=42F&rls=org.mozilla%3Aen-US%3Aofficial&q=The+type+%27Microsoft.Practices.ObjectBuilder.Locator%27+is+defined+in+an+assembly+that+is+not+referenced.+You+must+add+a+reference+to+assembly+&aq=f&aqi=&aql=&oq=
I'm trying to get a URL as a parameter from a user and redirect user to this URL.
How could I handle this in PHP?
The whole Story:
I'm trying to make some ads analytics on flash files so user submit flash ads to a website which contains a link to the required webpage.
Now,my client needs to know how many times this flash file was clicked.To solve this I 'll till every one who submits flash to write a link to my client webpage and pass the required URL as a parameter as follows
http://myclientwebpage.com/disp.php?link=www.google.com&id=16
by this way I can update my database and get a count for how many times this link was clicked
Use urlencode() or rawurlencode().
You wrote:
I'm trying to get a URL as a parameter
from a user and redirect user to this
URL.
But you didn't answer the question - how do you get that URL? How does user provide you with it? Is it written in <input type='text'/>? Or does user click some link that contains URL as one of parameters? Or is passed as ID of some URL that is stored in DB?
One case that comes into my mind - replacing URLs in plain text and sending user to some "redirecting page" before opening real page, so final page does not see HTTP referrer which might contain some secure data (e.g., session ID). In this case, you would write
<a href='redirect.php?link=<?php echo rawurlencode($url); ?>'>
<?php echo htmlspecialchars($url); ?>
</a>
instead of
<a href='redirect.php?link=<?php echo $url; ?>'>
<?php echo htmlspecialchars($url); ?>
</a>
From what I understand, you'll need to replace & into &.
$url = str_replace('&', '&', $url);
& is reserved, used for separating GET parameters, & is for writing a literal ampersand in a URL.

Categories