I am sending a link in parameter to a php page like :
http:// exemple.com/test.php?url=http:// i-want-to-get-this-link.com
in php Page I get this link like this :
$_GET['url'];
the problem some time the link has & symbol :
http:// exemple.com/test.php?url=http:// i-want-to-get-this-link .com/?page1&desc/otherstaff
so I only get the first part of the link : http:// i-want-to-get-this-link.com/?page1
how could I get the rest of the link &desc/otherstaff
Use urlencode on your url variable to generate the url
<?php
$url = 'http:// exemple.com/test.php?url='.urlencode('http://i-want-to-get-this-link.com');
?>
EDIT : you do not need urldecode with $_GET and $_REQUEST variables.
and urldecode to get the original URL.
<?php
$url = urldecode($_GET['url']);
?>
When you create your whole url, try to urlencode it:
http://php.net/manual/en/function.urlencode.php
then you can use:
urldecode($_GET['url']);
You can use parse_url() function to get the query, if you cannot control the input url. Try this:
print_r(parse_url($_SERVER['REQUEST_URI']));
Related
I'd like to insert part of the page url where the php function is displayed inside the brackets of the function. For example, my page's url is: www.mydomain.com/directory/**page**
I'd like to take /page and insert it inside: function(here)
Wont this do?
<?php
$url = "www.mydomain.com/directory/page";
$url = explode('/', trim($url, '/'));
print( $url[count($url)-1]);//prints "page"
//somefunc(page)
?>
Split the url by by / and select the last part of it. Then you can use it in any function.
This is a search URL generated by google:
https://www.google.com/url?rct=j&sa=t&url=http://EXAMPLE.com/example-Article/&ct=ga&cd=CAIyHjliOWMxZGQ0MzEzZDc1MWY6Y28uaW46ZW46R0I6Ug&usg=AFQjCNGoEabdV1jKNPGH8vNeiuoec_E2Iw
Now it contains a redirect URL.
http://EXAMPLE.com/example-Article/
How do I extract this URL from the above using PHP?
Solved this eventually. I used the parse_url and the parse_str functions:
$baseURL = "https://www.google.com/url?rct=j&sa=t&url=http://www.EXAMPLE.com/MY-ARTICLE-&ct=ga&cd=CAIyHjZkZjRjNDk2NTAwYWE1ZGU6Y28uaW46ZW46SU46Ug&usg=AFQjCNGT48irR-R0yx_PiiDqOHYW14bc1w"
$URLParse = parse_url($baseURL);
parse_str($URLParse['query'],$queryResult);
echo $queryResult['url'];
I'm trying to create a intermediary page, i.e user clicks on a link that leaves the site a page tells you that you're now leaving the site.
An example link would look like this:
http://example.com/transitionpage.php?r=http://www.google.com
transitionpage.php then works with a simple
$redirectto = $_GET['r'];
header( "refresh:2;url=".$redirectto );
However I'm running into the problem that if the url you're redirecting to also has multiple GET parameters in it, the domain gets cut off at the first occurrence of &
So if the link was originally:
http://example.com/transitionpage.php?r=http://www.google.com?par=1&par=2
It would become:
http://example.com/transitionpage.php?r=http://www.google.com?par=1
Which is unfavorable.
How do I pass on the full URL via GET without it getting chopped off ? Do I have to escape it ?
You can do URL encoding: http://www.w3schools.com/tags/ref_urlencode.asp
Your get query would translate to: http://example.com/transitionpage.php?r=http%3A%2F%2Fwww.google.com%3Fpar%3D1%26par%3D2
These are the PHP methods you need: http://php.net/manual/en/function.urlencode.php http://php.net/manual/en/function.urldecode.php
Use:
$link = 'http://example.com/transitionpage.php?r='. urlencode('http://www.google.com?par=1&par=2');
Use the built in function for Encoding Urls
for example
urlencode("http://www.google.com");
for function refrence
Urlencode Php
Think my current page url is:
http://example.com/id=10
In this this page has link to go other page, I want to pass current URL as a query string like this:
http://example.com/about-us/?edit=1&return=http://example.com/id=10
in PHP
http://example.com/about-us/?edit=1&return=<?php echo $_SERVER['QUERY_STRING'] ?>
but this is not working, could anyone help me to do this.
Use this (I assume you are using http only);
$currentUrl = urlencode("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
$link = "http://example.com/about-us/?edit=1&return=" . $currentUrl;
use urlencode($_SERVER['QUERY_STRING'])
It encodes the link.
Currently i using this ,
$page=urlencode($_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
which gives url without get parameters, but i need the previous page URL with GET parameters
Use HTTP_REFERER that referred the user agent to the current page
$page=urlencode($_SERVER['HTTP_REFERER']);
You have to use the Referrer header.
$_SERVER['HTTP_REFERER']
Please, keep in mind, a user can change the value of headers, so you can't "trust" it.
$url ="";
if (isset($_SERVER['HTTP_REFERER'])){
$url = $_SERVER['HTTP_REFERER'];
}
if want to send post get this as encryption the use
if (isset($_SERVER['HTTP_REFERER'])){
$url = urlencode($_SERVER['HTTP_REFERER']);
}
if you want to decrypt the url
$url = urldecode($url);
Simply used
$_SERVER['HTTP_REFERER']
You will get whole URL (with get parameters)