I'm using PHP and I'd like to create an if statement that does something if the user came to the current page from the home page. So far, I've been using this code:
if(!in_array($_SERVER['HTTP_REFERER'], $validHomes){
//do something}
The array $validHomes contains a couple different variations of index.php (without .php, without www.)
This has been working fine but now I'd like the home page to have a GET variable sometimes which will have different values: www.example.com/index?var=5. $_SERVER['HTTP_REFERER'] treats URLs with GET variables that have different values as different from each other so I'm wondering if anyone has a suggestion for how to get around this? How can I trigger the if statement for a wide range of index URLs that contain GET variables with different values?
Thanks a lot for any help.
It would be better to add a GET parameter from your home page links and check for that parameter instead. This would be far simpler and more reliable.
Another option would be to use stristr($_SERVER['HTTP_REFERER'], 'index');
Though Matt's answer is indeed more reliable.
Related
I tried duplicating a page in Wordpress in order to translate it for local users in different countries, but for some reason, even though it's the exact same page (it even looks the same inside wordpress preview) it just breaks and looks different (seems like a css problem of some sort, probably?)
The "nice" website is:
www.blaqkdesign.com/?noredirect=true
The one i'm having problem with:
www.blaqkdesign.com/mx/?noredirect=true
Side note: "noredirect" is the command used in order to bypass IP redirection
Any ideas on what could be happening? Thanks in advance!
I found that the second one missing of themify-builder-4534-generated.css?ver=17.09.19.04.52.54, it should be named themify-builder-2534-generated.css?ver=17.09.19.04.52.54
Difference is 4534 should be 2543, please try to change if possible.
From what I understand it is possible to get query strings and clean up the url afterwards.
I basically want to send a user a link containing many types of data to build up a special page for them and afterwards clean up the url to hide the mess. I would mainly use the parameters to load certain products etc.
What would be the best way going about this? And is this even possible?
Thank you.
My thought is use two functions/links instead for this. First function/link will be that user will click and store those values in a session and transfer it to other neat URL .
I'm using the sharethis plugin in a smarty template. And in the twitter is shared link which looks so :
<span class='st_twitter_large' st_via="mediajobscom" st_url="MY URL HERE" displayText='Tweet'>
I would like to generate via javascript a url to the current page and add two parameters to the url like ?featuredid=id?featuredname=name:
http://domain.com/currentpageisurl?featuredid=id?featuredname=name
I don't have much knowledge with javascript please try to make things clear to me, especially what i need to insert to st_url="THE CODE HERE".
Any help would be very much appreciated!
Well, you can find the value for the URL of the current page in:
document.URL
You would want to assign this to a variable:
var myURL = document.URL;
and then add the parameters... the comment from Mike Bryant is absolutely correct... a parameter in a url should be like this:
http://myURL.com?parameter1=whatever¶meter2=somethingElse
as long as you are using very basic parameters (no spaces, strange characters [like quotes, amperstands, etc.]) and you know them in advance when you write the page, you can simply tack them onto the string with the + sign:
var myURL = document.URL+"parameter1=whatever¶meter2=somethingElse";
But this greatly depends on what those parameters might be, what values they are going to have, and how you are going to determine that.
It might be that these parameters get defined only when the user interacts with the page, and they might be different every time and contain really strange characters; so this simple solution might not work well for you.
Feel free to update the question if your situation is too complicated for this solution.
I've found a number of solutions on stackoverflow on rewriting urls with a variable number of variables. But wasn't able to find anything on the situation where these variables can occur in a variable order. In my case I've a page with 4 potential variables:
www.domain.com/page.php?a=var1&b=var2&c=var3&d=var4
I want my users to be able to access this as:
www.domain.com/page/var1/var2/var3/var4
So far I was able to do this with htaccess. But the problem is that not all the variables occur anytime. I want Url's like these be possible:
www.domain.com/page/var1/var2/var4
www.domain.com/page/var1/var4
www.domain.com/page/var1/var3
etc.
I think this is not possible with htaccess. But what would be the most elegant solution to use clean Url's on this one.
Hope anyone has any ideas...
I think your best shot would be to change slightly the design of your "pretty" URL. So for the URL
www.domain.com/page.php?a=var1&b=var2&c=var3&d=var4
you'd be better off having the following
www.domain.com/page/a/var1/b/var2/c/var3/d/var4
or even
www.domain.com/page/a=var1/b=var2/c=var3/d=var4
How otherwise would your script know that e.g. b and c have been omitted?
A very fine, clean URL already is:
www.domain.com/page.php?a=var1&b=var2&c=var3&d=var4
If you don't think so (I like these URLs, they are very semantic), and if you now need to preserve information about which parameter is what, you just need to keep the names:
www.domain.com/page/a/var1/b/var2/c/var3/d/var4
works perfectly with .htaccess.
I have created dynamic url's like this:
http://www.example.com/index.php?page=test
But, if I send values via GET, I cannot get the values because the URL is structured like this:
http://www.example.com/index.php?page=test?value=1
How could I get the values without using POST? This is because I use a third-party app and they only support GET.
If you create your dynamic url's like
http://www.example.com/index.php?page=test&
then you will get
http://www.example.com/index.php?page=test&?value=1
which I believe you should be able to work with. You will then just have to look for the first parameter after your initial ? as $_GET['?value'] I believe
I hope I understood the question, but you could assign a full list of variables separated with & except for the first one.
$page = 'test&value=1';
and then assign it to your url.