PHP - Referring Url
Hello everyone,
I'm having real trouble with something I'm sure most of you would find easy.... ...here we go..... ...I want a redirect script based on referring URL. More specifically, a small part of the referring URL. example.... ad is placed on Bing, if someone clicks on the ad they get directed to a URL starting "0.r.msn.com/?Id=54r645f3345e" which redirects to my site. I want the referrer checker to looks specifically for the ".r.msn.com/?Id=" and if it's present let the visitor through to the site. The reason I only want it to check for that small part of the URL is because the bits before and after are variables and that is the only "static" part. However, if someone arrives at my site by not clicking on an ad, I want them to go somewhere completely different, let just say for arguments sake, google.com. This is what I have so far... <?php $_GET = $_SERVER['HTTP_REFERER']; if ($_GET == '.r.msn.com') { header('Location: http://www.mysite.com'); } else { header('Location: http://www.google.com'); } ?> I must be missing something, please help. Thanks Similar TutorialsI have 2 referring url.
USERNAME
http://testsite.com/...gister&ref=test
USER ID
http://testsite.com/...gister&ref_id=1
1. Code to remember ref and ref_id
2. Code to allow user to insert own referrer if no ref link detected?
3. Store ref and ref_id into same column Like db referrer = username/user_id or referrer = username / referrer_id = user_id ?
PHP
$ref_id = isset($_GET['ref_id']) ? filter_input(INPUT_GET, 'ref_id', FILTER_SANITIZE_STRING) : ''); $ref = isset($_GET['ref']) ? filter_input(INPUT_GET, 'ref', FILTER_SANITIZE_STRING) : '');FORM if(!empty($_GET['ref_id'])){ print ' <tr> <td style="font-weight:bold">Referred by user id #</td> <td><input type="text" name="ref_id" maxlength="255" style="width:200px" value="'.cleanOutput($ref_id).'"></td> </tr>'; }else{ print ' <tr> <td style="font-weight:bold">Referred by</td> <td><input type="text" name="ref" maxlength="255" style="width:200px" value="'.cleanOutput($ref).'"></td> </tr>'; }2. $ref = isset($_GET['ref']) ? filter_input(INPUT_GET, 'ref', FILTER_SANITIZE_STRING) : (isset($_POST['ref']) ? filter_input(INPUT_POST, 'ref', FILTER_SANITIZE_STRING) : ''); Hello People, I've been racking my brains, searching google and trawling through the many pages here to see if someone else has already asked the same question but I cant find it. I'm trying to build a simple redirect script based on the referring URL. I want to direct the user to "page a" if any of the arrays are found and "page b" if not. This is what I have so far Code: [Select] <?php $main_string="@$HTTP_REFERER"; $arr = array('aaaa','bbbb','cccc'); foreach($arr as $key => $search_needle) { if(stristr($main_string, $search_needle) != FALSE) { echo "<meta http-equiv=Refresh content=0;url=http://www.google.com/PAGEA.html>"; } } ?> I thought that it might be a case of adding the "else" command but doing that will always redirect to "page b" if all of the arrays aren't true and only 1 needs to be. Anyone got any ideas? Thanks Hey! I am having issues with my site not going to the correct page after submitting a form to login or register or anything in that regards. The script that referrers the user is poster below: Code: [Select] <? /** * Process.php * * The Process class is meant to simplify the task of processing * user submitted forms, redirecting the user to the correct * pages if errors are found, or if form is successful, either * way. Also handles the logout procedure. * * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC) * Last Updated: August 19, 2004 */ include("session.php"); class Process { /* Class constructor */ function Process(){ global $session; /* User submitted login form */ if(isset($_POST['sublogin'])){ $this->procLogin(); } /* User submitted registration form */ else if(isset($_POST['subjoin'])){ $this->procRegister(); } /* User submitted forgot password form */ else if(isset($_POST['subforgot'])){ $this->procForgotPass(); } /* User submitted edit account form */ else if(isset($_POST['subedit'])){ $this->procEditAccount(); } /** * The only other reason user should be directed here * is if he wants to logout, which means user is * logged in currently. */ else if($session->logged_in){ $this->procLogout(); } /** * Should not get here, which means user is viewing this page * by mistake and therefore is redirected. */ else{ header("Location: index.php"); } } /** * procLogin - Processes the user submitted login form, if errors * are found, the user is redirected to correct the information, * if not, the user is effectively logged in to the system. */ function procLogin(){ global $session, $form; /* Login attempt */ $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember'])); /* Login successful */ if($retval){ header("Location: ".$session->referrer); } /* Login failed */ else{ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } } /** * procLogout - Simply attempts to log the user out of the system * given that there is no logout form to process. */ function procLogout(){ global $session; $retval = $session->logout(); header("Location: logout.php"); } /** * procRegister - Processes the user submitted registration form, * if errors are found, the user is redirected to correct the * information, if not, the user is effectively registered with * the system and an email is (optionally) sent to the newly * created user. */ function procRegister(){ global $session, $form; /* Convert username to all lowercase (by option) */ if(ALL_LOWERCASE){ $_POST['user'] = strtolower($_POST['user']); } /* Registration attempt */ $retval = $session->register($_POST['user'], $_POST['pass'], $_POST['email']); /* Registration Successful */ if($retval == 0){ $_SESSION['reguname'] = $_POST['user']; $_SESSION['regsuccess'] = true; header("Location: ".$session->referrer); } /* Error found with form */ else if($retval == 1){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } /* Registration attempt failed */ else if($retval == 2){ $_SESSION['reguname'] = $_POST['user']; $_SESSION['regsuccess'] = false; header("Location: ".$session->referrer); } } /** * procForgotPass - Validates the given username then if * everything is fine, a new password is generated and * emailed to the address the user gave on sign up. */ function procForgotPass(){ global $database, $session, $mailer, $form; /* Username error checking */ $subuser = $_POST['user']; $field = "user"; //Use field name for username if(!$subuser || strlen($subuser = trim($subuser)) == 0){ $form->setError($field, "* Username not entered<br>"); } else{ /* Make sure username is in database */ $subuser = stripslashes($subuser); if(strlen($subuser) < 5 || strlen($subuser) > 30 || !eregi("^([0-9a-z])+$", $subuser) || (!$database->usernameTaken($subuser))){ $form->setError($field, "* Username does not exist<br>"); } } /* Errors exist, have user correct them */ if($form->num_errors > 0){ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); } /* Generate new password and email it to user */ else{ /* Generate new password */ $newpass = $session->generateRandStr(8); /* Get email of user */ $usrinf = $database->getUserInfo($subuser); $email = $usrinf['email']; /* Attempt to send the email with new password */ if($mailer->sendNewPass($subuser,$email,$newpass)){ /* Email sent, update database */ $database->updateUserField($subuser, "password", md5($newpass)); $_SESSION['forgotpass'] = true; } /* Email failure, do not change password */ else{ $_SESSION['forgotpass'] = false; } } header("Location: ".$session->referrer); } /** * procEditAccount - Attempts to edit the user's account * information, including the password, which must be verified * before a change is made. */ function procEditAccount(){ global $session, $form; /* Account edit attempt */ $retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email']); /* Account edit successful */ if($retval){ $_SESSION['useredit'] = true; header("Location: ".$session->referrer); } /* Error found with form */ else{ $_SESSION['value_array'] = $_POST; $_SESSION['error_array'] = $form->getErrorArray(); header("Location: ".$session->referrer); } } }; /* Initialize process */ $process = new Process; ?> All it does is bring you to a unknown page. Thanks! $_SERVER['HTTP_REFERER']; <-- this returns the full path. Can I return the referring page name only? ie) somepage.php Cheers Hello, When I use this function, the time always refers to January 1st 1970 ?! How come? I get the output '4 decades 1 year 11 months' regardless of which date I enter into the function.. ? Code: [Select] function timeAgo($tm,$rcs = 2) { $cur_tm = time(); $dif = $cur_tm-$tm; $pds = array('second','minute','hour','day','week','month','year','decade'); $lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600); for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v--); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]); $no = floor($no); if($no <> 1) $pds[$v] .='s'; $x=sprintf("%d %s ",$no,$pds[$v]); if(($rcs > 0)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= timeAgo($_tm, --$rcs); return $x; } When I call for the function I use this: Code: [Select] timeAgo($row['dateposted']) The format in the database for 'dateposted' is: Code: [Select] 2006-08-14 23:29:23 Any ideas what I am doing wrong? Thanks a million Hi Folks, This is my first post here and I was wondering if anyone could help me out at all please. I would basically like to change the logo on the home page based on whether a query string from a referring URL has a specific value. It's an affiliate URL for an online store, so essentially I need to get the referrer, check if the query string adnetwork = as and then replace the logo if it does, if not leave it as it is. Does that make sense? Any help would very much appreciated. I was thinking along the lines of: <?php if ($_GET('adnetwork') == 'as') { changeLogo(); } else { leaveLogo(); } ?> Am I along the right lines folks? |