jdock1 Posted June 18, 2009 Share Posted June 18, 2009 Sorry for the spam today, ive been on the computer all day trying things out due to the weather, so I have nothing better to do anyway, I saw this code on this site , its a script that emails you when somebody is referred to your site via google heres the code <?php // Script to email you when Google refers traffic to your site. $name=""; // add your name here $email_address=""; // add your email address here $keywords=""; $referrer=$_SERVER['HTTP_REFERER']; if( (stristr($referrer, "google")) && (stristr($referrer, "search")) ) { parse_str($referrer, $output); $keywords=$output['q']; $email_message="Hi $name, A visitor just arrived to your site after searching for '$keywords'. ($referrer)"; mail ("$email_address","Google referred a visitor","$email_message"); } ?> I filled out all the necessary variables, but cant get it to work. Is there something missing? I tried making it a seperate file, and used function.include() to include it, that didnt work. I tried html object tags, that didnt work, then I just put that code in the page. Nothing working. What could it be? Thank you all for your support, thanks to you all, I am making php applications that I thought I never could! Quote Link to comment https://forums.phpfreaks.com/topic/162691-this-code-isnt-working-anybody-help-me-out/ Share on other sites More sharing options...
xtopolis Posted June 18, 2009 Share Posted June 18, 2009 http://us.php.net/manual/en/reserved.variables.server.php '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. the script starts out: "If the referrer contains google and search", mail this message. Running it from your own server will not work unless you modify your UA to pretend to be a google page. Quote Link to comment https://forums.phpfreaks.com/topic/162691-this-code-isnt-working-anybody-help-me-out/#findComment-858616 Share on other sites More sharing options...
jdock1 Posted June 18, 2009 Author Share Posted June 18, 2009 http://us.php.net/manual/en/reserved.variables.server.php '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. the script starts out: "If the referrer contains google and search", mail this message. Running it from your own server will not work unless you modify your UA to pretend to be a google page. Thanks, do you know how to modify the user agent? Quote Link to comment https://forums.phpfreaks.com/topic/162691-this-code-isnt-working-anybody-help-me-out/#findComment-858657 Share on other sites More sharing options...
xtopolis Posted June 18, 2009 Share Posted June 18, 2009 Not personally, I'm sure you could google it. Likewise, you could test the script yourself by setting a variable to pretend to be from google at the top. I don't know off the top of my head, but just check out what the necessary HTTP_REFERER string looks like for the script, and set it at the top of your page to test. Quote Link to comment https://forums.phpfreaks.com/topic/162691-this-code-isnt-working-anybody-help-me-out/#findComment-858661 Share on other sites More sharing options...
jdock1 Posted June 19, 2009 Author Share Posted June 19, 2009 Im still not sure what to do. I really want to get this code to work. Can anybody else help me out? Quote Link to comment https://forums.phpfreaks.com/topic/162691-this-code-isnt-working-anybody-help-me-out/#findComment-859301 Share on other sites More sharing options...
Maq Posted June 19, 2009 Share Posted June 19, 2009 Test it. Echo something inside of your IF statement to make sure it's correct. You should also try to email something simple to yourself to make sure it's not the email. Quote Link to comment https://forums.phpfreaks.com/topic/162691-this-code-isnt-working-anybody-help-me-out/#findComment-859310 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.