PHP - Header Doesn't Redirect Me To Main.php
Problem: The page does not redirect the end user to main.php.
Notice: Use of undefined constant name_id - assumed 'name_id' in C:\x\xampp\htdocs\pages\form_process.php on line 48 Warning: Cannot modify header information - headers already sent by (output started at C:\x\xampp\htdocs\pages\form_process.php:48) in C:\x\xampp\htdocs\pages\form_process.php on line 87 The error messages displayed above make it seem like they are connected to the problem, but I don't understand why 'name_id' is undefined as its auto increments in mysql. I also think my .htaccess might be preventing me from redirecting, is that possible? " header('Refresh: 5; URL=http://localhost/pages/main.php'); " Goal: redirect user to main.php without error messages being displayed. form_process.php <?php //let's start our session, so we have access to stored data session_start(); if (isset($_POST['terms_and_conditions']) == 0) { // the code was incorrect // handle the error accordingly with your other error checking // or you can do something really basic like this die('You must agree to the terms and conditions to create a profile. Go back and try again.'); } include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php'; $securimage = new Securimage(); if ($securimage->check($_POST['captcha_code']) == false) { // the code was incorrect // handle the error accordingly with your other error checking // or you can do something really basic like this die('The code you entered was incorrect. Go back and try again.'); } else { include 'db.inc.php'; $db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or die ('Unable to connect. Check your connection parameters.'); mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db)); $error = array(); $query = 'SELECT name FROM user WHERE ' . 'name = "' . mysql_real_escape_string($_SESSION['values']['name'], $db) . '"' ; $result = mysql_query($query, $db) or die(mysql_error($db)); if(mysql_num_rows($result) > 0) { $error['uname'] = '<p class="errText">Username is taken.</p>'; header('Refresh: 5; URL=form1.php'); } //let's create the query else{ $query = sprintf("INSERT INTO user ( name_id, name, password) VALUES ('%s','%s','%s')", name_id, mysql_real_escape_string($_SESSION['values']['name']), mysql_real_escape_string(md5(SALTY . $_SESSION['values']['password']))); //let's run the query $result = mysql_query($query, $db) or die(mysql_error($db)); $name_id = mysql_insert_id(); $query = sprintf("INSERT INTO contact ( name_id, first_name, last_name, email, address, city, county, post, home, mobile) VALUES (LAST_INSERT_ID(),'%s','%s','%s','%s','%s','%s','%s','%s','%s')", mysql_real_escape_string($_SESSION['values']['first_name']), mysql_real_escape_string($_SESSION['values']['last_name']), mysql_real_escape_string($_SESSION['values']['email']), mysql_real_escape_string($_SESSION['values']['address']), mysql_real_escape_string($_SESSION['values']['city']), mysql_real_escape_string($_SESSION['values']['county']), mysql_real_escape_string($_SESSION['values']['post']), mysql_real_escape_string($_SESSION['values']['home']), mysql_real_escape_string($_SESSION['values']['mobile'])); //let's run the query $result = mysql_query($query, $db) or die(mysql_error($db)); $name_id = mysql_insert_id(); $query = sprintf("INSERT INTO profile ( name_id, bi, ex) VALUES (LAST_INSERT_ID(),'%s','%s')", mysql_real_escape_string($_SESSION['pro']['bi']), mysql_real_escape_string($_SESSION['pro']['ex'])); $result = mysql_query($query, $db) or die(mysql_error($db)); $_SESSION['logged'] = 1; header('Refresh: 5; URL=http://localhost/pages/main.php'); } ?> <html> <head> <title>Register</title> </head> <body> <p><strong>Thank you <?php echo $_SESSION['values']['name']; ?> for registering!</strong></p> <p>Your registration is complete! You are being sent to the page you requested. If your browser doesn't redirect properly after 5 seconds, <a href="main.php">click here</a>.</p> </body> </html> <?php session_destroy(); die(); } ?> Similar Tutorialsif ($count==1){ header("Location:store.php"); }very simple I have issolated it and it doesn't redirect maybe u can see where my mistake is Hi,
I have an address on my main server http://www.website.com/directory and would like to redirect it to a subdomain http://subdomain.website.com/directory
The subdomain is not pointing to the same server as the main domain.
How would I set up a redirect in htaccess?
Thanks!
Ok, I have a download script. The script is called like: http://www.site.net/index.php?action=downloadfile&filename=file001.zip&directory=directory12& The download file code is below. My site hosts quite a few files that get linked on other websites. Problem is, when that link is clicked, obviously it just starts the file download, as if it were a direct link to the file. What I need to do, is still have it download the file when the link is clicked, but I would also like it to redirect the browser to my homepage as well. I tried placing this after the download headers but it didn't work. header("Location: http://www.site.net"); Can anyone give me an idea how I can get the code to do that? Keep in mind that I'm not fluent in PHP. case 'downloadfile'; $filename = getGetVar('filename'); $directory = getGetDir('directory'); $current_dir = $uploads_folder_name; if ($directory != '') { $current_dir.="/$directory"; } $filename = basename($filename); if (!$grants[$user_status][DOWNLOAD]) { place_header($mess[111]); show_Contents(); break; } if (!file_exists("$current_dir/$filename")) { place_header($mess[125]); show_Contents(); break; } if (!is_path_safe($directory, $filename)) { place_header($mess[111]); show_Contents(); break; } list($upl_user, $upl_ip, $filestatus, $contents) = get_file_description("$current_dir/$filename", $comment_max_caracters); if ($validation_enabled && $filestatus == UNVALIDATED && !$grants[$user_status][VALIDATE]) { place_header($mess[111]); show_Contents(); break; } $size = filesize("$current_dir/$filename"); $daily_size = get_daydownload(); if (($max_daily_download_mb > 0) && (($size + $daily_size) > ($max_daily_download_mb * 1024 * 1024))) { place_header($mess[212]); show_Contents(); break; } $monthly_size = get_monthdownload(); if (($max_monthly_download_mb > 0) && (($size+$monthly_size) > ($max_monthly_download_mb * 1024 * 1024))) { place_header($mess[213]); show_Contents(); break; } increasefiledownloadcount("$current_dir/$filename"); increasebytecountdl("$destination/$userfile_name"); if (($user_status != ANONYMOUS) && ($logged_user_name != '')) // Update user statistics { list($files_uploaded, $files_downloaded, $files_emailed) = load_userstat($logged_user_name); $files_downloaded++; save_userstat($logged_user_name, $files_uploaded, $files_downloaded, $files_emailed, time()); } header("Content-Type: application/force-download; name=\"$filename\""); header("Content-Transfer-Encoding: binary"); header("Content-Length: $size"); header("Content-Disposition: attachment; filename=\"$filename\""); header("Expires: 0"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); // Decrypt file if encryption enabled if ($encrypt_filecontent) { decrypt_file("$current_dir/$filename", true); } else { readfile_chunked("$current_dir/$filename"); } exit; break; How can one re-direct a visitor, without using a header re-direct? I'd like a page to show up, then after about 5 seconds I need the visitor sent to another page. How can I do this? Hi all, I am having a time with my coding. The codes for the form.php will add to the db if the action is giving as form.php. I am trying to get the page to redirect to the login.php. so I put the header function in. It redirects to the login.php as the header but does not add data to the db. So I tried to put the code login.php in the action for the form but it does not add to the db. Where can I put the redirect so it adds to data to the db and goes to the next page.??????? <?php @include_once ("Connections/connect_to_mysql.php"); $err=''; if($_POST["submit"]){ // Validate form data if($_POST["firstname"]=='') $err.='Please enter First Name<br>'; if($_POST["email"]=='') $err.='Please enter Email<br>'; if($err==''){ // Check if there are duplicate entries in the 'contacts' table $results = mysql_query("SELECT id FROM `Members` WHERE firstname='".addslashes($_POST["firstname"])."' and Email='".addslashes($_POST["email"])."'"); if($row = mysql_fetch_array($results)){ $err.='Can not add duplicate entry<br>'; } else{ // adding new record to 'contacts' table mysql_query("INSERT INTO Members (firstname,lastname,country,Email) values ('".addslashes($_POST["firstname"])."','".addslashes($_POST["lastname"])."','".addslashes($_POST["country"])."','".addslashes($_POST["email"])."')"); // redirecting to success screen if($_POST['id']){ header("Location: login.php"); exit; } } } } ?> <html> <head> <title>Add New Contact</title> </head> <body> <h2>Register with us</h2> <?php echo $err==''?'''<p style="color:red;">'.$err.'</p>') ?> <form method="post" action="form.php"> <table border="0"> <tr> <td valign="middle">First Name:</td> <td><input type="text" name="firstname" size="30" value="<?php echo htmlspecialchars($firstname) ?>"></td> </tr> <tr> <td valign="middle">Last Name:</td> <td><input type="text" name="lastname" size="30" value="<?php echo htmlspecialchars($lastname) ?>"></td> </tr> <tr> <td valign="middle">Country:</td> <td><input type="text" name="country" size="30" value="<?php echo htmlspecialchars($country) ?>"></td> </tr> <tr> <td valign="middle">Email:</td> <td><input type="text" name="email" size="30" value="<?php echo htmlspecialchars($email) ?>"></td> </tr> </table><br> <input type="submit" name="submit" value=" Submit! "> </form> </body> </html> If I do something like header(Location: www.url.com). Is there a way that url.com would be able to get the IP from the server that did the redirect? It looks like $_SERVER["REMOTE_ADDR"] returns the clients IP address which isnt what I need. Thanks <!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 I am using a header redirect after a user makes a post which goes to their post. example they made a post which has an id of 236, then the url redirect would be index.php?forum=1&topic=1&post=236#p236 i have the <a name> set up on each post and it works fine until the post is on a different page. the url should be: index.php?forum=1&topic=1&page=2&post=236#p236 but how would i be able to tell the header redirect which page to go to. I was thinking if statements like: if ($number_of_results >=10) { $page = 2; } but that would involve alot of if statements with no way of knowing how many pages the topic could have. Is there an easier way? 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 is it possible to have a script that changes header based on what page the user came from. something like Code: [Select] if ($_SERVER['HTTP_REFERER']) == http://www.site.com/pagebefore.php) { // do nothing, letting page generate } else { header("Location: back_to_the_start_buddy.php"); } 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(); } ?>
I cannot use a header redirect anymore because I'm echo'ing out in the header.php file for the navigation, which will echo out a profile and settings button ONLY if the user is logged in, it's basically a simple if statement with session variables. Now when the user goes to the login page and has successfully logged in I'd like to redirect the user to the main page, but of course this won't work since I have already an echo in the header.php file for the navigation. So my question is, is there a workaround or alternate redirect for this case? Hi Everyone, I'm having a bit of a problem if someone could help me with? I have a simple registration form with fields userid, username, password, clientaddress So when the user logs in with their username and password it will redirect to their client address but I cant get the redirect working. Here is my code: Code: [Select] $clientaddress = trim($_POST['clientaddress']); $_SESSION['start'] = time(); header("Location:$clientaddress"); exit; } also note if I add: Code: [Select] $clientaddress = 'http://www.google.com'; it redirects ok to google. It's getting the field from the database I think thats the problem Can somone help it just wont redirect to the client address hi everyone. i have been working on a site on a local windows server then moved everything to a unix server. now my refresh doesn't redirect anymore. any ideas why? Code: [Select] <?php if(isset($_POST['GO'])){ $page ="go.php?IDNumber=" . $IDNumber; header("Refresh: 1; url=$page"); echo " "; } ?> <form action="" method="post" name="redirect" id="redirect"> <input type="submit" name="GO" id="GO" value="GO" /> </form> Here is the webpage.php which executes data entered in the email form. I want to display a webpage which would confirm that the email has been sent but the header redirect does not work. An email gets sent but a blank page is displayed instead of confirmation. Can anyone help? this is urgent <?php error_reporting(6143); require_once('recaptchalib.php'); $publickey = "6Ldmbr8SAAAAAGT17oCjkB8Y60kSqvq_0w7APAJp"; $privatekey = "6Ldmbr8SAAAAAMY5lEl-7LnkWCovoFa9G7Vl3_kA"; isset($_POST['Email']) ? $Email = $_POST['Email'] : $Email = ""; isset($_POST['name']) ? $name = $_POST['name'] : $name = ""; isset($_POST['surname']) ? $surname = $_POST['surname'] : $surname = ""; ?> <meta http-equiv="content-type" content="text/html; charset=iso-8859-2"> <body bgcolor="#000000"></body> <link href="loginmodule.css" rel="stylesheet" type="text/css" /> <?php if (isset($_POST['Submit'])) { //Validate form $errormessage = ""; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if ($name == '') { $errormessage .= "<li>Please provide your name.</li> ";} if ($surname == '') { $errormessage .= "<li>Please provide your surname.</li>";} if ($Email == '') { $errormessage .= "<li>What is your e-mail address?</li>";} if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)){ $errormessage = $errormessage . "<li>This is not a valid email address! </li>";} if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly $errormessage .= "<li>Please rewrite captcha characters</li>"; } echo "</ul></p>"; //If errors, return error message(s) and form if ($errormessage != "") { ?> <span class="link1"><a href="index.php">back to home page/a></span> <img src="images/clack.JPG"> <table align="center"> <p align="center" class="err_bold">correct the following errors:</p> <span class="text_err"><ul><?=$errormessage?></span> </table> <?php include("email-form.php"); } else { //If good, mail to DL $email_subject = "Hello, you have a new message"; $email_headers = "From: $name [$Email] \r\n"; $to = "blablabla@hotmail.com"; $message_content = "----------------------------------------------------------------------------------\n". " Hello\n". "name: $name\n". "surname: $surname\n". "E-mail: $Email\n". "-----------------------------------------------------------------------------------\n\n"; //Email message to Requestor if (mail($to, $email_subject, $message_content, $email_headers)) { //Display Sent Confirmation (Successful or NOT!) ?> <?php header ("Location: http://www.google.co.uk"); exit; ?> <?php } } } else { ?> <span class="link1"><a href="index.php">back to home page</a></span> <img src="images/clack.JPG"><br> <p class="err" align="center">Please fill the form below<br/></p> <?php include("email-form.php");?> <?php }; Hello, I am new to some of the rules to PHP as far as what you can POST or SEND via forms in PHP. I am attempting to change the location of a page via the header() function and basically redirect to another page if the weather is inclimate at an outdoor events center. Currently what I have is two different submit buttons that would post the header() redirect based on if the weather is good or bad. Ex. <div style="width:220px; height:50px;"> <form method="POST" action="../../weather.php"> <input type="submit" value="Good Weather" name="weather_good" /> <input type="submit" value="Bad Weather" name="weather_bad" /> </form> </div> Then the processing for the form is this file - <?php if(isset($_POST['weather_good'])){ $myFile = "../myfile.php"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = echo "<?php header ('Location:fall_festival/index.php'); ?>"; fwrite($fh, $stringData); fclose($fh); echo "Page Updated"; } else if(isset($_POST['weather_bad'])){ $myFile = "../myfile.php"; $fh = fopen($myFile, 'w') or die("can't open file"); $link = "header('Location:fall_festival/weather/index.php');" ; $stringData = $link; fwrite($fh, $stringData); fclose($fh); echo "Page Updated"; } ?> The file doesn't return an error when it's processed but it also doesn't update the file header and redirect to the proper page. Thanks for your time and help! I need to know if what I am doing will even work. I have a .php page which submits information into a form to a insert_form.php page which then parses then information and adds it to a DB. In this insert_form.php page I have a function which is being called which is located in another .php file called function.php. This function adds images to the file system and will display errors if anything happens to the user. I do this by doing a header redirect: Code: [Select] header('location:link.php?error=error message that i want to display'); The problem is the function is working because the images are being loaded correctly, but if something happens to the images and the header redirect gets initiated, its not redirecting. I need to know if the header redirect would work when being a function in another file or not. thanks beemer All, I found the following script to do the download: $resultsetpic = mysql_fetch_array($resultpic); $filename = "full_size/$resultsetpic[filename]"; // don't accept other directories $size = @getimagesize($filename); $fp = @fopen($filename, "rb"); if ($size && $fp) { header("Content-type: {$size['mime']}"); header("Content-Length: " . filesize($filename)); header("Content-Disposition: attachment; filename=$filename"); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); fpassthru($fp); exit; } This downloads the file fine. However what I would like to do is also refresh the page that the user was just on. So I tried to add this: $resultsetpic = mysql_fetch_array($resultpic); $filename = "full_size/$resultsetpic[filename]"; // don't accept other directories $size = @getimagesize($filename); $fp = @fopen($filename, "rb"); if ($size && $fp) { header("Content-type: {$size['mime']}"); header("Content-Length: " . filesize($filename)); header("Content-Disposition: attachment; filename=$filename"); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); fpassthru($fp); exit; } $target = "work_queue.php"; header("Location:". $target); However, this doesn't reload the page they were on. Any ideas on how to do this? Thanks in advance. I am trying to modify a header redirect similar to this: header("Location: index.html"); exit; I would like to do something like this: header("Location: index.html?user=' . $user . '"); exit; Ofcourse, this does not work. Any hints? 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 |