PHP - Header Redirection Issue.
I am having an issue with some scripts on my site. It won't redirect and emits an error. This occurs for only some of my scripts, but for the ones in which it does occur, it occurs 100% of the time. On a previous server, I didn't have this issue, now I do.
I get the following error: Warning: Cannot modify header information - headers already sent by (output started at /www/zzl.org/f/a/n/fantasyboxingonline/htdocs/bg/train_stat.php:5) in /www/zzl.org/f/a/n/fantasyboxingonline/htdocs/bg/train_stat.php on line 29 Below is the code to the page that emitted the error above (Note: session_start(); IS in autoupdater.php I'm not that stupid): <?php require_once("../autoupdater.php"); ?> <link rel="stylesheet" type="text/css" href="/style.css"/> <?php if(!$_SESSION["loggedin"]) { die("<b>You are not logged in, or you have been logged out. Please <a href=\"/login/\" target=\"_top\">login again!</a></b>"); } $id = $_GET["id"]; if($id > 4 || $id < 1) { die("<center><h2>An error occurred. You are trying to train an invalid statistic.</h2></center>"); } $userid = $_SESSION["userid"]; $time = time(); $stattraining = $_SESSION["stattraining"]; if($stattraining) { if($stattraining == 1) { $statname = "powerful"; } elseif($stattraining == 2) { $statname = "quick"; } elseif($stattraining == 3) { $statname = "skilled"; } elseif($stattraining == 4) { $statname = "durable"; } die("<center><h2>You cannot train! You are already training $statname!</h2></center>"); } mysql_query("UPDATE `users` SET `stattraining`='$id', `statstarttime`='$time' WHERE `userid`='$userid'", db_connect_select()); header("Location: training.php"); die(); ?> Any help or suggestions would be greatly appreciated. -Moon Similar TutorialsI am trying to redirect the user to a different Web site after they enter a password. I have two problems, I think. a. My phone file is not retrieving the 'input' from my html5 form. b. My phone header is not working: header (' location: http://filefippo.com'); What is wrong with my coding? <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="keywords" content="html"> <meta http-equiv="refresh" content "1800"> <link rel="stylesheet" href="menu_blue.css" type="text/css" media="screen" /> <title>Members 2</title> <script src="http://1.2.3.4/bmi-i...sion=1350564613" language="javascript"> </script> <!--[if IE 6]> <style> body {behavior: url("csshover3.htc");} #menu li .drop {background:url("img/drop.gif") no-repeat right 8px; </style> <![endif]--> </head> <body bgcolor="#000080"> <ul id="menu"> <li> <a href="index.html">Home</a> <!-- Home page --> </li> <!-- End Home page --> <li> <a href="contactform.html">Contact</a> <!-- Contact page --> </li> <!-- End Contact page --> <li> <a href="feedbackform.html">FeedBack</a> <!-- Feedback Page --> </li> <!-- End Feedback page --> <li> <a href="construc.html">Free Estimate</a> <!-- Free Estimate Page --> </li> <!-- End Free Estimate page --> <li> <a href="construc.html">Humor</a> <!-- Humor Page --> </li> <!-- End Free Humor page --> <li> <a href="#" class="drop">Other Links</a> <!-- Other Links Page --> <div class="dropdown_1column align_right"> <div class="col_1"> <ul class="simple"> <li> <a href="construc.html"> Members</a></li> <li> <a href="military.html"> Military</a></li> </ul> </div> </div> </li><!-- End Other Links page --> <li> <a href="repair_upgradeform.html">Repair/Upgrade</a> <!-- Repair/Upgrade Page --> </li><!-- End Repair/Upgrade page --> <li class="menu_right"> <a href="#" class="drop">Training</a> <!-- Training Page --> <div class="dropdown_1column align_right"> <div class="col_1"> <ul class="simple"> <li> <a href="tng_appsform.html"> Applications</a></li> <li> <a href="tng_hardwareform.html"> Hardware</a></li> <li> <a href="tng_osform.html"> Operating Systems</a></li> </ul> </div> </div> </li><!-- End Training page --> </ul> <br> <form name="myform" method="post" action="members2.php"> <table width="100%" align="center" bgcolor="#000080"> <tr> <th align="center" > <font size="+2" color=#ffff00"> ~ ~ ~ Member ~ ~ ~ </font> <br> </th> </tr> </table> <br> <table width="699" bgcolor="#000080" align="center"> <tr align="center"> <td align="center"> <input type="password" name="password" maxlength="15" size="15"> </td> </tr> </table> <table width="699" bgcolor="#000080" align="center"> <tr align="center"> <td align="center"> <font color="#ffffffff" size="+1"> (Please enter the password on your receipt) </font> </td> </tr> </table> <br> <table width="669" bgcolor="#000080" align="center"> <tr> <td align=center> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </td> </tr> </table> </form> <script language="JavaScript" type="text/javascript"> //You should create the validator only after the definition of the HTML form var frmvalidator = new Validator("myform"); frmvalidator.EnableMsgsTogether(); frmvalidator.addValidation("Password","req","Please enter the Password."); frmvalidator.addValidation("Password","maxlen=15","Max length for the Password is 15"); frmvalidator.addValidation("Password","alnum_s","Password - Alphabetic and Numeric chars"); </script> </body> </html> <script language="javascript"><!--//bmi_orig_img 0 // --> </script> PHP CODE <?php ob_start(); // Process membersform2.html error_reporting(-1) ; // Get Data From Form if ($_SERVER["REQUEST_METHOD"] == "POST") { if(isset($_POST["password"])) { $password = $_POST["passwords"]; trim($password); echo "$Password"; } else { if(empty($_POST["password"])) { echo "Password is required"; } } } // Validate Pwd if($password == "Z0y1X2w3V"){ header(' Location: http://filehippo.com/ '); exit; }else { members(); } // FUNCTION function members(){ // Print to browser global $password; // echo " <html>\n"; echo " <head>\n"; echo " <title>Redirect</title>\n"; echo " </head>\n"; echo " <body BGCOLOR=\"#000080\" TEXT=\"#ffff00\">\n"; echo " <table width=\"600\" Align=\"center\">\n"; echo " <tr>\n"; echo " <td width=\"600\" Align=\"left\">\n"; echo " You will be redirected to the members page in a moment.\n"; echo " <br />\n"; echo " $password \n"; echo " <br /><br />\n"; echo " </td>\n"; echo " </tr>\n"; echo " </table>\n"; echo " </body>\n"; echo " </html>"; } ob_flush(); ?> I cant seem to get the right format for adding in the echo to this header Code: [Select] <?php header("Location: search_goaulds.php?goauld= "echo $grab_goauld"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <style> .error {color: #FF0000;} h6 { font-family: bookman old style; font-size:20px; text-align: center; font-weight: normal; } h5 { font-family: bookman old style; font-size:15px; text-align: center; font-weight: normal; } </style> <?php $nameErr = $emailErr = $websiteErr = $categoryErr; $name = $email = $comment = $website = $reset = $category; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { $nameErr = "Name is required"; } else { $name = test_input($_POST["name"]); if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $nameErr = "Only letters and white space allowed"; } } if (empty($_POST["email"])) { $emailErr = "Email is required"; } else { $email = test_input($_POST["email"]); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = "Invalid email format"; } } if (empty($_POST["website"])) { $websiteErr = "URL is required"; } else { $website = test_input($_POST["website"]); if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) { $websiteErr = "Invalid URL"; } } if (empty($_POST["comment"])) { $comment = ""; } else { $comment = test_input($_POST["comment"]); } if (empty($_POST["category"])) { $categoryErr = "Category is required"; } else { $category = test_input($_POST["category"]); } if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['website']) && !empty($_POST['category'])) { $myemail = "links@loadsofads.com"; $subject = "Link Submission"; $message = "Your Link Submission form has been submitted by: Website Name: $name E-mail: $email URL: $website Category: $category Description: $comment"; mail($myemail, $subject, $message); header('location:submitthanks.php'); }} function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <?php include'header.php'?> <h6>Link Submission</h6> <h5><p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> Name Of Site: <input type="text" name="name" value=""> <span class="error">* <?php echo $nameErr;?></span> <br><br> E-mail: <input type="text" name="email" value=""> <span class="error">* <?php echo $emailErr;?></span> <br><br> URL: <input type="text" name="website" value=""> <span class="error">* <?php echo $websiteErr;?></span> <br><br> Description: <textarea name="comment" rows="5" cols="40"></textarea> <br><br> Category Of Site: <select size="1" name="category"> <option value=""> -- Please select -- </option> <option>Arts</option> <option>Business</option> <option>Computers</option> <option>Games</option> <option>Health</option> <option>Home</option> <option>Kids and Teens</option> <option>News</option> <option>Recreation</option> <option>Reference</option> <option>Science</option> <option>Shopping</option> <option>Society</option> <option>Sports</option> <option>World</option> </select><span class="error">* <?php echo $categoryErr;?></span> <br><br> <input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value="Reset Form"> </form> <?php include'footer.php'?>Hello All, OK so I have been at this for a few days now and everywhere I go to learn or read information it says the same thing, to redirect the code is header('location:mypage.php');exit(); but it just will not redirect it every thing I try it does not load the redirect page. it clears the form and sits there, I do not know why! Can please someone please help me and see why it is not doing it? Thanks Code: [Select] <?php { $name=$_POST["txtGiven"]; $surname=$_POST["txtFamily"]; $user=$_POST["txtUser"]; $email=$_POST["txtEmail"]; $password=$_POST["txtPassword"]; $query="INSERT INTO Customer(Firstnames,Surname,Username,Email,Password) VALUES('$name','$surname','$user','$email','$password')"; include"connection.php"; $result=mysql_query($query)or die("Error in query: $query. ".mysql_error());; header("Location: userReceipt.php"); mysql_close($connection); } ?> ive tried removing all the spaces from all my php pages. That is the most common solution that comes up and nothing seems to work. I also have a login page where the same error is Afternoon all, Quick query; On the index.php page I have a hyperlink entitled LOGOUT. This allows the users to log out of their current session. The hyperlink directs to a logout.php page with the following contents: Code: [Select] <?php session_end(); ?> <html> <head></head> <body> <?php header('Location: index.php'); ?> </body> </html> Essentially; the code should end the session and redirect the browser back to the main page. Currently, the hyperlink does redirect to the logout.php page, but; - it doesn't return to the index.php page - if I click the back button, the session is still alive Can anyone assist? Is there a better way of doing this? This isn't something that hasn't been done before, but finding the topic in the forums has been difficult. Thanks in advance. I am trying to understand how Cache-Control works when you define using header function in PHP. If I specify Cache-Control "max-age=3600, must-revalidate" in php using header function Does browser/proxy cache(liek Squid/Akamai) go all the way to orgin server to validate before max-age expires? Or will it serve content from cache till max-age expires? What if I want to a browser to check for any updated file before max-age expires ? Hi, I'm having trouble with redirect my page to another page. what I have is a page that uses a form to insert into a database, the form is then processed to another page (insert.php) which will insert the information inserted in the form. I'm trying to work out how I could redirect the user to another page once the data has been successfully inserted. this is what I have now: insert.php Code: [Select] <?php $link = mysql_connect('ericlee.dot5hostingmysql.com', 'user', 'password'); if (!$link) { die('Could not connect: ' . mysql_error()); } //echo 'Connected successfully'; mysql_select_db('remarch', $link); $sql="INSERT INTO posts (Name, Location, Fault, Other, Description) VALUES ('$_POST[name]','$_POST[location]','$_POST[fault]','$_POST[other]','$_POST[description]')"; header('Location: about.html'); if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } mysql_close($link); ?> I'm pretty sure it's just the placing of the code Quote header('Location: about.html'); . Would be appreciated if someone could give me some guidance Thank you in advance! Hi Everyone was kind enough to help with my last issue and am now nearly there. The data actually populates correctly now in my database, however, it will not direct me to my redirect. I get the error Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\loginsystem\Permnew.php:4) in C:\xampp\htdocs\loginsystem\Permnew.php on line 124 This is the redirect i am trying to do anyone any ideas? Thanks Steve
<?php require "header.php"; ?> <main> <div class="wrapper-main"> <div class="welcomelogged"> <p>Adding A Permanent New Starter<p> </div> <form class="form-addperm" action="" method="post"> <table id="Tableperm" width="1000px;" border="0"> <tr> <th align="right" scope="row"><label for="select">Week Commencing</label></th> <td><select name="WeekComm"> <option value="WC 6th April">WC 6th April</option> <option value="WC 13th April">WC 13th April</option> <option value="WC 20h April">WC 20h April</option> <option value="WC 27h April">WC 27h April</option> </select></td> </tr> <tr> <th align="right" scope="row"><label for="StartDate">Start Date</label></th> <td><input type="date" name="StartDate" placeholder="Start Date"></td> </tr> <tr> <th align="right" scope="row"><label for="select1">Consultant</label></th> <td><select name="Consultant"> <option value="Steven Buntin">Steven Buntin</option> <option value="Sam Ahmed">Sam Ahmed</option> <option value="David Millington">David Millington</option> <option value="Steven Nixon">Steven Nixon</option> <option value="Grahame Walsh">Grahame Walsh</option> <option value="Helal Ahmed">Helal Ahmed</option> </select></td> </tr> <tr> <th align="right" scope="row"><label for="FirstName">First Name</label></th> <td><input type="text" name="FirstName" placeholder="First Name"></td> </tr> <tr> <th align="right" scope="row"><label for="LastName">Last Name</label></th> <td><input type="text" name="LastName" placeholder="Last Name"></td> </tr> <tr> <th align="right" scope="row"><label for="ClientName">Client Name</label></th> <td><input type="text" name="ClientName" placeholder="Client Name"></td> </tr> <th align="right" scope="row"><label for="Position">Position</label></th> <td><input type="text" name="Position" placeholder="Position"></td> </tr> <th align="right" scope="row"><label for="Comments">Comments</label></th> <td><input type="text" name="Comments" placeholder="Comments"></td> </tr> <tr> <th align="right" scope="row"><label for="Salary">Salary</label></th> <td><input type="varchar" name="Salary" placeholder="Salary"></td> </tr> <tr> <th align="right" scope="row"><label for="ChargePercentage">Charge Percentage</label></th> <td><input type="varchar" name="ChargePercentage" placeholder="ChargePercentage"></td> </tr> <ty> <th align="right" scope="row"><label for="GPNotes">GP Notes</label></th> <td><input type="text" name="GPNotes" placeholder="GPNotes"></td> </tr> </table> <button type="submit" name="addstarter">Add Starter</button> </form> </div> </main> <?php $dBServername = "localhost"; $dBUsername = "root"; $dBPassword = ""; $dBName = "loginsystemtut"; mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $conn = mysqli_connect($dBServername, $dBUsername, $dBPassword, $dBName); if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } if (isset($_POST['addstarter'])) { $WeekComm = $_POST['WeekComm']; $StartDate = $_POST['StartDate']; $Consultant = $_POST['Consultant']; $FirstName = $_POST['FirstName']; $LastName = $_POST['LastName']; $ClientName = $_POST['ClientName']; $Position = $_POST['Position']; $Comments = $_POST['Comments']; $Salary = $_POST['Salary']; $ChargePercentage = $_POST['ChargePercentage']; $GPNotes = $_POST['GPNotes']; $sql = ("INSERT INTO permanent (WeekComm, StartDate, Consultant, FirstName, LastName, ClientName, Position, Comments, Salary, ChargePercentage, GpNotes) values (?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt = mysqli_stmt_init($conn); if (!mysqli_stmt_prepare($stmt, $sql)) { // If there is an error we send the user back to the signup page. header("Location: ../signup.php?error=sqlerror"); exit(); } else { mysqli_stmt_bind_param($stmt,"sssssssssss",$WeekComm,$StartDate,$Consultant,$FirstName,$LastName,$ClientName,$Position,$Comments,$Salary,$ChargePercentage,$GPNotes); mysqli_stmt_execute($stmt); } header("Location: ../loginsystem/permnew1.php?success"); exit(); } ?>
Hello everyone, I'm building a wordpress site, which of course is in PHP. One of the things I did was start with a template I moderately liked and have edited it until I do like it. I know the problems with debugging that this causes but I'm too far invested now to back out. One of the things I added to the header was some simple scroll-over images that have links. I created a div-id in the CSS style sheet for where this will go in the header and put in the image using the simple rollover image creator in dreamweaver. The images work fine on every page BUT the blog posts themselves. Then it's just an empty void without the images themselves. Any insight to where the problem could lie, in the header, in the pages, ect, would be really helpful. Thanks! Hi, I read the HEADER advice on the forum but I think that I still need help to figure out what I am doing wrong with header("location: page_to_load"). In local, the redirection works without problems. When I test online on a free server (p4o.net), it works fine; but when I test it on the paid server (mediaserve.com), the redirect loads a blank page. After the blank page is loaded, I manually load the protected page (MyAccount.php) and all the information were displayed successfuly. I logged out and signed in with wrong credential. The result is a blank page. I manually loaded MyAccount.php again and I had "Access denied". I then concluded that the redirection deos not work. Is there any work arround for this situation? Please help. Thanks Login.php Code: [Select] <form id="login" method="POST" action="handlers/login_handler.php"> <strong>Username</strong> <input name="TextBoxEmailAdress" type="text" id="TextBoxEmailAddress" /> <strong>Password</strong> <input name="TextBoxPassword" type="password" id="TextBoxPassword" /> <input name="ButtonSubmit" value="Login" id="ButtonSubmit" type="submit" /> </form> login_handler.php Code: [Select] <?php ob_start(); //Start session session_start(); //Include database connection details require_once('../includes/WebConfig.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $Var_EmailAddress = clean($_POST['TextBoxEmailAddress']); $Var_Password1 = clean($_POST['TextBoxPassword']); //Input Validations if($Var_EmailAddress== '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($Var_Password1== '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: ../index.php?PageId=login"); exit(); } //Create query $Var_Password1 = md5($Var_Password1); $query="SELECT * FROM $tbl_member WHERE EmailAddress='$Var_EmailAddress' AND Password1='$Var_Password1'"; $result=mysql_query($query); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['Member_Id']; $_SESSION['SESS_FIRST_NAME'] = $member['FirstName']; $_SESSION['SESS_LAST_NAME'] = $member['LastName']; $_SESSION['SESS_EMAIL_ADDRESS'] = $member['EmailAddress']; $_SESSION['SESS_ADMIN_ROLE'] = $member['AdminRole']; $_SESSION['SESS_CONTRIB_EMAIL'] = ""; session_write_close(); header("location: ../MyAccount.php"); exit(); } else { //Login failed header("location: ../index.php?PageId=login-failed"); exit(); } } else { //echo "mysql error: " .mysql_error(); //echo "<br> mysql error number: " .mysql_errno(); //die("Query failed"); //Login failed header("location: ../index.php?PageId=login-failed"); } ?> Hi All, I'm trying to debug my first few lines of PHP where I have all my "checks" to make sure someone is logged in. I have this code all by itself and it is still not executing. This is the only page that I'm having trouble with. header('Location: login.php?logout=1'); My Error Output is this: Warning: Cannot modify header information - headers already sent by (output started at city-search.php:1) in city-search.php on line 65 What I'm I missing in the code, I can't seem to get these. It works excellent in Localhost, but in production. Error above. Code: [Select] <?php // MG CREATED THIS SIMPLE REGISTRATION PHP FOR THAT GOES TO ONE SPECIFIC USER. // WILL TEST FORM REGSITRATION NG 07-2011 //If the form is submitted if(isset($_POST['submit'])) { //Check to make sure that the name field is not empty if(trim($_POST['name']) == '') { $hasError = true; } else { $name = trim($_POST['name']); } //Check to make sure that the subject field is not empty if(trim($_POST['subject']) == '') { $hasError = true; } else { $subject = trim($_POST['subject']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['email']) == '') { $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { $hasError = true; } else { $email = trim($_POST['email']); } //Check to make sure comments were entered if(trim($_POST['message']) == '') { //$hasError = true; $comments == 'Have No Friends'; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['message'])); } else { $comments = trim($_POST['message']); } } //If there is no error, send the email if(!isset($hasError)) { //$emailTo = 'regina@shushmedeals.com'; //$emailTo = 'reginabyrd32@yahoo.com'; $emailTo = 'mp3@danjaproduction.com'; //$emailBcc = 'ganja99@netzero.net'; //$emailBcc = 'info@danjaproduction.com'; //$emailBcc = 'ganja99@netzero.net'; //Put your own email address here $body = "Location: $name \n\nEmail: $email \n\nShushMeDeals Sign-up Info:\n $comments"; // To send HTML mail, the Content-type header must be set $headers = 'From: ShushMeDeals.com City Location sign-up - '.$name.'' . "\r\n" . 'Reply-To: ' . $email . "\r\n" .'Bcc: print@extremeatlanta.com'; //$headers .= 'Cc: birthdayarchive@example.com' . "\r\n"; //$headers .= 'Bcc: info@danjaproduction.com' . "\r\n"; mail($emailTo, $subject, $body, $headers); $emailSent = true; if($emailSent = true) { setcookie("location", $name); //echo '<script type="text/javascript"> // window.location = "index.php?option=com_enmasse&controller=deal&task=today&locationName='.$name.'" // </script>'; } } } ?> I just installed this new script here http://webhost.pro/domain-check.php it's a basic domain availability tool. I am trying to make a form that can be used on any page forward to this page with the content. The page loads with this in the url webhost.pro/domain-check.php?domain=dwhs.net and will run the page. So I can make a form that just submits to that page and sends the details. I made this page for testing http://webhost.pro/test.html But no go, here is the code: <form id="search" action="/domain-check.php" method="GET"> <input type="text" name="s"> <a onClick="document.getElementById('search').submit()" class="button1">Search</a> <div class="clear"></div> </form> Thanks! Hi i have multilang website when you entered homepage default site if you are from polonia it redirect to you polonia page this script works perfect but the problem is if you are trying to see www.server.com instead server.pl and if you are from polonia you not able see because of redirection on google they solved this problem like www.google.com/ncr post is there something i can do like this for example server.com/ncr and this will disable redirect function would be nice if you help me to how to do it thanks in advance Code: [Select] <?php function redirect() { $Destination['en-au'] = 'http://www.server.com.au'; //austr$Destination['pl'] = 'http://www.server.pl'; //polonia $Destination['se'] = 'http://www.server.se'; //sweden $DefaultDestination = 'http://www.server.com'; //us $lang = preg_replace('/;.*$/','',$_SERVER['HTTP_ACCEPT_LANGUAGE']); $lang = preg_replace('/,.*$/','',strtolower($lang)); $dest = ''; if( isset($Destination[$lang]) ) { $dest = $Destination[$lang]; } if( empty($dest) ) { $lang = substr($lang,0,2); if( isset($Destination[$lang]) ) { $dest = $Destination[$lang]; } else { $dest = $DefaultDestination; } } if( ! empty($dest) ) { header("Location: $dest"); exit; } } redirect(); ?>[/code] Hi, for sometime i have tried to create what this person is doing below with his script, when a user clicks the buy it now button he redirects them to another url. Is it possible to replicate what he has done? I plan using the body onload to redirect the user however im not sure how i can get the url from the url redirected from? Quote http://searchchief.co.uk/Search/Essential-Michael-Jackson If i have not made myself clear please let me know as I'm totally new to PHP. Thanks, Hi all, we are new bee to php, I am developing a project that has config and other sub folders under admin directory ROOT/ADMIN, ROOT/ADMIN/FOLDER1,2,3... how to manage redirection from one file to another folder. Hi, I am having a little problem with my coding and was wondering if someone could please help me. The code below is a working login script where when a user logs in they are redirected to a URL which I have in my SQL database. The problem I am having is I would like to create a link on every page which says something like "My Account" - and when a user clicks the link the script automatically knows who is logged on and redirects to the page which matches the URL in the database. I hope I am making sense as I've been working on it for days and cannot figure out how to do it. Code: [Select] <?php session_start(); require 'config.php'; $user_name = $_POST['username']; $user_password = $_POST['password']; $qry = "SELECT id, redirect FROM users WHERE username = '".$user_name."' AND password = '".$user_password."'"; $result = mysql_query($qry); $count = (int)mysql_num_rows($result); if($count != 0) { $row = mysql_fetch_assoc($result); $_SESSION['loggedIn'] = true; header('Location: '.$row['redirect']); } else { header('Location: index.php'); } exit; ?> The config.php has basically my login details for phpmyadmin and nothing else. If anyone can help me it would be greatly appreciated. Kind regards, Robert. Hi I have coded a form, and dependant upon the result I would like to re-direct to a different page. The problem is I am getting the "headers already sent" message..Is there a way around this, I can't use JS re-direction because of accessibility. E.G: <?php //Do stuff with form data if($result = y){ header(Location: "mysite.php/thankyou.php"); } else{ header(Location: "mysite.php/error.php"); } ?> In-fact whilst typing this I have an idea, why not do all of this at the top of the page before headers are sent? I'll go ahead and try it now, in the meantime if anybody knows how or if headers can be sent after output please let me know thanks. Hi, Working on a URL re-direction site. http://ziz.im At the moment, it's not using the most effecient of redirections. I want to change this to a 301 redirect. But I can't quite figure out how to get it to work. Currently: - I am using a .htaccess rewrite to re-direct all shortened urls to a page (parse.php) which is providing the public variable 'q' containing the shortened keywork (e.g. GTRfdrtlls). - This is then checked through the DB to find if its valid, then redirects to that URL. How can I get it to use 301 Redirects, like the below: <? Header( "HTTP/1.1 301 Moved Permanently" ); Header( "Location: http://www.new-url.com" ); ?> I need to be able to query the database to get the URL / Check if its valid before I can specify the URL. But you need to specify the headers at the start. Confused. Cheers. Ok so what I am trying to do is have multiple folders pull from one folder. So if I have this structu Code: [Select] /test1/some_folder /test2/some_folder /test3/some_folder I would want all of those folders named some_folder to read from a master directory. I dont need them to be able to go that specific url just need it to include the files from the main directory in each of those. Imagine I was setting up shared functions and just wanted to store them in one place but be able to include them on any site. I didnt know what to google (tried folder redirection but didnt seem right) so if anyone can offer a suggestion as to what to google or wants to provide an answer it would be appreciated. |