I am trying to create a conditional template in wordpres where the condition should only be passed if the referring page is the search page:
I am aware that url_to_postid(wp_get_referer()) would get me the page id of the refering page but in my case this does not work as the search page does not have an id. Is there any other way I can do this?
EDIT: the wordpress url for the search would be http:/mywebsite.com/?s=aaa where is the search term
Depending what your using this for and how reliable it needs to be you could use $_SERVER['HTTP_REFERER']
Taken from PHP Manual
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
You might be better off either using post/get to send a parameter to the next page, or using a session if you need more reliability and or control.
Related
Can someone tell me how to pass a variable into Wordpress from an incoming URL? For example, I have a visitor following this link:
http://mywebsite.com?variable=white
When they arrive at my wordpress site, I want to pull that "white" variable and store it for future use in my MailChimp list and departing links like this:
store mailchimp color
http://mySecondWebsite.com?favoriteColor=white
I want this to be temporary and specific to this user only. I understand the concept and use of session_start(), but I have no idea how to use this in conjunction with Wordpress. Any help is appreciated.
You can use the GET variables to fetch information from a URL. You can read out the $_GET array in PHP to get to your variable.
The part thats tricky, is that inside your wordpress application, you should check out if the user is logged in, and then update the users' information based on the current session. This is basically what you're looking for.
If the user is not logged in already, you can ofcourse not update his account by just that URL. You'd then need to add more info - something like a hash in the URL thats unique for this user and allows you to update a preference without logging in.
I have develop a simple modal box and I added $_SERVER["HTTP_REFERER"] so from specific referrer to do not appear. It works fine but the $_SERVER["HTTP_REFERER"] is not working on Mozilla. Is there any other way to do this?
I am using the simple PHP code:
if ($_SERVER["HTTP_REFERER"] == "www.thedomain.com/article.php"){
//Code to do not show the modal box
}else{
//code to show the modal box
}
As explained, you can't rely on the referrer. Some users choose to disable the referrer altogether, and over HTTPS it's always blank.
Just use a query string parameter, like &modal=true.
'HTTP_REFERER' -
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
http://php.net/manual/en/reserved.variables.server.php
In other words, you should not be relying on this value in your code. That said there is not really a better reliable way to get this information. You simply do not always have access to this information from the user's browser.
I'm creating a wordpress site that needs to have two distinct versions. The changes in the two are only frontend, and will be very minimal so I don't want to create two separate sites.
Instead, I'd like to pass a query string along that dictates whether or not to serve the prop version.
People will access the prop site by going to http://example.com/?prop=1. Once they're there, I need that "prop=1" to be carried over when they click any link on the blog. I could do this by hand in all of the templates, taking all the links and making sure to append that query to them, but I'd like to do it in an automated way.
Basically, if that query var is there, carry it through to any links that person clicks on the site. If it's not, then serve regular links. I'm also open to using session variables, but someone should be able to visit the prop and regular sites at the same time in separate windows, so I'm not sure if that will work.
Your can try this solution - htaccess rewrite
or a redirect plug-in
basic idea will be using RewriteCond %{HTTP_REFERER}
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted. - php.net
http://www.php.net/manual/en/reserved.variables.server.php
if the current request has ?prop=1 then it will append ?prop=1 to the end , else nothing happens.
once user enters ?prop=1 mode they won't be able to leave it unless ?prop=1 is removed
If someone sends my website link to another in facebook and that user visits my page using that link
Is there a way to find the person who sent him that link?
You can add additional parameter with your link and using that parameter you can detect who referred that link to the other person.
For example original link:
home/xyx/play.php?gameId=10
modified link with refId=10
home/xyx/play.php?gameId=10&refId=10
The first answer might work (if the link is shared keeping the "refid" parameter, yet you can't be sure it will be kept).
The answer I would provide is to use $_SERVER['HTTP_REFERER'] which contains the referer site (so you just check if there's a match between $_SERVER['HTTP_REFERER'] and facebook.com using string comparison functions or even regular expressions if you need a higher precision), yet as PHP states:
This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
So even this method might not work at all, my suggestion is to use both (reference parameter and http_referer) to achieve higher possibilities.
I would like to know what page redirected to the current page on my system.
For example. If the system stopped in the page current.php.
How to know what page called current.php?
Is there a function to perform this?
$_SERVER['HTTP_REFERER'] can contain the URL of the page the user agent was previously on, but it can be spoofed or empty.
You don't have a reliable way of doing that.
If you're expecting the redirecting page to be on your server, you can set a $_SESSION variable to the current page on every page you visit, that way, you can check for it on the next page (before resetting it of course).
Maybe there are better solutions, but you could use a hidden field inside a form to transfer this information between pages inside your system, or use GET vars in your URL.
Rhis way you can keep track of certain states during page changes, that u are interested in.
But u would also need to update every page to handle the additional variables.