PHP - Echoed 'logout' Link Not Working...
Hey there guys, small problem here that I can't seem to figure out. I am in the process of programming a database with user-access control. I have the log-in system working great, but the logout link, which is located next to the logged-in username seems to not be echoing correctly. It is loading the 'Logout' text in text-form only, not link-form....
Any ideas on what may be causing this small glitch?? Thanks!! I have attached relevant code for said part for reference. <img src="images/username.png" height="20" width="20"> <b>Welcome</b> <?php echo ("<font color=#9e0219>$username</font>");?>, <?php echo '<a href="logout.php">Logout</a>';?> Similar TutorialsI am having problems understanding the reason for why the user has to click logout twice, here's the bulk of the code: <?php ini_set('display_errors',0); require_once 'header.html'; require_once 'db.functions.php'; require_once 'config.php'; $database = dbConnect($host, $username, $password, $database); // should output 1 or nothing at all! if($database == true) { // now connected? // carry on with logic of outputting the blog contents: $result = entries("SELECT * FROM entries"); printf("<table>"); while($row = mysql_fetch_array($result)) { printf(" <tr> <td>%s</td> <td>%s</td> </tr> <tr> <td colspan=\"2\">%s</td> </tr> ", $row[2], $row[4], $row[3]); } printf("</table>"); printf("\n\n"); session_name("jeremysmith_blog"); session_start(); if(array_key_exists('login',$_SESSION)) { if($_SESSION['login'] == 1) // change this to correspond with session on the login.php script { printf("<p>Welcome %s</p> <p>To logout, click <a href=\"index.php?action=logout\">here</a></p> ",$_SESSION['username']); } } else { printf("<p>You are not logged in, please click <a href=\"login.php\">here</a> to login.</p>"); } } else { printf("\n<p id=\"error\">Could not connect to database, please try again later.</p>"); } // init the logout script? if(array_key_exists('action',$_GET)) { if($_GET['action'] == 'logout') { // log user out of the system: unset($_SESSION['login']); unset($_SESSION['username']); session_destroy(); } } printf("\n"); // just for output format! require_once 'footer.html'; Why does the user have to click logout twice, have I missed anything? Any helps appreciated thanks. For some reason my logout is not working properly. I searched other forum posts and read some tutorials but I still have an issue. Do this to create session: Code: [Select] $_SESSION['username'] = $row['username']; setcookie('username', $row['username'], time() + (60 * 60 * 24 * 5)); Do this to log out the user Code: [Select] session_start(); session_unset(); $_SESSION = array(); setcookie(session_name(), '', time() - 3600); session_destroy(); setcookie('username', '', time() - 3600); Above all else I am trying to end the $_SESSION['username'] Thank you all I am new to php.i want to be able to link echoed out rows from a table to another row in another table so that when users clicked the first row i echoed out it will take them to that SPECIFIC row i linked it to in the second table..JUST LIKE FACEBOOK...Please do i make sense or is there another way to do it. Thanks in advance here's my code that i've used to send an email. Code: [Select] $link = "<a href=\"http://www.example.com/" . $num . "\">" . $num . "</a>"; $query = "SELECT content FROM emails"; $result = mysql_query($query) or die(); $email_content = mysql_result($result, 0); $email = sprintf($email_content, $first, $name, $from, $link, $record, $rec, $inc, $max); $email_body = stripslashes(htmlentities($email, ENT_QUOTES, 'UTF-8')); // this is sent to another php script via post.... $subject = $_POST['subject']; $message = nl2br(html_entity_decode($_POST['email_body'])); $to = "me@whatever.com"; $charset='UTF-8'; $encoded_subject="=?$charset?B?" . base64_encode($subject) . "?=\n"; $headers="From: " . $userEmail . "\n" . "Content-Type: text/html; charset=$charset; format=flowed\n" . "MIME-Version: 1.0\n" . "Content-Transfer-Encoding: 8bit\n" . "X-Mailer: PHP\n"; mail($to,$encoded_subject,$message,$headers); in the db, emails.content is of the text type and contains several lines of text with %4$s which inserts the value of $link into the body. when the email arrives, there is a link and it appears fine, with the value of $num hyperlinked. however when you click on it it doesn't go anywhere. when copying the link location from the email it gives me x-msg://87/%22http://www.example.com/16 what is x-msg? how can i get this to work properly? I echoed the query once and it came up as UPDATE `fields` SET `enabled` = 'True' WHERE `ID` = ''good Not sure why. Code: [Select] <?php // Include the database page include ('../inc/dbconfig.php'); $styleID = $_GET['id']; $query = "SELECT fields.ID, fields.fullName, fields.enabled FROM fields INNER JOIN styles ON styles.ID = fields.styleID WHERE styles.ID = '" . $styleID . "'"; $result = mysqli_query ( $dbc, $query ); // Run The Query ?> <script> $(document).ready(function() { $('div.message-error').hide(); $('div.message-success').hide(); $("#bioConfigForm").submit(function() { $('div.message-error').hide(); var data = $(this).serialize() + "&submitBioFields=True"; $.ajax({ type: "POST", url: "processes/bioconfig.php", data: data, success: function() { $('div.message-error').hide(); $("div.message-success").html("<h6>Operation successful</h6><p>Bio fields saved successfully.</p>"); $("div.message-success").show().delay(10000).hide("slow", function() { $('#content').load('mods/bioconfiguration.php'); }); } }); return false; }); }); </script> <!-- Title --> <div id="title" class="b2"> <h2>Bio Configuration</h2> <!-- TitleActions --> <div id="titleActions"> <!-- ListSearch --> <div class="listSearch actionBlock"> <div class="search"> <label for="search">Recherche</label> <input type="text" name="search" id="search" class="text" /> </div> <div class="submit"> <button type="submit" id="search-button" class="button"><strong><img src="img/icons/search_48.png" alt="comments" class="icon "/></strong></button> </div> </div> <!-- /ListSearch --> </div> <!-- /TitleActions --> </div> <!-- Title --> <!-- Inner Content --> <div id="innerContent"> <!-- Form --> <form action="#" id="bioConfigForm" > <fieldset> <legend>Bio Config</legend> <?php while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { ?> <div class="field"> <label for="<?php '' . $row['ID'] . '' ?>"><?php echo '' . $row['fullName'] . ''?></label> <input type="radio" value="0" name="<?php echo $row['ID']; ?>" class="status" <?php if($row['enabled'] == 0) echo ' checked="checked"'; ?> />Enabled <input type="radio" value="1" name="<?php echo $row['ID']; ?>" class="status" <?php if($row['enabled'] == 1) echo ' checked="checked"'; ?> />Disabled </div> <?php } ?> <input type="submit" class="submit" name="submitBioFields" id="SubmitBioFields" title="Submit Bio Fields" value="Submit Bio Fields"/> </fieldset> </form> <!-- /Form --> Code: [Select] <?php // Include the database page require ('../inc/dbconfig.php'); if (isset($_POST['submitBioFields'])) { foreach($_POST as $bioFieldID => $value) { $query = "UPDATE `fields` SET `enabled` = '".$value."' WHERE `ID` = '".$biofieldID."'"; } mysqli_query($dbc,$query); $result = "good"; } else { $result = "bad"; } //Output the result echo $result; ?> So I'm kind of new to PHP, and have been having lots of success, but I have no idea why this is occuring. It's probably a super easy answer...
I have a form that has checkboxes. Essentially I am echoing out the results of which ever checkboxes the user checks. Here's my code...
if(!empty($_POST[$i])){ foreach($_POST[$i] as $check){ $answer .= $check; } echo $answer;And the result that is echoed out says this.. ArraySF6Nitrogen (SF6 is one of the checkboxes that was selected, and Nitrogen is the other checkbox that was selected) I would be incredibly happy if the echoed out result just said SF6Nitrogen My question is why does it say "Array" first? Edited by trevzilla, 05 November 2014 - 01:26 PM. Ok, here's what I'm trying to do. In Zend, you can modify a template title for a page within the actual template file even though the title has already been set. So, say I have this in a common header file: Code: [Select] <?php echo $title; ?> ..but I then want to maybe change that within my main template page, say my 'about' page. How would I go about that? Currently I do this: include($commonheader); include($content); include($footer); It's in the content where I want to be able to change the title in the header, should I need to. You can do this with Zend but it's beyond me how they do it. Should note, the above is for simplicity sake. I am doing this using OOP methods. Any help appreciated. Maybe ob_flush? Hey there I've adapted the search code from the tutorial on this site here http://www.phpfreaks.com/tutorial/simple-sql-search for a project I've been working on but have an error. The search works just fine but if either of the messages I've included are tripped (zero search characters or nothing found) then I get a blank screen and the error message is not echoed. (The vanilla code works fine - the error has arisen through the changes I needed to make). I don't know why this is happening and would appreciate some help please. Thanks in advance for any help. Code: [Select] session_start(); // check session variable if (isset($_SESSION['first_name'])) { include ('includes/header_loggedin.html'); //db connection info deleted $error = array(); //get search term, strip it if (isset($_GET['search'])) { $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 1) { $error[] = 'Search terms must be longer than 1 character.'; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } //formulate query if (count($error) < 1) { $query = "SELECT * FROM table WHERE row LIKE '%{$searchTermDB}%'"; //make the query $result = mysql_query($query) or die(mysql_error()); //display the results if (mysql_num_rows($result) < 1) { $error[] = "Your search term yielded no results."; } else { while ($endresult = mysql_fetch_array($result)) { echo '<br />'; echo 'This is what we found'; echo '<br />'; echo '<a href="newpage.php?w=' . $endresult['row'] . '">' . $endresult['row'] . '</a>'; } } } } } Ok I am not sure if this is possible but I hope someone out there can show me a way. I have a webpage with left content boxes that are looped in depending on the sql info. In one of the boxes the content of the box is going to be another page being pulled in. Now normally I would just put in the include ("page"); but its inside of an echo so you would end the echo do the include and then start the echo back up, however in this case its pulling in the coding from a variable so im a bit lost as to what to do now. The page would have something like... Code: [Select] echo ' '.html_entity_decode(stripslashes($info[content])).' '; and the info content part is Code: [Select] include("pages/paypalbox.php") I've tried making the variable Code: [Select] '; include("pages/paypalbox.php"); echo' Hoping that would fix it but I should of known better, the variable is being pulled in so its not processing it as part of the first step coding and it isn't going to do anything other then print it out like text. So is there a way to make this work? Thanks. So I filled out my edit form and I had it echo the query and it said exactly what it was supposed to but it didn't update it. Here's what the echo query looked like. UPDATE `efed_list_menu_items` SET `content_id`='0', `newscat`='0', `application_id`='1', `itemname`='Testing 3', `itemurl`='testing3.php', `sortorder`='3' WHERE `id` = '3' Hi there im having trouble with my code and was hoping someone may be able to help me? I think the trouble i am having is because i am echoing the form elements (form, hidden) and the value in those elements. This part is fine i think: Code: [Select] $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")){ $insertSQL = sprintf("INSERT INTO ships (ShipName, FleetID, PlayerName, Image1, Image2, Credits, HealthA, HealthB, MaxHealthA, MaxHealthB, Class, Hyperspace, PlanetID, Building, Maintenance) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['shipname1'], "text"), GetSQLValueString($_POST['fleetid1'], "int"), GetSQLValueString($_POST['playername1'], "text"), GetSQLValueString($_POST['image11'], "text"), GetSQLValueString($_POST['image21'], "text"), GetSQLValueString($_POST['credits1'], "int"), GetSQLValueString($_POST['healtha1'], "int"), GetSQLValueString($_POST['healthb1'], "int"), GetSQLValueString($_POST['maxhealtha1'], "int"), GetSQLValueString($_POST['maxhealthb1'], "int"), GetSQLValueString($_POST['class1'], "int"), GetSQLValueString($_POST['hyperspace1'], "int"), GetSQLValueString($_POST['planetid1'], "int"), GetSQLValueString($_POST['building1'], "int"), GetSQLValueString($_POST['maintenance1'], "int")); mysql_select_db($database_swb, $swb); $Result1 = mysql_query($insertSQL, $swb) or die(mysql_error()); $insertGoTo = "planet.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } The problem may lay he Code: [Select] <?php echo'<form id="form1" name="form1" method="post" action="">';echo'<table width="400" border="0" align="top">'; do { echo '<tr> <td width="200" align="center">'; echo '<span class="arial12">'; echo "<img src=".$row_Ships["Image1"]." height =\"250\" width=\"400\">"; echo'| Maintenance: '; echo $row_Ships['Maintenance'];echo ' | '; echo'<input type="submit" name="Submit" value="Build" />'; echo' | Construction Time: '; echo $row_Ships['Building']; echo' | ';echo '</td></tr>'; echo" <input name='fleetid1' type='hidden' id='fleetid1' value='".$totalRows_Fleet." + '1''/>"; echo" <input name='fleetname1' type='hidden' id='fleetname1' value='Fleet ".$totalRows_Fleet." + '1''/>"; echo" <input name='shipname1' type='hidden' id='shipname1' value='".$row_Ships['ShipName']."'/>"; echo" <input name='playername1' type='hidden' id='playername1' value='".$_SESSION['MM_Username']."'/>"; echo" <input name='credits1' type='hidden' id='credits1' value='".$row_Ships['Credits']."'/>"; echo" <input name='image11' type='hidden' id='image11' value='".$row_Ships['Image1']."'/>"; echo" <input name='image21' type='hidden' id='image21' value='".$row_Ships['Image2']."'/>"; echo" <input name='healtha1' type='hidden' id='healtha1' value='".$row_Ships['HealthA']."'/>"; echo" <input name='healthb1' type='hidden' id='healthb1' value='".$row_Ships['HealthB']."'/>"; echo" <input name='maxhealtha1' type='hidden' id='maxhealtha1' value='".$row_Ships['MaxHealthA']."'/>"; echo" <input name='maxhealthb1' type='hidden' id='maxhealthb1' value='".$row_Ships['MaxHealthB']."'/>"; echo" <input name='class1' type='hidden' id='class1' value='".$row_Ships['Class']."'/>"; echo" <input name='hyperspace1' type='hidden' id='hyperspace1' value='".$row_Ships['Hyperspace']."'/>"; echo" <input name='maintenance1' type='hidden' id='maintenance1' value='".$row_Ships['Maintenance']."'/>"; echo" <input name='Planetid1' type='hidden' id='planetid1' value='".$row_Credits['PlanetID']."'/>"; echo" <input name='building1' type='hidden' id='building1' value='".$row_Ships['Building']."'/>"; } while ($row_Ships = mysql_fetch_assoc($Ships)); echo '</table></form>';?> No records are insterted at all?? The page redirection after insert is not happening either. If anybody coould help that would be brilliant... Thank You when I send a post variable to another page for processing using cURL and then I echo the variable I am getting extra slashes and periods this is where I set the fields to send. Code: [Select] curl_setopt($ch, CURLOPT_POSTFIELDS,"name='. $name .'&email='. $email .'&serial='. $serialnumber .'"); this is what happens when I echo $serial on the processing page. Code: [Select] \'. SLNM7IV6ZM98YJRXO8D5 .\' it should look like Code: [Select] SLNM7IV6ZM98YJRXO8D5 this is not working Code: [Select] <?php session_start(); $username = $_SESSION['username']; echo mysql_query("UPDATE members SET online='0' WHERE username='$username' AND online='1'"); session_destroy(); echo "You've been logged out. <a href='index.php'>Click here</a> to return."; ?> what im trying to do is change the online mysql data from 1 back to 0 as i want to show when a user is on and off line can anyone help Code: [Select] <?php session_start(); $_SESSION['is_logged_out'] = 1; if($_SESSION['is_logged_out'] ==1) { echo("<SCRIPT LANGUAGE='JavaScript'>window.alert('You had been successfully signed out')</SCRIPT>"); session_unset(); session_destroy(); header("Location:chatframe.php"); } ?> I got this error Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\login\logout.php:6) in C:\xampp\htdocs\login\logout.php on line 9 which mistake im put? Hi, How logout is executed after 15 min. if does not hit or refresh any page. When writing a logout script in PHP what steps should i take? Should i: 1.) unset all session vars like: unset($_SESSION["var1"]); unset($_SESSION["var2"]); or calls session_unset(); 2.) destroy session cookie like: setcookie(session_name(), "NULL", time()-60, $params['path'], $params['domain'], $params['secure'], isset($params['httponly'])); 3.) finally destroy the session data by calling session_destroy(); or maybe just only unset the session vars - that is making only the first step? I'm asking because I've seen many logout scripts that doesn't involve these 3 steps (i most cases doing only the first one as i stated) Thx. for help. Hi, im new here Need some help. I have a database which contains users, and for every user i have logged_in value which is 1 if user is logged in and 0 if not. I use this so that user can be logged in only once. When user clicks on logout link i set logged_in on 0. My problem is when browser closes logged_in for current user is not set to 0, and after that user can't login because my site thinks he is already logged in. is there some way I can call some function when browser exits or any other solution? please help Hey guys, me again. A few of you were helping me with my login script, which I did finally get working. I am having one small problem though. Upon clicking the logout link, it does not re-direct back to the login page, it just stays blank. I have pasted my code from my logout.php file for reference. Thanks in advance for your help! Logout.php code <?php session_start(); session_destroy(); { header("location: login.php"); } exit(); ?> how to logout using session in proper way ? can you give me the code Hey! I have a table...with a column isOnline which is set to 1 when logging in (using login.php)...and 0 when logging out (logout.php), its how I determine whos logged in and whos not (in statistics etc.) Now the problem is if they dont have the remember me enabled..and don't log themselfs out via logout.php (which sets the isOnline to 0)...and close their browser the $_SESSIONS's get destroyed (which means their physically not logged in)...and their isOnline remains at 1 (even though their logged out) Another problem..is if they login with remember me enabled (as they want to remain logged in)....and close their browser or whatever, isOnline will still remain as 1 (theirfore others will think their online). For your info: In login.php I do an UPDATE query adding the current time generated by time() into the loginTime column...and also setting isOnline to 1. So my question is how can I overcome this, I have the isOnline (1 = logged in, 0 not logged in) and loginTime (which contains the login timestamp)? Cheers |