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.
Related
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']));
how can i take the link of the page that i am on with its variables ?
example i have the page link is
article.php?article_id=10&article_title=title&lang=ar
when i use the $_SERVER['SCRIPT_NAME'] variable it takes only article.php
and im rewriting the url as well so it looks like this
article/10/title/ar
what i want to do is just make a link that is to an English page so im trying to make it look like this
article/10/title/en
how can i do that?
Since the data looks like its passed with a HTTP GET method, you can use this
$_GET["lang"];
This returns the value assigned to "lang"
$_SERVER['QUERY_STRING'] will have all the parameters. You can also check $_SERVER['REQUEST_URI'] and that should contain the whole url, file and parameters.
Something like:
$params = $_GET;
$params['lang'] = 'en';
$link = basename($_SERVER['SCRIPT_NAME']) . implode('/', $params);
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)
I am working on a wordpress website which has thousands of pages and the owner has entered an affiliate link for each page via a custom field named: afflink
The affiliate link is outputted on the page using:
<?php echo get_post_meta(get_the_ID(), 'afflink', true) ?>
The user clicks the link which sends them to a page called go.php
The link looks like this:
www.mysite.com/go/go.php?url=http://www.somesite.com/redirector.aspx?aid=334&cid=2502&tid=3
Within the go.php page is the following meta refresh tag:
<meta http-equiv="refresh" content="5;<?php echo $_GET['url']?>
" />
However, when the page refreshes it sends us to just:
http://www.somesite.com/redirector.aspx?aid=334
How can i fix this?
You should use urlencode before printing link to the user, not after he clicks the link:
$link = "http://www.somesite.com/redirector.aspx?aid=334&cid=2502&tid=3";
echo '' . $link . '';
[+]
I strongly recommend writing some script that will change existing entries with proper ones. If all of them starts with www.mysite.com/go/go.php?url= then you can replace it with nothing in database, add this part to your meta tag and echo urlencoded link from db.
Any other solution will be just a kludge. One of it is to recreate original url from the rest of GET parameters in go.php:
$url = $_GET['url'];
unset($_GET['url']);
if ($_GET) {
$url .= '&' . http_build_query($_GET);
}
You're misusing URLs.
Your URL is parsed like this:
Path: go/go.php
?
First query string argument: url=http://www.somesite.com/redirector.aspx?aid=334
&
Second querystring argument: cid=2502
&
Third querystring argument: tid=3
Instead, you need to URL-parameter-encode the inner URL.
No need to urldecode a GET or REQUEST variable, they are automatically decoded:
http://php.net/manual/en/function.urldecode.php
by having an URL like this: mysite.com/subfolder/helloworld - Is it possible to read the "helloworld" from within a PHP page?
I would like to use the string as a part to load some content.
end( explode( '/', $_SERVER['REQUEST_URI'] ) )
without the end() call it will give you all the parts of the URL
You should read about URL rewriting.
This is more clean than "reading" the current URL. Basically you can redirect your URL (transparently) to something like :
mysite.com/index.php?folder=subfolder&category=helloworld
Then in PHP, you can access the URL parameter with :
$folder = $_GET['subfolder']
$category = $_GET['category']
This is maybe not the kind of answer you were expecting, but it can be interesting to know.
The request url (everything from the first / after the domain name) can be found in $_SERVER["REQUEST_URI"]
Hello have u used 'strstr' keyword of php?
please try like this
if(strstr($_SERVER["REQUEST_URI"], "helloworld"))
return true;
else
return false;
May be this will be helpful to you.