PHP - Http Referrer Redirect Not Working :(
I'm trying to redirect visitors that contain broadly matched URLs. For example, redirect the visitor if their url contains: "/welcome" or "order.php" or "login.mysite/"
At the same time I also want to redirect the user if they a particular User Agent. Here's what I have, but doesn't seem to be entirely working... Code: [Select] <?php //detect referrer $ref = $_SERVER['HTTP_REFERER']; $find = "order.php"; $find = "login.mysite/"; //setting the variables $linux = stripos($_SERVER['HTTP_USER_AGENT'],"Linux"); $aol = stripos($_SERVER['HTTP_USER_AGENT'],"AOL"); //detecting user agent device, os, browser, etc. if ($linux == true || $aol == true) $redirect = 1; //detect referrer elseif (preg_match($ref, $find)) $redirect = 1; //set redirects if ($redirect) { $url = "http://www.google.com"; } else { $url = "http://www.yahoo.com"; } header("Location: $url"); ?> Any help you can offer is appreciated. Thanks! Similar TutorialsHello. I am trying to redirect from page A to page B. I redirect from page A with code header( 'Location: http://AAA.com/bbb.php/' ); in page B I have code if(isset($_SERVER['HTTP_REFERER'])) { echo $_SERVER['HTTP_REFERER']; }else{echo 'SKATA';} so far I see the world SKATA. Can somebody tell me how can i redirect to page B including the referrer info from page A ? I am trying for hours and I can't get the solution. thank you in advance. How do I only redirect the page when index.php is present? Okay, my organanization has a page that we really need to autodirect to https:// in case anyone manually types in the http:// version. I've tried this (among many others) and it just sits there like a knot on a log: Code: [Select] <?php header( "Location: https://www.mywebsite.com/myfile.php" ) ; ?> Any ideas? It just simply doesn't redirect. It just sits there in its http:// format. I've also tried numerous other methods. None of them worked, either, but this is the simplest. Thanks! <?php //user name and Password for authentication $username = 'username'; $password = 'password'; if(!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || ($_SERVER['PHP_AUTH_USER'] != $username) || ($_SERVER['PHP_AUTH_PW'] != $password)) { //The username/password are incorrect or haven't been entered so send the authentication headers header ('HTTP/1.1 401 Unauthorized'); header ('WWW-Authenticate: Basic realm= "Gator Boats" '); exit ('<h2>Gator Boats Admin</h2> Sorry, You ust enter a valid username and password ' . 'access this page.'); } ?> Every time I enter the User Name: username and Password: password it just resends the headers. Can you see what I am doing wrong? Hi, I'm trying to get HTTP post to work on my server but even the most basic script does not work. Can anyone help me? PHP script: <?php echo 'Hello ' . htmlspecialchars($_POST["name"]) . '!'; ?> I try and POST data to the script using: http://www.czoryk.co.uk/post_test.php?name=Chris But when I try and do that only ' Hello ! ' is displayed. I'm sure this is just a simple error but I can't figure out what's wrong. Thanks, Chris So while editing my .HTACCESS file I added the proper lines to redirect users that encounter errors like 404 and 500. It works like a charm if I tell it to display a specific message. However if I tell the file to redirect users to a custom error page it fails.
When testing out my 404 redirect I get this:
Not Found
The requested URL /143/test.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.4.9 (Win64) PHP/5.5.12 Server at localhost Port 80
As you can see it is stating that my ErrorDocument is not found BUT if I type my ErrorDocument URL in I can go to it myself.
My .HTACCESS file looks like this:
ErrorDocument 400 /error.php ErrorDocument 401 /error.php ErrorDocument 403 /error.php ErrorDocument 404 /error.php ErrorDocument 500 /error.php ErrorDocument 502 /error.php ErrorDocument 504 /error.php # supress php errors php_flag display_startup_errors off php_flag display_errors off php_flag html_errors off # enable PHP error logging php_flag log_errors on php_value error_log PHP_errors.log NOTE: I am using localhost (WAMP). Thanks. I have an html login page. Once a user is verified through the PHP page they get redirected to another page. For some reason once I have validated that the user exists I get the message that is was successful but the page will not redirect. This is my script I use on my HTML page to pass the parameters: Code: [Select] $(document).ready(function() { $('#submit').click(function() { var username = $('input[name=username]'); var password = $('input[name=password]'); var data = 'username=' + username.val() + '&password=' + password.val(); .ajax({ url: "login.php", type: "GET", data: data, cache: false, success: function() { alert("SUCCESS"); } }); return false; }); }); And this is my PHP page: Code: [Select] <?php $username = ($_GET['username']) ? $_GET['username'] : $_POST['username']; $password = ($_GET['password']) ? $_GET['password'] : $_POST['password']; if ($_POST) $post=1; $userFound = false; $memberId = ""; // Create connection string, Note, params are as follow // mysql_connect(databaseLocation, username, password) $con = mysql_connect("localhost","root",""); if (!$con) { die("Could not connect: " . mysql_error()); } mysql_select_db("memberdb", $con); // SQL Query $result = mysql_query("SELECT memberId, firstName, lastName, username, password FROM member"); while($row = mysql_fetch_array($result)) { if ($username == $row["username"] && $password == $row["password"]) { echo "<h1>Welcome " . $row["firstName"] ." ". $row["lastName"] . "! </h1></br>"; $userFound = true; $memberId = $row["memberId"]; } } // If User is found, continue on to next page, if not redirect to index.html if ($userFound) { echo "<h2>Login Successful</h2>"; echo "<h3>Page will redirect</h3>"; header( "url=menu.html?memberId=" . $memberId); } else { echo "<h2>LOGIN FAILED</h2>"; echo "<h3>Page will redirect</h3>"; header( "refresh: 1; url=index.html#loginPage"); } ?> It does the echo successfully but hangs on the part where is says : Quote header( "url=menu.html?memberId=" . $memberId); How can I get it to redirect? Thanks Trying to run a simple program that, when submitted, stores the username and password as cookies. When clicking Submit, I get the error "HTTP Error 405 - The HTTP verb used to access this page is not allowed". If the username and password fields are left blank when submitting it's suppose to give a message to enter a username and password, but, I still get that error message. HTML form: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Week 1 Project--Cookies</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <form action="cookie1.php" method="post"> <h2 align="center">Cookies</h2> <br /> <div> <p>Enter your username and password and click "Submit":</p><br /> <p>Username:<input type="text" name="username" size="20"></p> <p>Password:<input type="text" name="password" size="20"></p> </div> <br /> <div><input type="submit" name="submit" value="Submit" /></div> <br /> <div> <input type="reset" name="Reset" value="Start Over" /> </div> </form> </body> </html> PHP file: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Cookie File</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <div> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { setcookie('username', $_POST['username'], time() + 2592000); setcookie('password', $_POST['password'], time() + 2592000); } if(($_POST['username'] == "") || ($_POST['password'] == "")) { print "You must enter both a username and password. Press the Back button on your browser and try again."; } else if (isset($_COOKIE['username'])) { print "Welcome, " .$_COOKIE['username']; } ?> </div> </body> </html> I've got an issue with a header redirect that is confusing me. I haven't been able to find any similar problems that have help me solve it and the PHP man page on headers isn't helping me either. <?php if(isset($_POST['add_cat'])) { $cat_obj->add_category($_POST['cat_title']); header("Location: admin/category.php"); } ?> This code is in a file called add_category.php which is in the same directory as the category.php file I want it to redirect to. without the 'header..' line it works perfectly; but with the 'header..' line I get the following warning - QuoteWarning: Cannot modify header information - headers already sent by (output started at /opt/lampp/htdocs/**/**/admin/add_category.php:2) in /opt/lampp/htdocs/**/**/admin/add_category.php on line 30
but there's no other place sending headers (that I can see) and to my inexperienced eye it seems like it's cyclical logic as it's saying the same line I want to send the redirect is the one that already sent it. Would someone mind giving me an ELI5 breakdown of why this isn't working properly and maybe a route to solving the problem, please? TIA this code works if i use the header() in the else section it doesnt but it will echo the commented part Code: [Select] <? /** * User has already logged in, so display relevant links, including * a link to the admin center if the user is an administrator. */ if($session->logged_in){ echo "<li>Logged In "; echo "<b>$session->username</b></li>"; if($session->isAdmin()){ echo "<li><a href=\"LoginSystem/admin/admin.php\">Admin Center</a></li>"; } echo "<li><a href=\"../LoginSystem/process.php\">Logout</a</li>"; } else{header("Location: ../LoginSystem/main.php"); //echo "<li><a href=\"../LoginSystem/process.php\">Login</a></li>"; } ?> Hey guys, I am not a coder at all and would love a little bit of help with my code not working. Basically, I have a redirect script that sends my visitors to a software download. I want to be able to track a snippet from the incoming refer and send it along with the download. I hope I am explaining this correctly. Here is my code: <?php $tid = $_GET["tid"]; header( 'Location: http://www.liutilities.com/affcb/?id=RBgendtd&aff=14231&xat=WU-<?php echo $tid; ?>' ); ?> The page that sends them to this script automatically adds ?tid={keyword here}. What the above script is supposed to do is grab tid and then put it after the &xat=WU- but instead, its only putting the actual code itself (&xat=WU-<?php echo $tid; ?>). Can anyone offer a suggestion? Thanks so much! Hi I have a from, now after the users send the form, i want to redirect to a thank you page. my code does not redirect and gives me this error Warning: Cannot modify header information - headers already sent by (output started at D:\inetpub\vhosts\feelmalaysia.com\httpdocs\sendmailsqlar.php:1) in D:\inetpub\vhosts\feelmalaysia.com\httpdocs\sendmailsqlar.php on line 25 I have the redirect page saved in the same directory as the php file. my Php Code : <?php $headers .= 'Content-type: text/plain; charset=UTF-8; format=flowed' . "\r\n"; $headers .= 'Content-Transfer-Encoding: 8bit'."\r\n"; $to = "xxx@xxx.com"; $visitor = $_REQUEST['Name'] ; $visitormail = $_REQUEST['Email'] ; $nationality = $_REQUEST['Nationality'] ; $stulevel = $_REQUEST['Level'] ; $stfield = $_REQUEST['Field'] ; $message = $_REQUEST['Message'] ; $header = "From: $visitormail\n" . "Reply-To: $visitormail\n"; $subject = "Arab Enquiry"; $message = "From: $visitor \n\n Email: $visitormail \n\n Nationality: $nationality \n\n Level: $stulevel \n\n Field: $stfield \n\n Message: $message"; mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header, $headers); //Sending auto respond Email to visitor $reply_header = "From: xxx@xxx.com\n" . "Reply-To: xxx@xxx.com\n"; $reply_subject = "- تم استلام طلبكم"; $reply_to = "$visitormail"; $reply_message = "$visitor \n\n شكرا لزيارتكم موقعنا . \n نود ابلاغكم بأنه تم استلام طلبكم وسوف يتم الرد عليكم قريبا.\n هذه الرسالة مرسلة من نظام الموقع.\n شكرا\n "; mail($reply_to, '=?UTF-8?B?'.base64_encode($reply_subject).'?=', $reply_message, $reply_header, $headers); header('Location: thankyouar.html'); ?> Please help . Thank you Can you see any problems with the code below? It doesn't work. What I am trying to do is quite straightforward. The links on my site look like this: go.php?id=1&url=usa go.php?id=1&url=uk go.php?id=2&url=usa go.php?id=2&url=uk When a visitor clicks on one of these links, I want to grab the values of the id and url parameters, count the click, and redirect the visitor. Here's the error that I get when I try the code: Quote Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\sites\go.php on line 18 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\sites\go.php:18) in C:\xampp\htdocs\sites\go.php on line 19 <?php $conn = mysql_connect('localhost','username', 'password') or trigger_error("SQL", E_USER_ERROR); mysql_select_db('database', $conn) or trigger_error("SQL", E_USER_ERROR); $id = intval($_GET['id']); $url = intval($_GET['url']); mysql_query("UPDATE urls SET click_counter = click_counter+1 WHERE id=$id"); if ($url=="usa") $href = "SELECT usa FROM urls WHERE id=$id"; elseif ($url=="uk") $href = "SELECT uk FROM urls WHERE id=$id"; elseif ($url=="aus") $href = "SELECT aus FROM urls WHERE id=$id"; elseif ($url=="can") $href = "SELECT can FROM urls WHERE id=$id"; else $href = "SELECT int FROM urls WHERE id=$id"; $qry = mysql_query($href); list($href)=mysql_fetch_row($qry); header("Location:$href"); mysql_close($conn); ?> Hi, Hoping someone can help me out with something that is probably really simple, but I can't seem to figure out. I'm storing referring URLs, and some of them are over 1,000 characters because of all the variables. How would I Get only the actual url and not all the variables, such as... Code: [Select] http://www.google.com/ajax/search/start.php?eid=AAAAAwAgACAAAAH0v4jVmjrvBVRZxy6_CX4Rl8t6reioLF6htZb4qitx_2nR3dkfj7b8VJhn43Rc1JD0_Mn8S05zD1-Zg35FdE4rE6-cSmGB4Jrvebc3B6sFCY1vamkir_c--8ESJIzZeybl-22ddGIv4qP3JFtmaaLXWpOZSkyeSN17nD_I-vMnhsV8nY-gHeYTC4vqddkJQYI2bBSXP9Y0KHE189A1tFH9Cyprt4hpubL7KCKE2EPG4rErzSgnERqJMiqeLDtmdUs1Fe6e6nhaoE5bBim00LCnsfvQfYfX2wWkpglx2cZIASlb7H3AohF0amFZN2ZVeQBMhR7PsCNhhIXuuxa39-mxdjARVLqwpoQHXa2ODMu7jyNA7CO5pJ56F7vqtL2h9oDA-YlQ8BBgfXwKrmKaTKgWEU-mRqMeJ076B-JGPY6NjOg9Vkpe3KVhzh_L_rF4fz7kbQYKOgyGvmnsIEdkqlVCePqDOTvkKNMwOEdDW1LqYXIG3i3u21GGZAOqUslMnCix0sVIE09ENi-K6k75mvHxvTADiBXgPAw03BodR3I5hBfw3uFjkBKAfGJ1ir_03z5ec0Yz9RoSIOEYcZlvxeiTP-V4OnTz7n5eVYzD3o0c9mfyAYhLh4KY9LVxy88Pux2NSeIG3XAWextqYtPJhoIxWvO1qSp9tJBl_smywvlF2oZRQNCCbNNGeJ4BhdvmZ3OG7e0Jjm9FL4zEadh5pENY1A0lSInBN_reFiqe2iZh2_N8NX83Y51Tl0bn_Xrhf9SOI&c=4&f=0&ui=6002910216647-id_4d487a6db36b33126309761&en=1 I only need the info up to the "?" Code: [Select] http://www.google.com/ajax/search/start.php My php code looks like: $referer = $_SERVER['HTTP_REFERER']; mysql_query("INSERT INTO `refs` (`referer`) VALUES ('$referer')"); Is there an easy way to handle this? Hello, I know i can use server side code to capture a url etc, however i have a problem, i have a piece of Javascript that collects some information and passes it back to a php page which then proceses the information collected, which all works fine, on that php page i have the code to collect the refferring page, but obviously it just collects the details of the page it has come from which i already know. Is there anyway of using php to look back and get the page before that and any keywords that might have been used to get to that page, i know i could do this with javascript and include that information in the send, however the javascript is on another site and i really would prefer not having to change that if possible. I am not neccesarily looking for the solution but more if it is possible. Any advice would be appreciated. Thanks Hello, I'm using a direct feature on my site, and on redirect I want to record unique hits, Ip Address, and referrer, so far, the code below records unique hits, and ip address, but i want it to record referrar aswell (it records data to data.txt): <?php $filename = "hits.txt"; $file = file($filename); $file = array_unique($file); $hits = count($file); echo $hits; $fd = fopen ($filename , "r"); $fstring = fread ($fd , filesize ($filename)); fclose($fd); $fd = fopen ($filename , "w"); $fcounted = $fstring."n".getenv("REMOTE_ADDR"); $fout= fwrite ($fd , $fcounted ); fclose($fd); ?> I have this on redirect page <?php include ('counter.php'); ?> Thank you. When making a fake identity in cURL, we use curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'); but which is better for the referrer: curl_setopt($ch, CURLOPT_AUTOREFERER, true); or curl_setopt ($ch, CURLOPT_REFERER, "http://www.google.com/bot.html"); Hello, I need a small php script to ping a domain with custom referrer url eg: I need a script to ping a website www.abc.com with a custom referrer url ie. xyz.com so that the website abc.com would think that the traffic is from xyz.com Anyone have an idea? --SS Hi, I have decent knowledge of htaccess and know enough about php/mysql so a little direction/advice is mostly what I need. I host a website(site1.com) that has links to files that are hosted on a different website(site2.com) on a different server. When a file link is clicked from site1.com, first it will go to a local php file(within site1.com) that checks that the user is logged in and make sure the file exists. Then it redirects(using a simple header function) to the file located at site2.com to begin download. But since my files at site2.com stored in a simple folder(if you knew the folder name, you could download all the files without having to be logged in), I want a way for site2.com to check that the file request is coming from site1.com(maybe using php referrer?) before it allows the download to proceed. Any ideas? |