PHP - Error While Using Header() To Direct To Another Page
Hi,
I found a code for login page on web which would check against the database and login, I wanted to modify it so that once the password is verified the user will be directed to a new page with the session variables also active. I read about " header()" functionality which would achieve this so i added this to the code but my code seems to fail with the error "Cannot modify header information - headers already sent by (output started at C:\xampp\phpMyAdmin\scripts\login1.php:7) in C:\xampp\phpMyAdmin\scripts\login1.php on line 10 " The code for login1.php is as below- For quick understanding i have removed all the section related to DB validation ..so the below code must activate the next page "add_entry2.php" immediately after submit button is pressed. Please see below.. Thanks in advance. Code: [Select] <html> <head> <title>Login</title> </head> <body> <?php if (isset($_POST['submit'])) {if(!$_POST['uname'] | !$_POST['passwd']){die('You did not fill in a required field.'); } header('Location: add_entry2.php');} else {// if form hasn't been submitted ?> <h1>Login</h1> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table align="center" border="1" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td> <input type="text" name="uname" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="passwd" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?> </body> </html> Similar TutorialsHello, I'm having some major major issues, with a web hosting / PHP / MySQL database issue and if anyone can help that would be amazing! Okay first I have a MySQL database setup, with a table called "staff", within that there is a "username" and "password" field pretty self explanatory. I have a login in page (login.php) see first set of coding and a loginaction (loginaction.php) and what is suppose to happen is the loginaction checks the posted data against the database and if correct relocate to another page. I have had this coding and much more complex coding working on various other servers, but this is the first time I've ever dealt with BT Business webhosting, which is pretty useless right now and poor help to date from technicians who say it is a purely a coding issue. From what I have established I believe that the issue is occuring because BT don't have the apache server setup correctly for what I'm trying to do or that the browser is seeing the "$result" on "loginaction.php" and data, resulting in a white page of certain doom! Please help!! login.php [<?php include "sections/phparea.php";?> <?php include "sections/header.php";?> <?php include "sections/left.php";?> <!-- start content --> <div id="content"> <?php // Include the formatted error message if (isset($_SESSION['message'])) echo "<h4>".$_SESSION['message']."</h4>"; // Generate the login <form> layout ?> <form action="loginaction.php" method="post" enctype="multipart/form-data"> <table class="tablelogin" > <tr> <td> <label for="email">E-mail Address</label> </td> <td> <input type="text" name="email" id="email" /> </td> </tr> <tr> <td> <label for="password">Password</label> </td> <td> <input type="password" name="password" id="password" /> </td> </tr> <tr> <td> </td> <td> <a href="../ambustar/accountrecovery.php">Forgotten Password?</a> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> <input type="hidden" name="count" id="count" value="1" /> <input type="reset" name="reset" id="reset" value="Clear" /> <input type="submit" name="submit" id="submit" value="Log in" /> </td> </tr> </table> </form> </div> <!-- end content --> <?php include "sections/right.php";?> <?php include "sections/footer.php";?> ] loginaction.php [<?php session_start(); include "dbconnect.php"; $email =$_POST["email"]; $password =$_POST["password"]; $query = "SELECT * FROM staff WHERE username = '$email' AND password = '$password'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) > 0) { header("Location: test.php"); } else { header("Location: login.php"); } ?> ] dbconnect.php [<?php $hostname = "sql5c30a.carrierzone.com"; $username = "user"; $password = "password"; $databaseName = "main_bikescarsandvans_co_uk"; $connection = mysql_connect($hostname, $username, $password); // or die ("Unable to connect!") mysql_select_db($databaseName) or die ("Unable to select database!"); ?> ] I just finished a page of code that passes all the debug tests except for the very last line on the page. </html>. The page has php and html, java script and some SQL. (see I'm learning and hadn't placed a post until I exhausted my limited resources. The Error Codeis: PHP Parse error: syntax error, unexpected $end in C:\wamp\www\registerform.php on line 292 Here's my concern: I read this error statement as an error()is missing. Please clarify something for me, You start the php code with <?php and end it with ?>. I also understand that the end() will stop all further operation. Correct. When you have a form call itself for data checking, and if the data is correct, send it to the appropriate database table, does one need to place the end() at the end of the php portion of the code? And if so, will it not stop any of the code from being read the first time the page is called? Also since the FORMs action calls for the page to load itself for data verification, how at the end of the checking do I go call another page? here's the page: The page is attached: Hello, I want to prevent this page from being directly accessed by all via just putting its address in the address bar: http://www.mysite.com/page1/page2/signup.php I want to allow to be accessed this page only via clicking on a link in a particular page like: http://www.mysite.com/activate/index.php Please help me. we have already see the facility in website gmail and facebook that when user log-in successfully then its redirects the page to another page automatically, can someone tell me how to redirect the page when log-in becomes successful ?
User tries to Log-in -> create session variable -> now redirect the page
I can verify user account details and set the session variable at the same time, but how to reload the page so that it finds the session and reload itself and then redirect the page to new page ??
Thanks for sparing your time here !!
I am using the debug_backtrace() php function to prevent direct access to admin files.
i simply place the code below at the top of a page eg config.php and direct access via the browser is prevented.
Is it a safe practice or is there a better way of doing it?
<?php debug_backtrace() || die ("Direct access to this resource is forbidden"); ?>Thanks Here is my code: // Start MySQL Query for Records $query = "SELECT codes_update_no_join_1b" . "SET orig_code_1 = new_code_1, orig_code_2 = new_code_2" . "WHERE concat(orig_code_1, orig_code_2) = concat(old_code_1, old_code_2)"; $results = mysql_query($query) or die(mysql_error()); // End MySQL Query for Records This query runs perfectly fine when run direct as SQL in phpMyAdmin, but throws this error when running in my script??? Why is this??? Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= new_code_1, orig_code_2 = new_code_2WHERE concat(orig_code_1, orig_c' at line 1 I have a page with results from a query that displays that has a link (works fine - passes variables etc) that deletes that line item from a database. It goes to the delete.php and actually executes and removes the item from the database and then has the line header("Location: page.php"); which returns BACK to the page displaying the results. However, it shows the old results until I hit Refresh in the browser. Its like the header is redirecting to a cached version of the page.
NOTE: This script used to work fine untouched when we where on a shared hosting account. We JUST updates to VPS hosting by the same host. Now this problem has risen and I can't figure out what is wrong. From what I can guess is there is something in php.ini that is either not set, set or set wrong. Any help would be greatly appreciated.
Thanks.
I've been staring at this for ages and I can't for the life of me see what the problem is, even after reading the 'HEADER ERRORS - READ HERE BEFORE POSTING THEM' post I still haven't been able to get it! It's probably something really stupid, I'm fairly sure its to do with the header because all the info gets passed to the MySQL datase. The form: admin-news.php Code: [Select] <?php session_start(); require_once('auth.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Admin Index</title> <link href="layout.css" rel="stylesheet" type="text/css" /> <script language="javascript" type="text/javascript"> function limitText(limitField, limitCount, limitNum) { if (limitField.value.length > limitNum) { limitField.value = limitField.value.substring(0, limitNum); } else { limitCount.value = limitNum - limitField.value.length; } } </script> </head> <body> <h1>Update News Feed</h1> <a href="admin-profile.php">My Profile</a> | <a href="admin-news.php">News</a> | <a href="adlogout.php">Logout</a> <p>Enter news below or click <a href="member-news.php">here</a> to view news feed.</p> <form id="news" name="news" method="post" action="newsfeed.php"> <table border="0" class="tablecontents"> <tr> <td align="left">Message:</td> <td><textarea name="newsfeed" style="resize: none;" rows="4" cols="40" onKeyDown="limitText(news.newsfeed,news.countdown,140);" onKeyUp="limitText(news.newsfeed,news.countdown,140);"></textarea> </td> </tr> <tr> <td> </td> <td><?php if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) { echo '<ul class="err">'; foreach($_SESSION['ERRMSG_ARR'] as $msg) { echo '<li>',$msg,'</li>'; } echo '</ul>'; unset($_SESSION['ERRMSG_ARR']); } ?> </td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="Post News"></td> </tr> <tr> <td></td> <td><p>(Maximum characters: 140)<br /> You have <input readonly type="text" name="countdown" size="3" value="140" /> characters left.</p></td> </tr> </table> </form> </body> </html> The php script: newsfeed.php Code: [Select] <?php //Start session session_start(); //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $newsfeed = clean($_POST['newsfeed']); //Input Validations if($newsfeed == '') { $errmsg_arr[] = 'Please enter some news'; $errflag = true; } //If there are input validations, redirect back to the registration form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: admin-news.php"); exit(); } //Create INSERT query $qry = "INSERT INTO newsfeed(newsfeed) VALUES('$newsfeed')"; $result = @mysql_query($qry); if($result) { header("location: news-success.php"); exit(); } else { die("Query failed"); } ?> The script carries out the insert but just leaves me at a blank newsfeed.php page! Any ideas? Thanks in advance I have been trying to fix this for a really long time. It does not show an error on my local server but on my demo server it does.' What am I doing wrong? I have tried changing the location of the default.php file. I even tried require_once and require. Nothing worked. try logging in with random details with this link. You will see the error. http://goo.gl/3IetJ default.php <?php $hostname_default = "localhost"; $database_default = "mypass"; $username_default = "my_user"; $password_default = "my_pass"; $default = mysql_pconnect($hostname_default, $username_default, $password_default) or trigger_error(mysql_error(),E_USER_ERROR); ?> login.php <?php if (!isset($_SESSION)) { session_start(); } if (!empty($_REQUEST['password'])) { include("../Connections/default.php"); $username = $_REQUEST['username']; $password = md5(md5($_REQUEST['password'])+salt); mysql_select_db($database_default, $default); $login_check = "SELECT * FROM users WHERE username = '$username' AND password = '$password'"; $login = mysql_query($login_check, $default) or die(mysql_error()); $row_login = mysql_fetch_assoc($login); $val_login = mysql_num_rows($login); if ($val_login == '1') { $_SESSION['E_User'] = $row_login['username']; header('Location: index.php'); } else { header('Location: login.php?error=1&username='.$username.''); } } ?> Hello I am getting this error in my script. Can anyone help? Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb25b/b904/ipg.votpservicescom/listing15.8.php:12) in /hermes/bosweb25b/b904/ipg.votpservicescom/listing15.8.php on line 39 if ((!$_POST[username]) || (!$_POST[password])) { header("Location: listing15.7.php"); exit; } //connect to server and select database $link = mysql_connect('servicescom.ipagemysql.com', 'ssap', 'pass'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_select_db(formlogin); //create and issue the query $sql = "select f_name, l_name from auth_users where username = '$_POST[username]' AND password = password('$_POST[password]')"; $result = mysql_query($sql, $link) or die(mysql_error()); //get the number of rows in the result set; should be 1 if a match if (mysql_num_rows($result) == 1) { //if authorized, get the values of f_name l_name $f_name = mysql_result($result, 0, 'f_name'); $l_name = mysql_result($result, 0, 'l_name'); //set authorization cookie setcookie("auth", "1", 0, "/", "votpservices.com", 0); //prepare message for printing, and user menu $msg = "<P>$f_name $l_name is authorized!</p>"; $msg .= "<P>Authorized Users' Menu:"; $msg .= "<ul><li><a href=\"listing15.8.php\">secret page</a></ul>"; } else { //redirect back to login form if not authorized header("Location: listing15.7.php"); exit; } ?> <html> <head> <title>Listing 15.8 User Login</title> </head> <body> <?php print "$msg"; ?> </body> </html> Hi, I'm a newbie, and needed help fixing a part of a code Whenever someone is clicking add to cart, it triggers an error. The output is: Duplicate entry Warning: Cannot modify header information - headers already sent by (output started at C:\ampp\htdocs\ptc1\pages\insertTotempsql.php:9) in C:\ampp\htdocs\ptc1\pages\insertTotempsql.php on line 56 Is there some weakness in the code causing it? line 56 is the last line. The code is <?php if( !isset( $_SESSION )){ session_start(); } $ses_id = session_id(); require_once('../Connections/connect.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <?php if(isset($_POST['id'])){ $id=$_POST['id']; $uom=$_POST['uom']; $quantity=$_POST['QUANTITY']; $date=$_POST['dateToday']; $PRICE=$_POST['PRICE']; if(isset($_POST['MeatOrigin'])){ $prod=$_POST['prodname'] . " ( " . $_POST['MeatOrigin'] . " ) "; } else { $prod=$_POST['prodname']; } mysql_select_db($database_connect, $connect); //check database if item is existing $query_duplicate = sprintf("SELECT * FROM tbl_cart WHERE pd_id='$id' and ct_session_id='$ses_id' and ct_date='$date'"); $duplicate = mysql_query($query_duplicate, $connect) or die(mysql_error()); $row_duplicate = mysql_fetch_assoc($duplicate); $totalRows_duplicate = mysql_num_rows($duplicate); if($totalRows_duplicate > 0){ echo "Duplicate entry"; } else { $insertSQL = "INSERT INTO tbl_cart ( pd_id, pd_name, ct_qty, ct_session_id, ct_date, PRICE, uom) VALUES ('$id', '$prod', '$quantity', '$ses_id', '$date', '$PRICE', '$uom')"; $Result1 = mysql_query($insertSQL, $connect) or die(mysql_error()); } mysql_close($connect); header("Location:".$_SERVER['HTTP_REFERER']); } ?> Thanks i'm having trouble working with my search bar, when i used wamp it worked but now online i keep getting this message Quote Cannot modify header information - headers already sent by (output started at...) I placed that code for the search bar above the html tags but i keep getting the error here is my coding Code: [Select] <?php mysql_connect("localhost", "user", "pass") or die(mysql_error()); if (isset($_POST['submit'])) { $search = mysql_real_escape_string($_POST['search']); $type = mysql_real_escape_string($_POST['type']); if ($type == true) { header("Location:http://www.link.com/searchresults.php?subdirectory=$search&type=$type"); } } ?> This is the error message: Warning: Cannot modify header information - headers already sent by (output started at /home/public_html/main.php:12) in /home/public_html/main.php on line 61 I've tried reading into this but find no solutions if anyone can help I would be very grateful. I'm just trying to get the code to take the user to register page if they not a member heres the code im using <table border="0" width="220" align="center"> <tr> <? if(!session_is_registered("username")){ // if session variable "username" does not exist. echo "<td width='71'>Username:</td> <td width='139'><input type='text' name='username' size='16' style='font-family: Times New Roman, Times, serif; font-size: 11pt;' /></td> </tr> <tr> <td width='71'>Password:</td> <td width='139'><input type='password' name='password' size='16' style='font-family: Times New Roman, Times, serif; font-size: 11pt;' /></td> </tr> <tr> <td colspan='2' align='center'><input name='login' type='submit' value='Log In' style='background-color: #900002; border-color: #555555; color: #FFFFFF; font-weight: bold; width: 60px;' /></td>"; }else{ echo "<td><b>Welcome $username</b><br /><a href='logout.php'><b>Logout</b></a></td>"; } ?> </tr> </table> </form></div> <div id="menutext"><span class="class1"><a href="http://www.fightwatcher.com">Home</a> <a href="http://www.fightwatcher.com">News</a> <a href="http://www.fightwatcher.com">Profile</a> <a href="http://www.fightwatcher.com">Friends & Fighters</a> <a href="http://www.fightwatcher.com">Videos</a> <a href="http://www.fightwatcher.com">Groups</a> <a href="http://www.fightwatcher.com">Forum</a></span></div> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <? if(!session_is_registered("username")){ header("Location: http://www.fightwatcher.com/register.html"); }else{ include("connect.php"); $result = mysql_query("SELECT * FROM signup ORDER by date AND time LIMIT 10"); echo "<table cellpadding=0 cellspacing=0 width=163> <tr bgcolor=#990000><td colspan=2 align=center height=24><font color=#FFFFFF><b>Newest Users:</b></font></td></tr>"; while($row = mysql_fetch_array($result)) { $username = $row['username']; $gender1 = $row['gender']; if ($gender1=="male") { $gender2="<font color=#0066FF><b>M</b></font>"; } if ($gender1=="female") { $gender2="<font color=#FF33CC><b>F</b></font>"; } echo "<tr><td align=center width=100>$username</td><td align=center width=57>$gender2</td></tr>"; } echo "</table>"; } ?> </body> Thanks Hi... I'm a little bit new to php and it seems I am getting a small issue that I am not able to resolve... Basicly I just have a page in wich you see the account file of a customer and you can add notes into it. Here's the account file script Code: [Select] <?php mysql_connect("localhost", "user", "pass") or die(mysql_error()); mysql_select_db("db") or die(mysql_error()); if( ($_GET['cmd']=="view") && (is_numeric($_GET['id'])) ) { $id=$_GET['id']; $data = mysql_query("select * from client_table WHERE id_client='$id'") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { echo " <table border=\"0\" celppadding=\"0\" cellspacing=\"0\" style=\"font-weight: bold; width: 820px;\"> <tr> <td colspan=\"2\" style=\"height: 50px;\"><a href=\"../dashboard.php\">Panneau de controle</a> > <a href=\"clients.php\">clients</a> > <a href=\"view_client.php?cmd=view&id=".$info['id_client']."\">Fiche client</a> > Notes > ".$info['entreprise']."</td> </tr> <tr> <td style=\"padding-left: 10px\"> NEQ : ".$info['neq']."<br /> <h2>Nom de l'entreprise : ".$info['entreprise']."<br /></h2> <h2>Telephone : ".$info['client_phone']."<br /></h2> </td> </tr> </table> "; } } ?> <form enctype="multipart/form-data" action="process/insert_note.php" method="POST" target="main"> <input type="hidden" name="id_client" value="<?php echo $id; ?>"> <input type="hidden" name="note_date" value="<?php echo date("Y-m-d"); ?>"> <input type="hidden" name="note_time" value="<?php echo date("G:i:s"); ?>"> <table border="0" celppadding="0" cellspacing="0" style="font-weight: bold; width: 780px;"> <tr> <td colspan="0" style="padding-left: 10px">Ajouter une note : <br /><textarea name="note" style="height: 80px;" cols="90"></textarea><br /> <input type="submit" value="Ajouter une note"> </td> </tr> </table> </form> So when I add the note....the form data is passed to a php script to insert the note into the MySQL DB and I just want to be redirected back to the acount file page with the note on it.... Here's the insert script : Code: [Select] <?php header('location:../view_notes.php?cmd=view&id=$id_client'); require_once('../../auth.php'); $id_client = $_POST['id_client']; $con = mysql_connect("localhost","user","pass"); $note_date = $_POST['note_date']; $note_time = mysql_real_escape_string($_POST['note_time']); $note = mysql_real_escape_string($_POST['note']); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("db", $con); $sql="INSERT INTO notes_table ( id_client, note_date, note_time, note) VALUES ('$id_client','$note_date','$note_time','$note')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } ?> The problem I have is that the HEADER part is working but the value : header('location:../view_notes.php?cmd=view&id=$id_client'); is not passed so I am redirected to a blank page..... I tried to find the info on google but can't seems to find what wrong... Any help will be appreciated! Thanks this code works if i use the header() in the else section it doesnt but it will echo the commented part Code: [Select] <? /** * User has already logged in, so display relevant links, including * a link to the admin center if the user is an administrator. */ if($session->logged_in){ echo "<li>Logged In "; echo "<b>$session->username</b></li>"; if($session->isAdmin()){ echo "<li><a href=\"LoginSystem/admin/admin.php\">Admin Center</a></li>"; } echo "<li><a href=\"../LoginSystem/process.php\">Logout</a</li>"; } else{header("Location: ../LoginSystem/main.php"); //echo "<li><a href=\"../LoginSystem/process.php\">Login</a></li>"; } ?> Before asking, I have read this. http://www.phpfreaks.com/forums/index.php?topic=37442.0 I am just confused why my header still doesn't work. I don't think I'm outputting anything in the else statement where my header(Location: 'registerconf.php') is; Here's the code Code: [Select] <?php require('includes/header.php'); ?> <?php //VARIABLES $submit = mysql_real_escape_string($_POST['submit']); $username = mysql_real_escape_string($_POST['username']); $user = $_POST['username']; $firstname = mysql_real_escape_string($_POST['firstname']); $lastname = mysql_real_escape_string($_POST['lastname']); $email = mysql_real_escape_string($_POST['email']); $password = mysql_real_escape_string($_POST['password']); $passwordconf = mysql_real_escape_string($_POST['passconf']); $ageconf = mysql_real_escape_string($_POST['ageconf']); $tosconf = mysql_real_escape_string($_POST['tosconf']); $loweruser = strtolower($username); $checkuser = mysql_query("select * from users where username_lower='{$loweruser}'"); $userexists = mysql_fetch_assoc($checkuser); $emailexistsquery = mysql_query("select * from users where email='{$email}'"); $emailexists = mysql_fetch_assoc($emailexistsquery); /*CHECKS * Many checks need to be done, the checks will also be done in order. The order will * be listed here * */ if(isset($_POST['submit'])) { if(empty($username)||empty($firstname)||empty($lastname)||empty($email)||empty($password)||empty($passwordconf)){ echo('Please fill out all fields!<br/>'); }else{ if($userexists) { echo "Username $username already exists"; }else{ if(strlen($username)>15||strlen($username)<5) { echo "Username must be between 5 and 15 characters"; }else{ if (!preg_match('/^[a-zA-Z0-9]+$/', $user)) { echo "Username can only contain letters and numbers with no spaces"; }else{ if(strlen($firstname)>20) { echo "Your first name cannot be larger than 20 characters"; }else{ if(!preg_match('/^[A-Z]{1}[a-z]+$/', $firstname)) { echo "Your first name can only contain letters and must start with a capital followed by lowercase letters"; }else{ if(strlen($lastname)>20) { echo "Your last name cannot be larger than 20 characters"; }else{ if(!preg_match('/^[A-Z]{1}[a-z]+$/', $lastname)) { echo "Your last name can only contain letters and must start with a capital followed by lowercase letters"; }else{ if(strlen($email)>40) { echo "Email cannot be longer than 40 characters"; }else{ if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "Invalid Email"; }else{ if($emailexists) { echo "Email already exists"; }else{ if(strlen($password)<5||strlen($password)>30) { echo "Password must be between 5 and 30 characters"; }else{ if($password!=$passwordconf) { echo "Passwords don't match"; }else{ if($ageconf=='') { echo "You must be 16 or older to register"; }else{ if($tosconf==''){ echo "You must agree with the Terms of Service"; }else{ //add to database $mdpass = md5($password); $rand = rand('12345','54321'); $activekey = time()+$rand; $query = "insert into users set username='{$username}', username_lower='{$loweruser}', firstname='{$firstname}', lastname='{$lastname}', email='{$email}', activationcode='{$activekey}', password='{$mdpass}'"; $query2 = mysql_query("select * from users where username='{$username}'"); mysql_query($query); $sqluserid = mysql_fetch_assoc($query2); $userid = $sqluserid['id']; $to = $email; $subject = "Activate your account"; $message = "Welcome to Site! $firstname! </br> Thank you for taking your time to register an account for the Site Networks your click the link below to activate your account! </br></br> <a href=ns.com/registerconf.php?pid=$userid&activate=$activekey; "; header('Location: registerconf.php'); } } } } } } } } } } } } } } } echo ""; } echo "<table> <form name='login' method ='POST' action='register.php'> <tr><h3>Register your account and get access to all of the Networks!<h3></tr> <tr><td>Username</td><td><input type='text' name='username' value=".$username."></td></tr> <tr><td>First Name</td><td><input type='text' name='firstname' value=".$firstname."></td></tr> <tr><td>Last Name</td><td><input type='text' name='lastname' value=".$lastname."></td></tr> <tr><td>Email</td><td><input type='text' name='email' value=".$email."></td></tr> <tr><td>Password</td><td><input type='password' name='password'></td></tr> <tr><td>Confirm Password</td><td><input type='password' name='passconf'></td></tr> <tr><td>I am 16 or older</td><td><input type='checkbox' name='ageconf'></td></tr> <tr><td>I agree with the <a href='tos.php'>terms of service</a></td><td><input type='checkbox' name='tosconf'></td></tr> <tr><td><input type='submit' name='submit' value='Register'> </form> </table> "; ?> <?php require('includes/footer.php'); ?> It might be the sql statement but I need that for the user id. Thanks Hello everybody, I created a function called 'imgCreate ()' to resize an image. I'm trying to use this function to recreate images in two sizes that I need from a base image received by upload. The question is, the two images are created from the base image that I keep in a folder 'uploads', the original image is saved correctly now two other file is created, but it only comes with zero bytes and the image does not appear, or is not properly created. Another thing also happened is that the images began to be displayed in binary. I tried to insert the header ("Content-type: image / jpeg) but still does not work. I've tried several ways to correct but still not had success, if someone can me better target for correction of these errors will be immensely grateful. Below is the code I'm using. Function 'imgCreate()' in file 'funcoes.php': <?php function imgCreate($imgjpg, $width_target) { $img = imagecreatefromjpeg($imgjpg); $width_origin = imagesx($img); $heigth_origin = imagesy($img); $heigth_new = (int)($heigth_origin * $width_target)/$width_origin; $new = imagecreatetruecolor($width_target,$heigth_new); $criado = imagecopyresampled($new, $img, 0, 0, 0, 0, $width_target, $heigth_new, $width_origin, $heigth_origin); if($criado){ header("Content-type: image/jpeg"); echo imagejpeg($new, $arquivo, 100); } else return "Not possible create image!"; } ?> Code where I'm trying to use the function: <?php require 'funcoes.php'; $photo = $_FILES["photo"]; if(isset($photo)) { $widthThumb = 117; $widthImage = 350; $newNamePhoto = uniqid(time()); $newPhoto = "../uploads/".$newNamePhoto; $newNameThumb = $newNameFoto."_thumb.jpg"; $newNameImage = $newNameFoto."_img.jpg"; move_uploaded_file($photo['tmp_name'], $newPhoto); $thumb = imgCreate($newFoto, $newPhoto, $widthThumb); $file = fopen("../uploads/".$newNameThumb,"wb"); fwrite($file, $thumb, sizeof($thumb)); fclose($file); $image = imgCreate($newFoto, $newPhoto, $widthImage); $file = fopen("../uploads/".$newNameImage,"wb"); fwrite($file, $image, sizeof($image)); fclose($file); } ?> hi there, seems like I'm getting a fairly common beginners php error but as I'm using a number of differant files and as I'm not entirley clear on a couple of things I thought I'd tap into the immense php talent on this site here's the error - Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Epointment\index.php:4) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Epointment\ot\views\header.php on line 38 I have an index page that allows a user to log on, the processing go's away and checks the usual stuff then reloads the login page with the user detail or just reloads the login page with the user/password fields blank. This seemed to be working ok until I put my files onto another web server that had output_buffering turned off. here's part of the login page Code: [Select] <html> <head><title></title></head> <body> <?php ini_set("display_errors", "1"); error_reporting(-1); $dir = dirname(__FILE__); require_once "$dir/ot/ot.php"; ot::include_view('header', array('account' => null)) ?> // various stuff <p>Please login below</p> <?php ot::include_view('login_form')?> the ot.php file doesn't have any echo's or print_r's etc if that helps?? here's the header.php file.. <?php Code: [Select] if (ot::get('do_logout', 0) == 1) { ot::destroy_session(); header("Location: http://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']}"); exit; } elseif (self::post('do_reset_password')) { ot::do_reset_password($err); echo "$err"; } $adb = ot::db('account'); $account = null; $error = ""; $id = ot::account_id(); if ($id) { $account = ot::account_from('id', $id); $res = ot::do_change_password($account, $err); if ($res) { echo "<p>Password Changed Successfully</p>"; $account = $res; } else if ($err) { echo "<p>Error: $err</p>"; } $res = ot::do_change_email($account, $err); if ($res) { echo "<p>Email Changed Successfully</p>"; $account = $res; } else if ($err) { echo "<p>Error: $res</p>"; } } else { $account = ot::do_login(); if ($account) { header("Location: http://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']}"); exit; } } ?> here's the ot::do_login function Code: [Select] public static function do_login(&$err="") { $adb = ot::db('account'); $e = self::post('email'); $p = self::post('pwd', '', false); if (self::post('do_login') && $e && $p) { $ao = self::account_from('email', $e); if ($ao) { if (self::validate_login($e, $p, $ao)) { //echo "\n"."hit2"; $_SESSION['id'] = $ao->id; return $ao; } } $err = "Invalid email or password"; return false; } } and here's the login_form.php, which is called from ot::do_login from header.php ... Code: [Select] <form action='<?php echo $_SERVER['REQUEST_URI']?>' method='post' > <p>Email:<br/><input type='text' name='email' /></p> <p>Password:<br/><input type='password' name='pwd' /></p> <p><input type='submit' name='do_login' value='Login' /> <input type='submit' name='do_reset_password' value='Reset Password' /></p> </form> Any pointers or useful things I've not posted? is this bit of code from above ok? as in I'm doing some php stuff before the header() function gets used? Code: [Select] <html> <head><title></title></head> <body> <?php ini_set("display_errors", "1"); error_reporting(-1); $dir = dirname(__FILE__); require_once "$dir/ot/ot.php"; ot::include_view('header', array('account' => null)) I hate header errors... I can never figure them out, im getting this error; Warning: Cannot modify header information - headers already sent by (output started at /home/damnpeti/public_html/restrict2.php:6) in /home/damnpeti/public_html/restrict2.php on line 62 Code: <?php $testDB = mysql_connect('localhost', $db_user, $db_pwd); mysql_select_db ($db_name); if (!$testDB) { die('Could not connect: ' . mysql_error()); } $surfer_ip = $_SERVER["REMOTE_ADDR"]; $str_sql = "select * from ".$db_table." where ipaddress='".$surfer_ip."'"; $result = mysql_query($str_sql); if ($row = mysql_fetch_assoc($result)) { $blocked_time = strtotime($row['blocked_time']); if($blocked_time != 0) { $current_time = time(); if($current_time - $blocked_time > 3600*24) //24 hours past { $str_sql = "delete from ".$db_table." where ipaddress='".$surfer_ip."'"; mysql_query($str_sql); $str_sql = "insert into ".$db_table." (ipaddress, surf_index) values('".$surfer_ip."', 1)"; mysql_query($str_sql); } else { die ("<center><div class='errors'>You have accessed this page too many times. To regain access, purchase a license or wait 24 hours.</div></center>"); } } else { if($row['surf_index'] < 2) { $str_sql = "update ".$db_table." set surf_index=surf_index+1 where ipaddress='".$surfer_ip."'"; mysql_query($str_sql); } else { $str_sql = "update ".$db_table." set blocked_time='".date ("Y-m-d H:i:s")."' where ipaddress='".$surfer_ip."'"; mysql_query($str_sql); die ("<center><div class='errors'>You have accessed this page too many times. To regain access, purchase a license or wait 24 hours.</div></center>"); } } } else { $str_sql = "insert into ".$db_table." (ipaddress, surf_index) values('".$surfer_ip."', 1)"; mysql_query($str_sql); } if(!isset($_COOKIE['surf_no'])) setCookie('surf_no', '1'); else setCookie('surf_no', $_COOKIE['surf_no']+1); if ($_COOKIE['surf_no'] > 2) die("<center><div class='errors'>You have accessed this page too many times. To regain access, purchase a license or wait 24 hours.</div></center>"); include 'http://damnitpetitions.com/cut/index3.php'; ?> Line 62 is if ($_COOKIE['surf_no'] > 2) I know it has something to do with the cookie... but Idk? I need the include there. If there include isnt where its at, the script is worthless. Hello, I have a simple login script that basically, when if you go to a page and you are NOT logged in (saved in cookie) then you get redirected to the login page, else the content is shown. It works, but I currently have my database connection details on the same page, I like to have them on a separate PHP and use require 'connet.php'. So I've gone ahead and done that, but now I get an error saying "Warning: Cannot modify header information - headers already sent". This only happens if I'm NOT logged in. It has something to do with my require "connect.php"; because if I comment that out, it works fine. Here is the script: Code: [Select] <?php //require "connect.php"; // < causes header error // Connects to your Database mysql_connect("localhost", "user", "pass") or die(mysql_error()); mysql_select_db("db") or die(mysql_error()); //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )){ //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']){ header("Location: index.php"); } //otherwise they are shown the admin area else{ ?> - content - <a href=logout.php>Logout</a> <? } } } //if the cookie does not exist, they are taken to the login screen else{ header("Location: index.php"); } ?> My connect.php page is just: Code: [Select] <? // Connects to your Database mysql_connect("localhost", "user", "pass") or die(mysql_error()); mysql_select_db("db") or die(mysql_error()); ?> Why is the require causing this error, and how do I fix it? Thanks |