PHP - Get Id From Header??
Hi everyone,
I have a login area, and i also have set up for me is a view page... the view page is each user's sort of profile, it gets id and displays relevant content. i was wondering if i could get the id or post rather through a re-direct on log in? for example user logs in with username and password, user is re-directed to the view page like this: header( "refresh:5;url=view00=id.php " ); echo '<h1>You will be re-directed in 5 seconds...</h1>'; user is taken to view page where they can edit bit on it. So far though i'm getting page not found error? first of all is this possible? if not whats the correct way/better way? Thanks Similar TutorialsHello everyone, I'm just starting out with PHP as I need to create an online bookstore for a school project. I'm working by a magazine which should teach you exactly how to do this using PHP, but I've had a bunch of problems with the code they use and I don't really know what's going on. Anyway, this looks really simple and basically what it does is allows you to post a comment on a book, then returns you to the book's page. Problem is, I'm getting the Header may not contain more than a single header, new line detected. error and I can't figure out why. I've tried researching into the matter but all the cases I found had to do with returning to an url, which is not my case. Anyway, here's the snippet of code: The form: Code: [Select] <div style="width:400px; border:1px solid #ffffff; background-color:#F9F1E7; padding:5px"> <b>Adauga opinia ta:</b> <hr size="1"> <form action="adauga_comentariu.php" method="POST"> Nume: <input type="text" name="nume_utilizator"><br><br> Email: <input type="text" name="adresa_email"><br><br> Comentariu: <br> <textarea name="comentariu" cols="45"></textarea><br><br> <input type="hidden" name="id_carte" value="<?=id_carte?>"> <center><input type="submit" value="Adauga"</center> </form> </div> The script adaugare_comentariu.php: Code: [Select] <?php ob_start(); include("conectare.php"); $numeFaraTags=strip_tags($_POST['nume_utilizator']); $emailFaraTags=strip_tags($_POST['adresa_email']); $comentariuFaraTags=strip_tags($_POST['comentariu']); $sql="insert into comentarii (id_carte, nume_utilizator, adresa_email, comentariu) values(".$_POST['id_carte'].", '".$numeFaraTags."','".$emailFaraTags."','".$comentariuFaraTags."')"; mysql_query($sql); $inapoi="carte.php?id_carte=".$_POST['id_carte']; header("location:urldecode($inapoi)"); ob_end_flush(); ?> conectare.php connects to the mysql database. $inapoi is the variable which returns the user to carte.php (the book he posted a comment on), where id_carte is the book's unique id. I'm getting Header may not contain more than a single header, new line detected on line ten, which is the header line. Can anyone help me? I've been stumped on this for a few days now and I've just let it pass and started working on other bits, but it's bugging me too much and I'd like to fix it. This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=350027.0 Hi there, I have a form which displays a "successful" message if the form is completed correctly. However, I want the form to go to another url if it is successful. I have tried this, but I get the "headers already sent..." message // Add New Subscriber Success Message $successMsg = header('Location: http://www.example.com/'); is there another way to forward onto another page? Thanks Hi is there a way that i can set header not go anywhere like the problem with this is that it still goes to the second header is there a way i can set if none do nothing exit? and else do the second header?? Code: [Select] <?php if ($_POST['agents']=="none") { header("location:#"); exit; // header("Location: {$_SERVER['PHP_SELF']}"); } else { header("location:http://www.xxxxxx.co.uk/tv/".$_POST['agents']."/index.php"); } ?> Hey guys, I have a problem, i'm using ob_start to send multiples headers and it works but the problem is that my metada is not being sent, when i remove the ob_start it gets sent. Is there a way i can allow more info to be sent with ob_start? or should i use other methods to redirect to pages? i dont want to use javascript or meta http because they are not very reliable is there any other way? Thanks for help. How do I get this to put in the pilotID? Code: [Select] header("Location: logbook.php?id=" . $pilotid); Thanks! Can some one help please i always get this wrong dont now why keep saying header already been sent any help please and how to fix it Code: [Select] <?php session_start(); $conn = mysql_connect(""); $db = mysql_select_db("", $conn); if(isset($_POST['submit'])){ $user = mysql_escape_string($_POST['user']); $pass = mysql_escape_string($_POST['pass']); } if(empty($user) && empty($pass)){ exit; }else{ } ?> <?php $sql = mysql_query("SELECT * FROM useradmin WHERE dbusername= '".$user."' AND dbuserpass= '".$pass."'")or die(mysql_error()); $row = mysql_fetch_assoc($sql); $count = count($sql); $u = $row['dbusername']; $p = $row['dbuserpass']; if($u == $user && $p == $pass){ $_SESSION['access'] = "$u"; header("location: index.php"); }else { echo "Sorry there as been a problem!"; exit; } ?> Does starting a Session send data to the Header? Debbie Can someone assist with this, the form works, but the end user cannot simply click on reply, they have to copy/paste. I think it is just a header issue, but i'm not sure and the person who wrote this script is no longer availalble...any help would be much appreciated! Code: [Select] <?php if ($_POST['post'] != '') { $to = 'fetch@domain.com'; $subject = 'Appointment Request'; $message = "A user on the website has submitted an appointment request. Find their details below.\n\n"; $reqd = array('name', 'email', 'phone', 'phonetype1', 'petname'); $disregard = array('post', 'Appointment_Mail_'); $breaks = array('break', 'break2', 'break3'); foreach($_POST as $key=>$value) { if (in_array($key, $reqd) && $value == '') { $error .= '- Fill out '.$key.'<br />'; } elseif (!in_array($key, $disregard)) { if (in_array($key, $breaks)) { $message .= "\n"; } else { $message .= ucwords($key).": ".stripslashes($_POST[$key])."\n"; } } } if ($error == '') { mail('fetch@domain.com', $subject, $message, 'From: domain.com <noreply@domain.com>'); header('Location: http://www.domain.com/thanks.html'); die(); } else { $error = 'Please correct the following errors:<br />'.$error; } } ?> 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 Hi everyone, I have a login area, and i also have set up for me is a view page... the view page is each user's sort of profile, it gets id and displays relevant content. i was wondering if i could get the id or post rather through a re-direct on log in? for example user logs in with username and password, user is re-directed to the view page like this: header( "refresh:5;url=view00=id.php " ); echo '<h1>You will be re-directed in 5 seconds...</h1>'; user is taken to view page where they can edit bits on it. So far though i'm getting page not found error? first of all is this possible? if not whats the correct way/better way? 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 want to set the correct header / cache values for a site. I am working on a social network / forum style site. I want to ensure that every page a user requests results in a fresh one being requested from the server as most content changes by the minute. (1) How would I set this? (2) Also, can I prevent nav bars being reloaded as these never, ever change. 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.''); } } ?> I currently have a login script in place on my site and to get to certain pages you have to be logged in to get to. So when a user tries to go to one of those pages and is not logged in it sends them to the login page (which is great) But on the login page once they login it uses " header('Location: index.php') " to automatically send them to the index page logged in. How can i dynamically see what page they are coming from that way when they login I can send them back to where they where trying to get to to begin with. (like if they click on "Profile" and they are not logged in it sends them to "login" then they login and it currently sends them to "index" I want it to dynamically know to send them back to "profile" instead) If this doesn't make sense and i will try and explain it better But if you understand and know how to do this please help Thanks ahead of time! I've got this sign in code: Code: [Select] [php] <?php include("conf.inc.php"); // Includes the db and form info. if ($_SESSION['logged'] == 1) { // User is already logged in. $_SESSION['email'] = $email; header("Location: main.php"); // Goes to main page. exit(); // Stops the rest of the script. } else { if (!isset($_POST['submit'])) { // If the form HAS NOT been submitted. echo "<td width=\"320\" height=\"50\" align=\"left\" valign=\"middle\"> </td>"; echo "<td width=\"360\" height=\"50\" align=\"left\" valign=\"middle\">"; echo "<form name=\"form\" action=\"index.php\" method=\"POST\" style=\"margin-bottom:0;\">"; echo "<a href=\"signup.php\" class=\"bluelink\">Sign Me Up!</a> "; echo "<a href=\"pwordhelp.php\" class=\"bluelink\" onMouseOver=\"window.name = 'main'\" onClick=\"return popup(this, 'notes')\">Forgot Password</a><br>"; echo "<input type=\"text\" name=\"email\" size=\"17\" value=\"Email...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Email...') {this.value=''; this.style.color='#000000'}\"> "; echo "<input type=\"password\" name=\"pword\" size=\"17\" value=\"Password...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Password...') {this.value=''; this.style.color='#000000';}\"> "; echo "<input type=\"submit\" name=\"submit\" value=\"Submit\">"; echo "</form>"; } else { // If the form HAS been submitted $email = form($_POST['email']); $pword = md5($_POST['pword']); // Encrypts the password. $q = mysql_query("SELECT * FROM `signin` WHERE email = '$email' AND pword = '$pword'") or die (mysql_error()); // mySQL query $r = mysql_num_rows($q); // Checks to see if anything is in the db. if (!$r) { // There is nothing in the db. The username/password do not match up. echo "<td width=\"108\" height=\"50\" align=\"left\" valign=\"middle\"> </td>"; echo "<td width=\"572\" height=\"50\" align=\"left\" valign=\"middle\">"; echo "<form name=\"form\" action=\"index.php\" method=\"POST\" style=\"margin-bottom:0;\">"; echo " <a href=\"signup.php\" class=\"bluelink\">Sign Me Up!</a> "; echo "<a href=\"pwordhelp.php\" class=\"bluelink\" onClick=\"return popup(this, 'notes')\">Forgot Password</a><br>"; echo "<font color=\"#FF0000\"><strong>Incorrect Email or Password.</strong></font> "; echo "<input type=\"text\" name=\"email\" size=\"17\" value=\"Email...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Email...') {this.value=''; this.style.color='#000000'}\"> "; echo "<input type=\"password\" name=\"pword\" size=\"17\" value=\"Password...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Password...') {this.value=''; this.style.color='#000000';}\"> "; echo "<input type=\"submit\" name=\"submit\" value=\"Submit\">"; echo "</form>"; } else { // If the username/password is invalid $_SESSION['logged'] = 1; // Sets the session. $_SESSION['email'] = $email; header("Location: main.php"); // THIS IS LINE 111 exit(); // Stops the rest of the script. } } } ?> [/php] And when I sign in with my user name and password, I get this warning message: Warning: Cannot modify header information - headers already sent by (output started at /home/content/29/6879529/html/calhoun/index.php:9) in /home/content/29/6879529/html/calhoun/head1.inc.php on line 111 Can anyone help me out and tell me what I need to do to correct this? Thanks in advance for your help! Hello! I need a while loop that renders out part of my "header" redirect block. <?php header ('Location: /mylocation?' /////this is where the header starts. however, for the rest of the header, it needs to be dynamic $counter=1; //I need to define some variables while (babababa) // and I need a while loop that renders out stuff for the header. { Renders out stuff for the header } ) // and then finally i close the "header" ?> However, apparently.. it's yelling at me for having dynamic stuff within the header. Parse error: syntax error, unexpected T_WHILE in /var/www/ars/includes/common.inc(1699) : eval()'d code on line 18 So.... how would I put something dynamic, like a while loop or variables, within the "header" redirect block? Thanks folks! Sorry if this is a bad question xD 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 have a php page that is maid up of three pieces. header.php main.php footer.php I can't figure out how to refresh the header.php and footer.php without refreshing the main.php. Anyone have an example of how I can do this. Thanks hits 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? |