PHP - Not Redirecting Correctly
For some reason the below is always redirecting to ./index.php?usercp=ideas&message=error
I'm assuming it's something to do with mysql_affected_rows. <?php session_start(); require_once 'db_select.php'; require_once 'func.php'; $donor_id=$_POST['donor_id']; $donor_id=sanitize($donor_id); $username=$_POST['username']; $username=sanitize($username); $name=$_POST['name']; $name=sanitize($name); $amount=$_POST['amount']; $amount=sanitize($amount); $idea_message=$_POST['idea_message']; $idea_message=sanitize($idea_message); $_SESSION['idea_message']=$idea_message; $subject=$_POST['subject']; $subject=sanitize($subject); $_SESSION['subject']=$subject; $confirm_agreement=$_POST['confirm_agreement']; $confirm_agreement=sanitize($confirm_agreement); if($subject==""){ $error0=1; } else{ $error0=0; } if($idea_message==""){ $error1=1; } else{ $error1=0; } if(($confirm_agreement!="no" && $confirm_agreement!="yes") || $confirm_agreement=="no"){ $error2=1; } else{ $error2=0; } $error="".$error0."".$error1."".$error2.""; if($error!="000"){ header("Location: ./index.php?usercp=ideas&error=".$error.""); } else{ $sql="INSERT INTO $tbl_name5 (message_number, donor_id, username, name, amoutn, message) VALUES ('$message_number', '$donor_id', '$username', '$name', '$amount', '$message')"; mysql_query($sql); if(mysql_affected_rows()==1){ header("Location: ./index.php?usercp=ideas&message=submitted"); unset($_SESSION['idea_message']); unset($_SESSION['subject']); } else{ header("Location: ./index.php?usercp=ideas&message=error"); } } ?> Similar TutorialsHey guys, If my php looks like this: (notify if errors) <?php $user=$_POST['user']; $pass=$_POST['pass']; if(($user=="testing") && ($pass=="testing123")) echo "Access Granted"; if other echo "Access Denied!" ?> If after the "Access Granted" It could redirect the user to another webpage, index2.html for instance. Thanks in advance I do know that nothing should be printed out before a header() redirect, yet this error message: Code: [Select] Warning: Cannot modify header information - headers already sent by Is pointing to a meta tag, why does a meta tag become considered as a print out? The meta tags are as usually located in between the header tags of the whole website. What would you rather recommend in this case to accomplish a redirecting after a successful log in? why won't this header redirect? it doesn't seem to like the mysql_close. can i update the database before redirecting to another page? is it possible? Code: [Select] <?php session_start(); $name = "uname"; $lastLogin = date('l jS \of F Y h:i:s A'); require_once('../Connections/uploader.php'); mysql_select_db($database_uploader, $uploader); $query = "SELECT * FROM members WHERE uname='" . $name . "'"; $result = mysql_query($query) or die(mysql_error()); // connect to database here MYSQL_CONNECT($server, $user, $password) or die ("Server unreachable"); MYSQL_SELECT_DB($database) or die ("Database non existent"); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result) or die(mysql_error()); mysql_query("UPDATE members SET lastLogin='$lastLogin' WHERE uname='$name'") // ERROR MESSAGE?? or die(mysql_error()); mysql_close($con); header('Location: redirect.php'); } ?> thanks in advance. Hello, I'm having some problems with a redirect situation. I start on a page called Create Assignment. From this page I pass (using GET) the variable assignment_id to a page called Add_questions (the user can add questions to this specific assignment). When a user wants to add a question, they hit a link which brings them to my Database Update script. All works great so far! After the update, however, I want to redirect them BACK to the Add_questions page while keeping the same Assignment number. I've tried using: header('Location: list_assignment_question.php?assignment_id'); but I get this error: Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/algebra_book/main_scripts/db_insert_assignment_question.php:6) in /Applications/MAMP/htdocs/algebra_book/main_scripts/db_insert_assignment_question.php on line 12 Any thoughts? I'd be more than happy to provide more code as needed. Is it okay to redirect a user to another page - which displays an outcome message - after a form is submitted? Debbie i am trying to redirect a user to a certain page, if the credentials are not right. if there is no session user, they are kicked out. if it is set, but to the guest account, they go to the login page with a special error message. here is my code for it: Code: [Select] if (!isset($_SESSION['user'])) { header('Location: portal.php?logintocontinue'); exit; } elseif($_SESSION['user'] == "guest") { header('Location: portal.php?invalidLogin'); exit; } else { } after attempting to run the page, with session user = guest, i get this error message: The page isn't redirecting properly. does it have to do with headers already being sent? Is there anyway to do this: my form is posting to self, then checking login creds. if they are incorrect it spits out "invaild bla bla" but if they are correct send them to a different page? here is the short version of what I have. if(isset($_POST['submit'])) { //check inputs vs db if ($check) { header("Location: http://". $_SERVER['SERVER_NAME']."/include/process_renew.php"); } else { echo "<font color='red'>Username or Password did not match.</font> <br /><br />"; } } } I tested it using echo first and it worked fine then replaced the echo with header and now when I submit it just refreshes the page. is this not possible? Hi again, I have created a comment script, which is working pretty good. Now the problem I am facing is for instance this is one page www.mysite.com/blah1 and this is another www.mysite.com/blah2. They both have options to comment, now what is happening some one posts on blah2, it redirects to blah 1 and some one posts on blah 1 redirects to itself what I want to achieve is when a person posts a comment on any given page PHP redirects the person to the page where they posted from (itself) not the other one. Thanks any help or guidance would be appreciated. I hope was clear enough! Hello everyone, i have a "bug" i'd like you to see and help me solve if possible. Let me tell you about when the redirection starts. In my script, it checks if the two words you've entered in two boxes, if they match with the two words on the mysql database then send them to /php/userpanel.php if they doesnt send them to /php/loginerror1.php My problem is, that when you've been redirected to ex. /php/loginerror1.php then when you click to a new page in the menu, it sends you to /php/loginerror1.php/index.php /php/loginerror1.php also dont have any design, i think it doesnt load the .css properly. Anyone had this, or anyone knows how to fix it? Thanks Niixie Hello I have moved my web site from local machine to a hosted server (Ionos) I seem to be having issues with any code that has redirects or checks if the user is logged in, I just get a blank page, any idea's ? works fine on my local Xamp version two examples below (if I remove the code the page runs)
// We need to use sessions, so you should always start sessions using the below code. session_start(); // If the user is not logged in redirect to the login page... if (!isset($_SESSION['loggedin'])) { header('Location: login.php'); exit(); } ?>
<?php // database connect include('../db_connect.php'); // We need to use sessions, so you should always start sessions using the below code. session_start(); // If the user is not logged in redirect to the login page... if (!isset($_SESSION['loggedin'])) { header('Location: login.php'); exit(); } // if submit button selected run code if(isset($_POST['submit'])){ $_SESSION['district'] = $_POST['district']; header('Location: add_d_choice.php'); } ?> <!DOCTYPE html> <html> <head> </head>
As the title says, my headers not redirecting. Login.php: <?php include("global.php"); if (isset($_POST['login'])) { // Form data $email = $_POST['email']; $password = $_POST['password']; // If email and password are both filled in if ($email && $password) { mysql_select_db("social_site") or die("Can\'t find database!"); $query = mysql_query("SELECT * FROM users where email = '$email'"); $numrows = mysql_num_rows($query); // If email in database if ($numrows != 0) { // Login while ($row = mysql_fetch_assoc($query)) { $dbemail = $row['email']; $dbpassword = $row['password']; } if ($email == $email && $password == $dbpassword) { // User is logged in header(' location: index.php '); } else { echo "Incorrect password."; } } else { echo "That email does not exist."; } } else { echo "Please fill in <strong>all</strong> fields."; } } ?> <p> <html> <form action = 'login.php' method = 'POST'> Email: <input type = 'text' name = 'email'> <p> Password: <input type = 'text' name = 'password'> <p> <input type = 'submit' name = 'login' value = 'Login'> </form> </html> Global.php: <?php // This is the global file for the entire website // Start a session session_start(); // Start MySQL connection mysql_connect('localhost', 'root', 'root'); ?> Any ideas? Hi Guys,
I have a Url which allows me to send sms to a number. The url usually asks for id , number and few other things. When I paste the url in browser and press enter it opens and a sms is sent.
Now I want to code in php a way to send sms without redirecting to that page. For e.g. I ask user his mobile number and then I should be able to call/run that url and a sms should be sent to his number. If I use php header then it redirects to that page. I have tried using file_get_contents and php cURL but it has not worked so far.
Can you guys help me out ?
Thank you,
Cheers,
GR
Hi guys Another basic question. I have this dynamic link when I click it, it redirect to this link below, Code: [Select] http://samplesite.com/adventure/\'google.com\' How do I remove the main site --> samplesite.com redirect only to google.com? I also tried to remove the two slashes using stripslashes() but it won't. By the way here is the stripslashes() codes, Code: [Select] while ($db_field = mysql_fetch_assoc($result)) { $title = $db_field['title']; print "Title: " . stripslashes($title) . "<br>"; print "Description: " . $db_field['description'] . "<br>"; print "Version: " . $db_field['version'] . "<br>"; print "Started: " . $db_field['started'] . "<br>"; print "Finished: " . $db_field['finished'] . "<br><br>"; } Thanks in advanced. Can Someone please look at the following zip file and edit index and code-gen so when someone refer required amount of visitors, php echo will redirect them to complete.php
I have got css and js but not uploading as they are too big
Thanks (please help me)
script.zip 29.95KB
3 downloads
Hi, I have a form in file A.php. <?php <form name="A.php" action="B.php" method="post"> ...... <input type="text" name="name" id="name" /> .... <input type="text" name="email" id="email" /> .... ?> When the form is submitted php validation takes place on form B.php <?php if ( isset($_POST['submitted']) { if ($_POST[name]) { $name = $_POST[name]; } else { //what code goes here? } ...... ?> What I would like to happen in the else statement is that if name field is left blank user is automatically redirected to A.php, the name field is highlighted and a small error message that the name field was left empty appears. How can that be achieved? I would be very grateful for all help. Is there a way to catch the target of a redirecting url? For example, http://tinyurl.com/KindleWireless redirects to http://www.amazon.com/Kindle-Wireless-Reading-Display-Globa lly/dp/B003FSUDM4/ref=amb_link_353259562_2?pf_rd_m=ATVPDKIK X0DER&pf_rd_s=center-10&pf_rd_r=11EYKTN682A79T370AM3&pf_rd_ t=201&pf_rd_p=1270985982&pf_rd_i=B002Y27P3M How to catch the final url in php and echo it as a string? Hi go easy on me please, I'm a PHP newbie. I've got a HTML form that posts information to a PHP page. This PHP page runs some code and has a counterInt that is = 1 if everything is okay, and is = 0 otherwise. I want the PHP page to automatically redirect to another PHP page if counterInt = 1. But using the header() redirect thing apparently doesn't let me already have code before it. How can I make it redirect at the appropriate point in my code, if and only if counterInt is 1? Thanks very much . i enabled my output_buffering i used ob_start() and ob_end_flush functions i did'nt put any html tag before my php i used rapid php 2010 so dont know it making utf8 or not and i dont know how to check it i read many forums threads but cant find answer please answer but still i'm not redirecting to index.php from login.php here is my login.php <?php require_once("../../includes/database.php"); require_once("../../includes/functions.php"); require_once("../../includes/user.php"); require_once("../../includes/session.php"); if($session->is_logged_in()) { redirect_to(index.php); } //redirect_to("index.php"); if(isset($_POST['submit'])) //... if submit button is clicked { $username = trim($_POST['username']); $password = trim($_POST['password']); // check in database to see if username/password exist $found_user = User::authenticate($username,$password); // if we get some record in var $found_user if($found_user) { $session->login($found_user); // echo $found_user->username; // here is problem not redirecting redirect_to("index.php"); // this method is user define in function.php } else { //where i put header() $message = "Password/Username combination is not correct."; } } else { $username =""; $password =""; } ?> <html> <head>....... here is my function.php <?php function redirect_to( $location = NULL ) { if ($location != NULL) { header("Location: {$location}"); exit; } } function output_message($message="") { if (!empty($message)) { return "<p class=\"message\">{$message}</p>"; } else { return ""; } } ?> i'm attaching files too Per usual, I'm having an issue wrapping my head an issue, or I'm just not able to narrow the search well enough.
I have a form... method = post action = /process.php Upon hitting process.php, it will UPDATE a data table with the $_POST data it gets from the form. After that, I want to send it to PayPal.
It seems like at some point I was able to complete two 'actions' at once, but it's so long since I've created my own forms. Then again, maybe it was a redirect after executing the UPDATE. I just don't remember, and anything I search for doesn't seem to produce results of something that worked. I understand that this is a header error but i still do not know how to fix it. I am trying to create a login box that is in the top right corner of my site. Once the user uses it to log in they need to be redirected to the account page. i include the login_box.php file in the appropriate div. however the file uses header("Location: account.php"); to redirect the user. because this file is included after the header i receive Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\index.php:17) in C:\xampp\htdocs\layout_inc\login_box.php on line 76 What would be the correct way to do this. My code is bellow. Thank you in advance <?php //Forms posted if(!empty($_POST)) { $errors = array(); $username = trim($_POST["username"]); $password = trim($_POST["password"]); $remember_choice = trim($_POST["remember_me"]); //Perform some validation //Feel free to edit / change as required if($username == "") { $errors[] = lang("ACCOUNT_SPECIFY_USERNAME"); } if($password == "") { $errors[] = lang("ACCOUNT_SPECIFY_PASSWORD"); } //End data validation if(count($errors) == 0) { //A security note here, never tell the user which credential was incorrect if(!usernameExists($username)) { $errors[] = lang("ACCOUNT_USER_OR_PASS_INVALID"); } else { $userdetails = fetchUserDetails($username); //See if the user's account is activation if($userdetails["Active"]==0) { $errors[] = lang("ACCOUNT_INACTIVE"); } else { //Hash the password and use the salt from the database to compare the password. $entered_pass = generateHash($password,$userdetails["Password"]); if($entered_pass != $userdetails["Password"]) { //Again, we know the password is at fault here, but lets not give away the combination incase of someone bruteforcing $errors[] = lang("ACCOUNT_USER_OR_PASS_INVALID"); } else { //Passwords match! we're good to go' //Construct a new logged in user object //Transfer some db data to the session object $loggedInUser = new loggedInUser(); $loggedInUser->email = $userdetails["Email"]; $loggedInUser->user_id = $userdetails["User_ID"]; $loggedInUser->hash_pw = $userdetails["Password"]; $loggedInUser->display_username = $userdetails["Username"]; $loggedInUser->clean_username = $userdetails["Username_Clean"]; $loggedInUser->remember_me = $remember_choice; $loggedInUser->remember_me_sessid = generateHash(uniqid(rand(), true)); //Update last sign in $loggedInUser->updateLastSignIn(); if($loggedInUser->remember_me == 0) $_SESSION["userCakeUser"] = $loggedInUser; else if($loggedInUser->remember_me == 1) { $db->sql_query("INSERT INTO ".$db_table_prefix."Sessions VALUES('".time()."', '".serialize($loggedInUser)."', '".$loggedInUser->remember_me_sessid."')"); setcookie("userCakeUser", $loggedInUser->remember_me_sessid, time()+parseLength($remember_me_length)); } //Redirect to user account page header("Location: account.php"); die(); } } } } } if(!isUserLoggedIn()) {?><form name="newUser" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <table> <tr> <td> <label>Username:</label> </td> <td> <input type="text" name="username" /> </td> </tr> <tr> <td> <label>Password:</label> </td> <td> <input type="password" name="password" /> </td> </tr> <tr> <td> <label> </label> <input type="submit" value="Login" class="submit"/> </td> <td> <input type="checkbox" name="remember_me" value="1" /> <label style="font-size:12px">Remember Me?</label> </td> </tr> </table> <div style="text-align:center;"> <a href="register.php" class="info">Register</a> | <a href="forgot-password.php" class="info">Forgot Password?</a> </div> </form><?php } else{?><h1>Welcome <?php echo $loggedInUser->display_username; ?> </h1> <br/> <a href="account.php" class="info">Dashboard</a> | <a href="logout.php" class="info">Logout</a><?php } ?> |