PHP - Redirecting After Some Code Has Been Processed
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 . Similar TutorialsKeep going over this and can't find the stupid error. Need some fresh eyes for some help. Thanks Code: [Select] <?php ob_start(); session_start(); include("include/db_connect.php"); // Define $username and $password $username = $_REQUEST['username']; $password = $_REQUEST['password']; // To protect MySQL injection $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql="SELECT * FROM login WHERE username = '$username' AND password = '$password'"; $result=mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_array($result); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched, table row must be 1 row if($count!=0) { // Register session variables and redirect to file "dashboard.php" $_SESSION['id'] = $row['id']; $_SESSION['franchise_id'] = $row['franchise_id']; $_SESSION['dealer_id'] = $row['dealer_id]'; $_SESSION['first'] = $row['first']; $_SESSION['last'] = $row['last']; header("location:dashboard.php"); } else { header("location:not_logged_in.php"); } ob_end_flush(); ?> I have 2 servers I use for hosting, both Linux and Apache. I am executing the same php script on both, the one server the information is sent to me as it is processed, the other it only sends when it is finished processing the script. How can I change it so that it sends me the stuff as it processes it, and not right at the end? Thanks Hi there, I need help with my form. i have this from which user will fill out e.g name telephone and a message. i want to add pre text after the message e.g name phone message preTEXT. how do i do that ? I'll be having .txt files uploaded via a form. Upon submission, it will be passed to another .php file to have the data entered into the database. It's not uploading the file to the folder, and while the trigger echoes what's set up to echo, it's loading the data into the database.
Here is the form: echo '<form action="/wp-content/plugins/csi_stats/csi_process.php" method="post" enctype="multipart/form-data"> Select Boxscore to upload: <input type="file" name="fileToUpload" id="fileToUpload"> <input type="submit" value="Upload" name="submit"> </form>'; } Here is csi_process.php $filename = $_FILES['fileToUpload']['name']; $target_dir = "/wp-content/uploads/csi_boxscores/21/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); // Check if image file is a actual image or fake image if(isset($_POST["submit"])) { // $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); echo $target_file . ' Boxscore Sent'; echo '<br>' .$filename; $uploadOk = 0; } $query = " LOAD DATA INFILE '$fileName' INTO TABLE a_stats FIELDS TERMINATED BY '|' LINES TERMINATED BY '\r\n' IGNORE 2 Lines (jersey,points,2pm,2pa,3pm,3pa,ftm,fta,oreb,dreb,treb,ast,blk,stl,deflect,turn,charge,pf,tf) SET team = 426"; "team" will ultimately be a variable, and I'll have "game" in there too.
Here is the data: 235a5d12-be10-43af-abba-e45456d9d8da Jersey|Points|TwoPointsMade|TwoPointAttempts|ThreePointsMade|ThreePointAttempts|FreeThrowsMade|FreeThrowAttempts|OffensiveRebounds|DefensiveRebounds|Rebounds|Assists|BlockedShots|Steals|Deflections|Turnovers|Charges|PersonalFouls|TechnicalFouls 10|8|1|2|2|6|0|0|0|4|4|1|1|1|0|1|0|0|0 12|3|0|5|0|3|3|4|1|2|3|0|1|1|0|0|0|2|0 20|8|4|6|0|0|0|0|1|1|2|0|1|1|0|2|0|0|0 22|3|0|1|1|1|0|0|1|2|3|1|0|0|0|2|0|2|0 24|18|4|7|1|3|7|10|0|2|2|1|0|1|0|3|0|3|0 32|1|0|2|0|3|1|2|2|1|3|0|0|1|0|0|0|2|0 41|8|0|0|2|3|2|2|0|0|0|0|0|1|0|0|0|1|0 43|11|5|7|0|0|1|2|0|6|6|1|0|4|0|2|0|3|0 52|3|1|6|0|0|1|1|4|3|7|0|0|1|0|1|0|4|0 Edited November 14, 2020 by Jim R I want to get a simple true/false to check if my ffmpeg is still converting a video. You can check out the shell command I executed below. convertToFlv( $input, $output ); function convertToFlv( $input, $output ) { echo "Converting $input to $output"; $command = "ffmpeg -y -i $input -acodec libfaac -ar 44100 -ab 96k -vcodec libx264 -level 41 -crf 20 -bufsize 20000k -maxrate 25000k -g 250 -r 20 -s 640x480 -coder 1 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -flags2 +brdo+dct8x8+bpyramid -me umh -subq 7 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq 'blurCplx^(1-qComp)' -bf 16 -b_strategy 1 -bidir_refine 1 -refs 6 -deblockalpha 0 -deblockbeta 0 $output"; shell_exec( $command ); } Can someone provide me some code that will help me check if ffmpeg is still doing the conversion? <body> <?php Echo "Hello World!"; ?> <h1> The headline here</h1> </body> The above os an example. The problem can be read in title. When clicking on View Source Code in the web browser the PHP tags are still there, which means they have not gotten processed. Why does this happen? Using Apache (XAMP). I am trying to build a form that will process all the user inputted information, and put those contents into an html table so that I can send the info to both my customer and myself. I figured out how to send an email to myself as html, but the user email is arriving as plain text with all the html tags. Someone had suggested PHPMailer, but I cannot figure out how to format it properly to work with my setup. I am new to PHP so this is a learning curve. I have included a sample of my process form with fictitious email addresses. Any help is much appreciated. Thank you in advance for the help! Code: [Select] <?php header("Location: ../contactthank.php"); ?> <?PHP $field_Type = $_POST['field_Type']; $field_Service_Provider = $_POST['field_Service_Provider']; $field_Brand = $_POST['field_Brand']; $field_Model = htmlspecialchars($_POST['field_Model']); $field_Size = $_POST['field_Size']; $field_Charger = $_POST['field_Charger']; $field_Case = $_POST['field_Case']; $field_Software = $_POST['field_Software']; $field_Manual = $_POST['field_Manual']; $field_Box = $_POST['field_Box']; $field_Condition = $_POST['field_Condition']; $field_FirstName = htmlspecialchars($_POST['field_FirstName']); $field_LastName = htmlspecialchars($_POST['field_LastName']); $field_Email = $_POST['field_Email']; $field_ZipCode = (int)$_POST['field_ZipCode']; $field_Comments = $_POST['field_Comments']; ?> <?php $reference = (rand(100000000000,99999999999999)); echo $reference; ?> <?php $to = "email@mail.com"; $subject = "Submission# $reference"; $headers = 'From: $field_Email' . "\r\n"; $message = '<html> <head> <title>Cell Phone Form Submission</title> </head> <body> <h1>Thank you for your submission. We will get back to you shortly</h1> <table border="1"> <tr> <td>Reference#</td> <td>' . $reference . '</td> </tr> <tr> <td>I want to</td> <td><b>Sell</b></td> </tr> <tr> <td>Service Provider</td> <td>' . $field_Service_Provider . '</td> </tr> <tr> <td>Model</td> <td>' . $field_Model . '</td> </tr> <tr> <td>Size</td> <td> ' . $field_Size . '</td> </tr> <tr> <td>Accessories</td> <td>' . $field_Charger . " " . $field_Case . " " . $field_Software . " " . $field_Manual . " " . $field_Box . '</td> </tr> <tr> <td>Condition</td> <td>' . $field_Condition . '</td> </tr> <tr> <td>Name</td> <td>' . $field_FirstName . " " . $field_LastName . '</td> </tr> <tr> <td>Email</td> <td>' . $field_Email . '</td> </tr> <tr> <td>Zip Code</td> <td>' . $field_ZipCode . '</td> </tr> <tr> <td>Comments</td> <td>' . $field_Comments . '</td> </tr> </table></body> </html> '; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $user = "$field_Email"; $usersubject = "Form Submission# $reference"; $userheaders = "From: email@mail.com\n"; $usermessage = '<html> <head> <title>Form Submission</title> </head> <body> <h1>Thank you. We will get back to you shortly</h1> <table border="1"> <tr> <td>Reference#</td> <td>' . $reference . '</td> </tr> <tr> <td>I want to</td> <td><b>Sell</b></td> </tr> <tr> <td>Service Provider</td> <td>' . $field_Service_Provider . '</td> </tr> <tr> <td>Model</td> <td>' . $field_Model . '</td> </tr> <tr> <td>Size</td> <td> ' . $field_Size . '</td> </tr> <tr> <td>Accessories</td> <td>' . $field_Charger . " " . $field_Case . " " . $field_Software . " " . $field_Manual . " " . $field_Box . '</td> </tr> <tr> <td>Condition</td> <td>' . $field_Condition . '</td> </tr> <tr> <td>Name</td> <td>' . $field_FirstName . " " . $field_LastName . '</td> </tr> <tr> <td>Email</td> <td>' . $field_Email . '</td> </tr> <tr> <td>Zip Code</td> <td>' . $field_ZipCode . '</td> </tr> <tr> <td>Comments</td> <td>' . $field_Comments . '</td> </tr> </table></body> </html> '; mail($to,$subject,$message,$headers); mail($user,$usersubject,$usermessage,$userheaders,$headers); ?> Hey 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. 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? 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>
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
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 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"); } } ?> 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! 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? Is it okay to redirect a user to another page - which displays an outcome message - after a form is submitted? Debbie |