how to get passed in function from page url php - php

I am trying to pass the id to another page so it can be deleted when the link is pressed. the Id is displaying in the url but I am having trouble, getting hold of the id, I have tried: to use the pars url but it is not working.
parse url
echo parse_url( $_SERVER['REQUEST_URI'], PHP_URL_QUERY);
link
<p>Delete</p

It is because your URL needs to be corrected to add a query string, starting with a ? and an identifier
<a href="<?php echo 'example.php/?foo='.$item->getproductid(); ?>">
Now you can either parse the URL (not necessary and unnecessarily complex for this action) or get the value from the GET array:
$_GET['foo']; // is the id in $item->getproductid()

Related

Get URL by $_GET

I need get current url (url can be different), I want send this url to email by ajax form, but I cant get right url. I use:
echo $_GET['ref']
But it return empty value.
Addition:
I have ajax form which send some data (including current url) to my email.
Yes, I use this 2 values:
$url1 = $_SERVER['HTTP_HOST'];
$url2 = $_SERVER['REQUEST_URI'];
But it return me url like this:
/cloud/abuse/abuse_mailer.php
not my current URL.
$_GET is an array containing data passed through a GET request method. If you want to get your current URL, then you can use $_SERVER; it contains server and request data. As an example:
echo $_SERVER['REQUEST_URI']; // outputs current URI of client
Or you can try:
echo $_SERVER['PHP_SELF'];

history pushstate fetch the url parameter using PHP

im trying to fetch the url parameter i pass to my current url, and i already use PHP get, post, request function to fetch, but nothing happened?
look at my code:
PHP:
echo $_POST['x'];// current page
echo $_REQUEST['x'];// current page
echo $_GET['x'];// current page
jquery:
history.pushState({}, '', 'daone.php?x=1'); // current page

How to generate a new URL using current_url in codeigniter

I am trying to use the current_url() function in codeigniter but not sure how to manipulate this data. I understand I can echo out the current_url() but how do I take each of the segments and use to generate a new URL?
I am trying to take pieces of the current page and use to generate a new URL with adding in new variable data.
I have never worked with current_url(); before, so not sure what to do. Lets say my user is on a filters page and has 2 variables to filter their results (neighborhood and category). If the user clicks on a neighborhood, how would I structure the hyperlink to pull the current url variable for the category and then insert the variable for neighborhood?
My URLs look something like:
mydomain.com/ny/find/$neighborhood/$category
Breakdown:
ny = controller
find = function
param1 = $neighborhood
param2 = $category
Any help would be much appreciated...
You can breakdown your URL by means of this:
For ny: echo $this->uri->segment(1);
For find: echo $this->uri->segment(2);
For param1: echo $this->uri->segment(3);
For param2: echo $this->uri->segment(4);
<?php //check if there is a value in uri segment 3 (param1)
if($this->uri->segment(3)){
//if there is a value there then include it in the link ?>
Link text
<?php //otherwise just go to the link for param1
}else{ ?>
Link text
<?php } ?>
This should work though depending on the exact logic needed you may have to tweak the links and also the logic in the else statements. Depending on how you want to link you may also have to add an elseif($this->uri->segment(4)) and use different logic if the user is on a page with 4 url segments.
current_url() returns a string for the actual page loaded. You can create any url you want using the segments.
Let´s say you have this current url:
mydomain.com/ny/find/$neighborhood/$category
if you want add something to this url and create a link to the user, you can make a string:
$url = base_url().$this->uri->segment(1).'/'.$this->uri->segment(2).'/newParamYouAdd/'.$this->uri->segment(4);
And then:
New url
Let me know if is this what you want.

How to pass a hash tag (#) with an address bar variable ?searchTerm=#JustKeepGoing

How can I pass a variable that contains a hash tag via a website URL?
I currently pass this information into the URL, but cannot echo it out on the new page because '#' is used to anchor/jump to a specific page area.
Can I tell it to ignore the hash tag and echo what follows it?
Current url:
http://localhost/social3/search/?searchTerm=#JustKeepGoing
Current way to echo content:
$searchTerm = $_GET["searchTerm"];
echo $searchTerm;
You have to url encode it :
http://host.com/social3/search/?searchTerm=%23JustKeepGoing
Not sure your browser won't interpret it, but worth trying.

urlencode and GET request breaks at Ampersand

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

Categories