PHP - Losing Some Session Variables After A Header Redirect
I have four session variables, two I am valueing using $_POST elements from a previous page's form, the other two I am valueing using items retrieved from a database. Here is the code -
---------------------------------------------------- <?php session_start(); $_SESSION['UserLastName'] = strtolower(trim($_POST['txtLastName'])); $_SESSION['BadgeID'] = trim($_POST['txtBadgeID']); //get list for supervisor drop down $q1 = sprintf("select * from emps where emp_last = '".$_SESSION['UserLastName']."' and emp_badge = '".$_SESSION['BadgeID']."'"); $rs_emp_info = hitMSSQL($q1,"intra_sql","employees","xxxx","xxxx",1); $_SESSION['SSN'] = $rs_emp_info->fields("emp_ssn"); $_SESSION['CostCenter'] = $rs_emp_info->fields("emp_costcenter"); if ($_POST['rdoAction'] == 0) { header("Location: http://webapps/injury/empForm.php"); } ?> ---------------------------- When I get to the next page, empForm.php, the Last name and badge ID session vars are populated but the SSN and Cost Center session vars are not. I have tried several things including putting an exit(); after my header statement and first putting the database items into plain old $vars and then trying to populate the session vars with the value of the regular $vars, but nothing seems to work. I have a session_start() at the top of all of my scripts. Any idea why I am losing these values? (and why this box that I am typing into on this site is bouncing around so badly that I can't see what I am typing here???) Similar TutorialsHey all, I am having a situation where I have a singleton class with a static array in it. I insert an element into that array, and then I redirect the user to another page. At that page, I then retrieve that array (it's stored in the session vars), but the array is then empty when I retrieve it. I can't figure out why. Here are some pertinent code snippets. First, the class with the static array: class Logger { private static $instance = NULL; private static $messages = array(); //Private constructor to prevent this class from being instantiated multiple times private function __construct() { } //The clone function is private to prevent cloning of this class private function __clone() { } //Returns the singleton instance of this class public static function GetInstance() { if (!self::$instance) { self::$instance = new Logger; } return self::$instance; } public static function GetMessageCount() { return count(self::$messages); } public static function LogMessage($new_message) { self::$messages[] = $new_message; } public static function GetMessages() { return self::$messages; } public static function ClearMessages() { self::$messages = array(); } } Here is the code where I insert something into the aformentioned array (the process is that a user tries to log in, but the login fails, and so we insert a message into the array saying that the login credentials failed). //Retrieve the message logging instance from the session data to be able to pass messages to the user. $message_log = $_SESSION['user_messages']; $user = $_SESSION['user_account']; //Create a new instance of the database management class and //try to connect to the database $dbm = new DBM(); if ( !$dbm->isConnected() ) { $message_log::LogMessage("We are sorry, but we are unable to access the database at this time. Please try again later."); } else { //Retrieve the user login information $useremail_dirty = $_POST['useremail']; $password_dirty = $_POST['userpassword']; //Check to see if the email we were given exists in the database, and if the password matches $doesPasswordMatch = $dbm->doesPasswordMatch ( $useremail_dirty, $password_dirty ); if ( $doesPasswordMatch ) { //Correct login information was received. Login the user and redirect appropriately. $user->Login(); header ( "Location: ".BASE_URL."/userpage.php" ); exit; } else { //If an incorrect email or password was given, report that information to the user. $message_log::LogMessage("Incorrect login information."); } } //The user has failed to login. Redirect to the appropriate page. header ( "Location: ".BASE_URL."/loginfailed.php" ); And finally, given an unsuccessful login attempt, this is where I pick back up the array of messages to display the messages to the user: $message_log = $_SESSION['user_messages']; $all_messages = $message_log::GetMessages(); print $message_log::GetMessageCount()."<br>"; print count($all_messages)."<br>"; foreach ($all_messages as $message_string) { $prepared_string = prepare_text_for_html_output($message_string); echo $prepared_string."<br>"; } $message_log::ClearMessages(); Unfortunately, the "all_messages" variable has nothing in it...it's like the messages that I logged in the previous PHP script never even existed. I am calling session_start, so don't worry about that (even though it's not seen in these code snippets). What could be going wrong? 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? Hi guys I have 2 question. 1. Is it possible to use the a variable in a header redirect function i.e. Code: [Select] $test = 'index.php'; header("location: $test"); 2 assuming $test = 'index.php'; how do I pass the variable from one page to another? Thanks Hey guys, i always get the error: Warning: Cannot modify header information - headers already sent by (output started at /home/worldw44/public_html/Newsletter/Admin/Admin.php:1) in /home/worldw44/public_html/Newsletter/Admin/Admin.php on line 6 when im tyring to run: <?php if(isset($_SESSION['adminlogin'])) { $run=yes; } else { header( 'Location: http://www.worldwidelighthouses.com/Newsletter/Admin/Log-In.php'); }?> <!DOCTYPE HTML> <html lang="en-GB"> <head> <meta charset="utf-8"> <!--Search Engine Meta Tags--> <meta name="author" content="Worldwide Lighthouses"> <meta name="keywords" content="Lighthouses,Lightships,Trinity House,Fog Signals,Fog Horns,Fresnel"> <meta name="description" content="Worldwide Lighthouses is the number 1 source of information, pictures and videos on the Subject of Lighthouses and Lightships"> <!--Stylesheets/Javascript--> <link rel="stylesheet" href="../../Page-Layout.css" media="screen and (min-width: 481px)"> <link rel="stylesheet" href="../../Mobile-Page-Layout.css" media="only screen and (max-width:480px)"> <!--Mobile Browser Support--> <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> <!--IE Support--> <!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <link rel="stylesheet" href="../Page-Layout.css"><![endif]--> <meta name="application-name" content="Worldwide Lighthouses"> <meta name="msapplication-starturl" content="http://worldwidelighthouses.com/"> <meta name="msapplication-tooltip" content="Worldwide Lighthouses: Your number one source of Lighthouse Information, Videos and Pictures"> <meta name="msapplication-task" content="name=Lighthouses;action-uri=http://worldwidelighthouses.com/Lighthouses.php;icon-uri=http://worldwidelighthouses.com/IE9/Lighthouses.ico"> <meta name="msapplication-task" content="name=Lightships;action-uri=http://worldwidelighthouses.com/Lightships.php;icon-uri=http://worldwidelighthouses.com/IE9/Lightships.ico"> <meta name="msapplication-task" content="name=Fog Signals;action-uri=http://worldwidelighthouses.com/Fog-Signals.php;icon-uri=http://worldwidelighthouses.com/IE9/Fog-Signals.ico"> <meta name="msapplication-task" content="name=Glossary;action-uri=http://worldwidelighthouses.com/Glossary.php;icon-uri=http://worldwidelighthouses.com/IE9/Glossary.ico"> <title>Mailing List Administration | Worldwide Lighthouses</title> </head> <body> <header> <h1 id="WWLH">Worldwide Lighthouses</h1> <form method="get" action="http://www.worldwidelighthouses.com/Search/search.php" id="Search-Box"> <input type="search" placeholder="Search Worldwide Lighthouses" name="query" id="query" size="30" value="" autocomplete="off"> <input type="submit" value="Search"> <input type="hidden" name="search" value="1"> </form> </header> <nav> <ul id="Nav"> <li class="MenuButton" id="Index"><a href="../Index.php"><p class="Nav">Home</p></a></li> <li class="MenuButton" id="Lighthouses"><a href="../Lighthouses.php"><p class="Nav">Lighthouses</p></a></li> <li class="MenuButton" id="Lightships"><a href="../Lightships.php"><p class="Nav">Lightships</p></a></li> <li class="MenuButton" id="FogSignals"><a href="../Fog-Signals.php"><p class="Nav">Fog Signals</p></a></li> <li class="MenuButton" id="Daymarks"><a href="../Daymarks.php"><p class="Nav">Daymarks</p></a></li> <li class="MenuButton" id="Buoys"><a href="../Buoys.php"><p class="Nav">Buoys</p></a></li> <li id="MenuButtonLast"><a href="../Glossary.php"><p class="Nav">Glossary</p></a></li> </ul> </nav> <article> <h1 class="Title">Contact Admin Centre</h1> <div class="Textbox"> <div id="Social"> <a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="WWlighthouses">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> <object id="Facebook" data="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fworldwidelighthouses.com/&layout=button_count&show_faces=false&width=450&action=like&colorscheme=light&height=21"></object> </div> </div> </article> <footer> <ul> <li><a href="../About.php">About</a></li> <li><a href="../Contact-us.php">Contact</a></li> <li><a href="../Use-Our-Media.php">Use our media</a></li> <li><a href="../Search/search.php">Search</a></li> <li><a href="../Social-Networking.php">Social</a></li> <li><a href="#Top">Back to top</a></li> </ul> <br> <br> &#169; Worldwide Lighthouses <?php echo date("Y"); ?> </footer> </body> Cany anyone offer some suggestions as to why? Note i have no ability to change phpconfig. Afternoon, Not sure if i've been staring at the screen for too long or not, but have a log in script which saves the password as a session variable and I can pass that variable across my page like so: <?php session_start(); //Print_r ($_SESSION); echo "Erm, I have reached page.php and the password is ".$_SESSION['password']; ?> However, I want to make this secure, so I added a function to it which when you log in says if $_SESSION['password'] does not exist then send me away, like so: <?php session_start(); function checklogin() { session_start(); if(!isset($_SESSION['password'])) { header("location: /index/"); exit; } } checkLogin(); Print_r ($_SESSION); echo "Erm, I have reached page.php and the password is ".$_SESSION['password']; ?> However, using the function and a valid log-in it (as shown above) it chucks me out of the page even though $_SESSION['password'] exists? Am I doing something really stupid here? Thank you I'm having an issue with holding a session variable in the statement below $Color is losing its value in the if statement. For example int the ( ) $Color is a zero while in the echo part $Color is being displayed correctly as Blue. Hello,
I have a secure login script that uses sessions to maintain a users logged in status. I regenerate the session ID on each page reload for added security. Sometimes, I will lose sessions, and I am hard time figuring out why. It seems to be when I have a slow internet connection. I am wondering what could be causing this?? I have a few ideas, do any of these seem plausible.
-A max execution error, returns a fatal error.
-An ajax request get sent before the previous request returns, so the session ID's dont match an I am kicked out.
Any other ideas would be helpful.
Best,
James
I'd describe myself as a "basic" php programmer....
I'm trying to build my first multi-page forms.
The first page is calculator_q1.php
No session variables are needed here, I have omitted a few options, the code looks like this
<form id="page1" method="post" action="calculator_q2.php"> <h1>1. Which best describes the primary and secondary sports combination that will be played on your pitch?</h1> <table> <tr><td>Rugby only</td><td><input type="radio" name="1_primary_secondary_combo" value="Rugby only"></td></tr> <tr><td>Rugby/Soccer</td><td><input type="radio" name="1_primary_secondary_combo" value="Rugby Soccer"></td></tr> <tr><td>Soccer/Hockey</td><td><input type="radio" name="1_primary_secondary_combo" value="Soccer Hockey"></td></tr> </table> <input class="blue" type="submit" value="Next"> </form>The 2nd page is calculator_q2.php. This has some php to start the session, copy the result of form 1 to a session var, I do a debug echo and the variable is printed correctly so I think have captured it correctly. In extract, I do this: <?php //Start the session session_start(); //Store our posted values in the session variables $_SESSION['1_primary_secondary_combo'] = $_POST['1_primary_secondary_combo']; ?> <?php $debug=True; if ($debug) { echo ("Debug: session for q1 = ".$_SESSION['1_primary_secondary_combo']); } ?> <form id="page2" method="post" action="calculator_q3.php"> <h1>2. Please choose a preferred surface</h1> <table> <tr><td>3G Rubber Crumb Filled Turf</td><td><input type="radio" name="2_preferred_surface" value="3G Rubber Crumb Filled Turf "></td></tr> <tr><td>Sand Filled Turf</td><td><input type="radio" name="2_preferred_surface" value="Sand Filled Turf"></td></tr> <tr><td>Sand Dressed Turf or<br>a Water Based Surface</td><td><input type="radio" name="2_preferred_surface" value="Sand Dressed Turf or a Water Based Surface"></td></tr> </table> <p> <script> function submitForm(action){ document.getElementById('page2').action = action; document.getElementById('page2').submit(); } </script> <input class="blue" type="button" onclick="submitForm('/calculator_q1.php')" value="Previous" /> <input class="blue" type="button" onclick="submitForm('/calculator_q3.php')" value="Next" /> </form>So far so good, but when I introduce page 3 (calculator_q3.php) then it prints the previous page's (from page 2) variable but can't find the session variable from question 1. This is from calculator_q3.php: <?php //Start the session session_start(); //Store our posted values in the session variables $_SESSION['2_preferred_surface'] = $_POST['2_preferred_surface']; ?> <?php $debug=True; if ($debug) { echo ("Debug: session for q1 = ".$_SESSION['1_primary_secondary_combo']); echo ("<br>Debug: session for q2 = ".$_SESSION['2_preferred_surface']); } ?> <form id="page3" method="post" action="calculator_q4.php"> <h1>3. Please choose one watering option</h1> <table> <tr><td>With a Rain Gun System</td><td><input type="radio" name="3_watering_option" value="With a Rain Gun System"></td></tr> <tr><td>With a Rain gun System + Water Borehole</td><td><input type="radio" name="3_watering_option" value="With a Rain gun System + Water Borehole"></td></tr> <tr><td>Not Required</td><td><input type="radio" name="3_watering_option" value="Not Required"></td></tr> </table> <p> <script> function submitForm(action){ document.getElementById('page3').action = action; document.getElementById('page3').submit(); } </script> <input class="blue" type="button" onclick="submitForm('/calculator_q2.php')" value="Previous" /> <input class="blue" type="button" onclick="submitForm('/calculator_q4.php')" value="Next" /> </form>To see this in action see: http://www.sports.ha...lculator_q1.php Any insights would be appreciated. Many thanks. 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 Ok so a user tries to access a part of the site that requires them to login. So they are taken to the login page. but when they login I want them transfered to the page they were going to. So i thought of something like: <a href="securepage.php" onClick="<?php echo $_SESSION['clicked_link'] = $site_root.'securepage.php'; ?>"> Click Here </a> But when I echo $_SESSION['clicked_link'] not only am i getting the url i am getting the content after. echoed it looks like: http://www.thevault.cz.cc/securepage.php">Click Here So is there a better way to do it? if not what would i need to do to remove everything after the " ? 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(); } ?>
<!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 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 }; 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? 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? 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> 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 |