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.
Related
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.
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.
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.
I am new to PHP and javascript programming
I have a string that can be "abc" or "aac" or "aaa" etc based on the inputs given by the user. After the user clicks some button(say submit) I want to generate a dynamic link like www.domain.com/abc or www.domain.com/aac based on string and navigate the user to the generated link. Is this possible?
Thank You
You can actually define a function and set it your form action. Then taking the user input it will be really each in the function to use header('location:YOUR_SITE_URL/'.$_GET['user_input']); die; for redirecting the user to desired url.
Hope that helps.
Yes it is possible, you can pass the string variable throw POST or GET when the user click submit
and then echo the link you want with the string congrenated. assuming you want to use php take a look at the example
$adress = "www.domain.com/";
$string = $_POST["get_string"];
$result = $adress + $string;
echo $result;
Possible, using routing. A real world example is how your usernames get to be part of the URL in social sites like Facebook.
What you need is a database of some sort to store the string, and it's matched data (could be an ID, or some identified) to tell the server what to load when that string is received. You'd also need routing code, which parses the entire url in search of that certain segment which should contain the string. This is how routing works in frameworks like CodeIgniter, Connect and Express.
In JS, routers in Connect look like:
app.route('/users/:username',function(username){
//okay! we got the username!
//now we'll look for it in the database if it's there
});
For PHP, here's an article regarding URL parsing.
In PHP :
Use methode in your page and store the variable to $UrlName (for example)
and continued with
echo("<script>location.href = \"www.domain.com/" . $UrlName . "\";</script>");
First in page1.html:
<form method="post" action="page2.php" >
String: <input type="text" name="string" />
<input type="submit" />
</form>
Then in page2.php:
header('location:www.domain.com/string/'.$_POST['string']);
But you should put a .htaccess containing:
Redirect /string/(.+) /page3.php?string=$1 [B,QSA]
And page4.php:
echo $_GET['string'];
I want to pass an id from one page to another when user clicks a url. There can be multiple url each corresponding to a separate id. Based on url clicked, I want to pass corresponding id and an action. Currently I am using following approach:
<a href="Process.php?action=del&id='.$id.'">
However both action and id are visible in url. Is there any way to hide this information in url and not passing it through url?
Also if I pass them using hidden fields, they can be accessed using browser dev tools. I want to make them secure so they can't be read or modified at all.
I would like to hide this for security purpose so no any user can see this
In HTML only, you'll not able to pass "hidden" variables through $_GET.
If you really want to hide some variables when a user click on a link, you can use Javascript with an auto-submitted form to use $_POST variables.
Example
<form method="POST" action="yourpage.php" id="yourform" style="display:none;">
<input type="hidden" name="hiddenfield" value="__" />
</form>
<a href="" onclick="document.getElementById('yourform').submit();return false;" />
Now, in yourpage.php, you'll be able to obtain the $_POST['hiddenfield'] value.
Edit:
I don't think it can be possible to really hide the values from dev tools. Btw, you can maybe use sessions, it will be more "secure"..
Example:
// page1.php
session_start();
$_SESSION['yourname'] = 'yourvalue';
// page2.php
session_start();
$_SESSION['yourname']; // Contains 'yourvalue'
The best way to hide id(if you mean security) is to encrypt it. You should use MCRYPT function to encrypt the id. You can encrypt both ID and your ACTION in one string and just pass this string to URL and then when you want to use it you can decrypt parameter and split it. When you connect it with MOD_REWRITE in htaccess you can get url like:
<a href="Process,Some title of yourpage,í,eHGxC•z»#”“§``"> to make it more "pretty" you can use base64 on this string.
or with base64, mcrypt and mod_rewrite
<a href="Process,SWRlYW">
to decrypt string you should use base64_decode(), mcrypt_decrypt()
You can use base64 for this (if security is really a big concern). Before passing it to the URL,
you can encode it first and then in the receiving end, you can decode it.
Check this URL : http://www.webtoolkit.info/javascript-base64.html
EDIT:
Please ignore the line above in the bracket.
Based on the comments below, base64 is really not responsible for security. Better approach is to use a server sided language to encrypt/decrypt values. Using base64 through javascript is not a good idea. Thanks Bobby.