PHP Keeping URL parameters when clicking a hyperlink to add GET variable - php

I'm trying to figure out how to have a hyperlink that will add a new/additional GET variable to the URL, but will not remove any existing GET variables or anchor tags. So, if my URL is any of the following:
http://example.com/index.html?color=blue
http://example.com/index.html?color=blue&type=shirt
http://example.com/index.html?color=blue#reviews
...and I click the link, such as:
Large
... the URL should be updated to:
http://example.com/index.html?color=blue&size=large
http://example.com/index.html?color=blue&type=shirt&size=large
http://example.com/index.html?color=blue&size=large#reviews
Right now, if I make a link as above, it will remove all existing GET variables and anchor tags from the existing URL.
What's the fix?

You can do something like:
Large
See QUERY_STRING.

much like Samsquanch's answer but try replacing SERVER with GET
Large

Related

php how to pass an anchor in the command line

I need to pass parameters and an anchor in a php program to make sure the cursor is positioned at the last place it was in the page when it returns.
program.php?ID=123&ID2=456#777
ID=123
ID2=456
html anchor is #777
Can someone tell me how to make this work? Since it isn't working the way I'm doing it now. Thanks
The browser will not send the anchor to web server.
So PHP can't get the anchor from url.
maybe you can use javascript to request program.php?ID=123&ID2=456&anchor=777, then you can get the anchor by $_GET['anchor'].
Sorry for my bad english (愒o愒).
If you want force the cursor to the position.
this code will redirect to http://website.com/page.php#anchor and the broswer will auto cursor the position.
<?php
header("location: http://website.com/page.php#anchor");
exit;
warning: take care about header function, there is the manual header function
If the current page is the same as the redirect page, above the code will infinite redirect and the browser will throw error. So you have to write some logic, make it redirect when you want. Or just write two different page, one to show content, other one redirect to content page with anchor.
But I still think it is better to do that by JavaScript.

scroll down to specific div id on page from inside a php redirect function

I have a redirect function which works, and inside it I'm using a variable that tells it where to link to.
redirect_to($url);
For a couple times I need to use this function, however, I want it scroll down to a certain div id on the page, which I think is usually something like:
scroll to comments
I just don't know the proper way to combine that with the php function I'm using above. Everything I've tried just gives me a syntax error.
Any help would be greatly appreciated!!
If you have an anchor defined try:
$anchor = '#comments';
redirect_to("{$url}{$anchor}");
Give it anchor an id then ur redirect will be 'header("url#idname")

Anchor to a section with CodeIgniter

i'm trying to create an anchor to a page's element. There's a tab interface. In html i can see that their links are like this:
http://example.com/index.php/service#tab-1
http://example.com/index.php/service#tab-2
http://example.com/index.php/service#tab-3
http://example.com/index.php/service#tab-4
So that i have 4 div's with id's tab-1,tab-2 etc.
How can i create anchor to them from another view file? When i try this:
give it a try
it goes to page /service but not focused on #tab-1 . It was working on plain html, but i couldnt do it with codeigniter
Thanks for help!
I just tried the same thing on my CodeIgniter and it worked fine so I suggest double checking your IDs are correct. Other than that try
give it a try
or
give it a try
You need to put the target of #tab-1 etc. in your page. So in your div you need to include a named anchor such as:
<a name="tab-1"></>
This will cause the page to jump to this element.

Can I modify anchor tag href in htaccess?

Not sure if this is possible but wanted to know if htaccess has a trick...
Say I have anchor tag href like this -
Click here
I have changed the URL structure using mod_rewrite but wanted to know if i can hide the actual URL in href using htaccess.
i.e when a user hover over the anchor tag, the browser displays http://example.com/index.php?id=12345 at the bottom. All I want the browser to display is http://example.com/index/12345 without changing it manually on all my pages.
Thanks for the help !
Why don't you change the link to the following?
Click here
As you can change the .htaccess I expect that you own or adminstrate this domain. So it should be possible.
If the links are generated by PHP code, then I suggest you to implement and use a translation function like:
function beautify($ugly) {
// your logic comes here
return $nice; // ;)
}
... and wrap it around the existing code that currently outputs the urls. This would have two advantages:
It's easy and more failsafe to migrate to the new url scheme
From now on you have control over all url related code using a single function
I agree, htaccess can't help you. I guess you'll have to change them manually.
I wish I could be of more help
No. htaccess is for processing input to the web server, not data sent back from the server.
If you use jQuery you could have it rewrite the href when the page loads using something like this.
$(function(){
$("a").each(function() {
this.href = 'some_new_url that you made based on the one in this.href';
});
});

php open dynamic link in new window with iframe

Hello I am trying to figure out how to make it so when someone clicks a link on my search results it will open in a new window and in the new window have an iframe that displays the url. I am not sure how to go about doing this. I have
$row['url']
that displays the url for each result to use.
To be more specific I am trying to do what filestube does. I like the feature a lot and would like to use something like it on my site. Here is an example url to show you want I mean http://www.filestube.com/5a4c10249bd9fce003e9/go.html
when the link is clicked on filestube it will open a page like this. I have seen lots of sites do this but filestube is what pops in my head right now. Can anyone provide me with a code example or try to explain how to do this? thanks.
You need to redirect to a URL inside of your application, example my_url.php and post to it in parameters the URL you want to show. Than in that script, load an iFrame with that URL.
Example of my_url.php?url=http://www.google.ca:
<div>You Header</div>
<iframe src="<?php $_GET['url']"></iframe>
<div>Your Footer</div>
The link should point to another PHP page. Something like this.
http://www.google.com
In your open-link.php, write your iframe code.
<iframe src="<?=$_GET['url']?>"></iframe>
Assuming you have PHP file named external.php
Make that PHP file accept a $_GET parameter.
Pass the URL as a param
Use that URL to point the iframe in that PHP file to whatever URL is passed

Categories