PHP - Moved: Back Button Script
This topic has been moved to JavaScript Help.
http://www.phpfreaks.com/forums/index.php?topic=350924.0 Similar Tutorials
I Need To Show Data After Pressing Browser's Back Button [accidentally Pressed Enter Instead Of Tab]
This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=321154.0 Please, take a look to the following code.After clicking Next it goes to overview.php.Why when I click back on my browser to return to this page again, it is not returning back? When I click back I receive "Confirm Form Resubmission" message. After refreshing page it loads page. I guess problem is in "session_start();" part. Something to do with cookies. Please, help me it is very urgent for me. <?php session_start(); echo "<html> <head> <title>Hello World</title> <meta http-equiv='Content-Type' content='text/html; charset=Windows-1252'/> </head>"; require_once ('functions.inc'); if(!isset($_POST['userid'])) { echo "<script type='text/javascript'>"; echo "window.location = 'index.php'"; echo "</script>"; exit; }else{ session_register("userid", "userpassword"); $username = auth_user($_POST['userid'], $_POST['userpassword']); if(!$username) { $PHP_SELF = $_SERVER['PHP_SELF']; session_unregister("userid"); session_unregister("userpassword"); echo "Authentication failed " . "Please, write correct username or password. " . "try again "; echo "<A HREF=\"index.php\">Login</A><BR>"; exit; } } function auth_user($userid, $userpassword){ global $default_dbname, $user_tablename; $user_tablename = 'user'; $link_id = db_connect($default_dbname); mysql_select_db("d12826", $link_id); $query = "SELECT username FROM $user_tablename WHERE username = '$userid' AND password = '$userpassword'"; $result = mysql_query($query) or die(mysql_error()); if(!mysql_num_rows($result)){ return 0; }else{ $query_data = mysql_fetch_row($result); return $query_data[0]; } } echo "hello"; echo "<form method='POST' name='myform' action='overview.php'>"; echo "<input type='submit' value='Next'>"; echo "</form>"; ?> I have tried to create a back button, but I have not reached the correct solution. I log into first page (index.php) and then you will get two new buttons that brings me to two different pages. Then I want to come back to the login page, the session is gone and I have to log in again. I want to remain logged in when I get to the index page and be able to see the two buttons. I tried different things such as: Code: [Select] <input type="button" value="Return to previous page" onClick="javascript:history.go(-1)" /> Code: [Select] <?php $referer = $_SERVER['HTTP_REFERER']; if (!$referer == '') { echo '<p><a href="' . $referer . '" title="Return to the previous page">« Go back</a></p>'; } else { echo '<p><a href="javascript:history.go(-1)" title="Return to the previous page">« Go back</a></p>'; } ?> But that's not what I'm thinking about. How can I solve this? index.php <?php session_start(); if(isset($_POST['LoutBtn'])) { session_destroy(); } if(isset($_POST['LoginBtn'])) { //convert a string to all lower case letters. //if user gives username with big letters still can login. $user = strtolower($_POST['username']); $pass = $_POST['password']; if($user == 'admin' && $pass == '123') { $_SESSION['LogedIn'] = true; { print('Welcome admin'); ?> <table width="50" align="right" cellpadding="2" cellspacing="2"> <form method="POST" action="panel.php"> <tr> <td><input type="submit" value="add post" name="PnlBtn" /></td> </tr> </form> <form method="POST" action="stat.php"> <tr> <td><input type="submit" name="showstat" value="visitorlog" /></td> </tr> </form> </table> <?php } } elseif (empty($user) || empty($pass)) { print('<font color="#FF0000">Please fill in username and password!<br/></font>'); } elseif ($_POST['username'] != 'admin'){ print('<font color="#FF0000">wrong username<br/></font>'); } elseif ($_POST['password'] != '123'){ print('<font color="#FF0000">wrong password<br/></font>'); //elseif { // print('<font color="#FF0000">The User Name And/Or Password is incorrect! // Please try again...<br/></font>'); //print('<a href="index.php">Back</a>'); } } ?> <?PHP /* define the blog content file name */ $filename = "myBlogContent.txt"; ?> <!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=utf-8" /> <title>Untitled Document</title> </head> <body> <form method="post" action="index.php" > <table width="300" border="1" align="right" cellpadding="2" cellspacing="2"> <tr> <td width="150">UserName:</td> <td> <input type="text" name="username" size="20" /> </td> </tr> <tr> <td width="150">Password</td> <td><input type="password" name="password" size="20" /></td> </tr> <tr> <td><input type="submit" value="Login" name="LoginBtn" /> </td> </tr> <tr> <td><input type="submit" value="Logout" name="LoutBtn" /></td> </tr> </table> </form> <!-- CONTENT DIV --> <div style="position:absolute; left: 100px; top: 100px; width: 400px;"> <?PHP /* check to see if the file exists */ if (!file_exists($filename)) { echo "The Blog Is Empty"; }else{ /* get the file lines into an array */ $BlogArray = file($filename); /* count the number of blog entries */ $count = count($BlogArray); $i=0; while($i<$count) { $new_array = explode("|", $BlogArray[$i]); echo "Posted by: " . $new_array[1] . "<br>"; echo "Posted on: " . date("m/d/y", time($new_array[0])) . "<br>"; echo "Title: " . $new_array[2] . "<br>"; echo $new_array[3] . "<hr>"; $i ++; } } ?> </div> </body> </html> panel.php <?php session_start(); if ($_SESSION['LogedIn'] == false) { $redirect = "Location: " . $_REQUEST['LoginBtn'] . "index.php"; echo header($redirect); } elseif ($_SESSION['LogedIn'] == true) { echo "welcome"; } //if(isset($_POST['LoutBtn'])){ //{ // session_destroy(); // header ('Location: index.php'); //if ($_SESSION['LogedIn'] == true) //{ // print('<h1>Welcome admin</h1>'); // } //else //{ // session_destroy(); // header ('Location: index.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=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="content.php" method="post"> <table> <tr><td>Blog entry posted by (Your name): </td><td><input type="text" name="who" size="20" maxlength="20" value=""></td></tr> <tr><td>Title of this blog entry: </td><td><input type="text" name="title" size="40" maxlength="80" value=""></td></tr> <tr><td>Content: </td><td><textarea name="content" rows="5" cols="40"></textarea></td></tr> <tr><td clospan="2"><input type="submit" value="Submit"></td></tr> <tr><td clospan="2"><input type="submit" name="showstat" value="visitorlog" /></td></tr> <tr><td clospan="2"><input type="submit" value="Back" name="back" /></td></tr> </table> </form> </body> </html> I have found a point in my site where the user may wish to go back a page. Using the back button in the browser works perfectly fine. However, for aesthetical reasons and for "obvious function" reasons i need to create a button on the page which goes back a step in the browsers history. I know I can do this with Javascript, but I would rather get it done with php first. Therefore is it possible to create a back button in PHP. The back button in question will go back one step in the browsers history to the same .php it is currently on but in a previous state. I found this from google, http://www.webmasterworld.com/forum88/870.htm, but then found there was some js in the answers. I cannot find any other posts similar to this in php freaks I am getting strange behavior after a user submits a comment. After they comment on an article, I display a success message with two buttons: "Return to Article" and "Go to Home Page" Each button seems to work, and I was even able to "Return to Article" and then hit my browser's Back button to return the original "You Comment was Added" message, but if I hit the Back button after hitting "Go to Home Page" I got this error... Quote Notice: Undefined index: pageTitle in /Users/user1/Documents/DEV/++htdocs/01_MyProject/add_comment.php on line 39 Call Stack On Line 39 I have this code... Code: [Select] // Set Page Title. $pageTitle = $_SESSION['pageTitle']; It seems to me that if a user hits the Back button in general it will often cause problems, so is there a way to handle this?? I'm not exactly certain is causing the error above in the first place since my SESSION should be intact.... Debbie So, I just don't know where to post this question. I've written a quiz program where 50 English vocab words are pulled from a dB and displayed on one page with the order scrambled. My students then type the Spanish translation for each. When they submit the form the next page grades their work. They have to get a 90 or better for the grade to be automatically recorded, so I want them to click the back button and go back and make corrections. The problem is when they use a Chrome browser and click the back button the program re-sorts the order of questions. It leaves the order of their answers the same. So what they answered for number 1 is still in the field for number 1, but the questions (the English vocab word) is different. Chrome does this consistently so I thought this was a Chrome issue only. Then one of my students said the same thing happened to her when using Safari. So here is my question, how can I stop Chrome (or any other browser) from re-running my server-side PHP scripts (re-sorting the vocab array) when clicking the back button?
Here is the code for students taking the quiz:
<form method="post" action="portal.php?load=vquiz_grade" style="margin-left: 50px; line-height: 30px;">
$max = $count-1;
?>
//print "<br>";
<input type="hidden" name="max" value="<?print $max?>"> And here is the code showing them what they missed.
<?
// Total grade
print "You missed ".$wcount." words.<br>";
print "<table>";
// Grade response and set color
if ($wrong == 1){ if ($grade >= 90){
$query = "SELECT * FROM inno_vocab_assignments WHERE key_code = '$key_code' AND uname = '$secure_uname' AND teacher = '$teacher'";
// Prevent student from changing vocab list so as to do an easier list
// Insert grade
}
Thank you!
Hey, I made a register page and its all working great. I want to have a "Back" button when the user submits the form if password1 & password2 do not match or username allready exists. But trying to put one in after the echo command isn't working for me. Can anyone help? Heres the error I recieve: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/jamiew90/public_html/Staff/register.php on line 49 Heres line 49 & the surrounding lines incase needed, line 49 is the one beginning with echo: //none were left blank! We continue... if($password != $cpassword) { // the passwords are not the same! echo "<br><br><b>Passwords do not match</b> <p> <FORM><INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;;"> </FORM>";"; }else{ // the passwords are the same! we continue... Is it possible to even add a back button after echo? Thanks for the help - Jamie I have made a website with a custom scroll bar and a back to top button. For some reason the back to top button doesn't show up. Code is below:
<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Adding a dynamic "Back To Top" floating button with smooth scroll</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="css/bootstrap.min.css" rel="stylesheet" media="screen"> <style> /* For the "inset" look only */ html { overflow: auto; } body { position: absolute; top: 8px; left: 8px; bottom: 8px; right: 1px; padding: 10px; overflow-y: scroll; overflow-x: hidden; } /* Width of bar */ ::-webkit-scrollbar { width: 8px; } /* Track */ ::-webkit-scrollbar-track { -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); -webkit-border-radius: 10px; border-radius: 10px; } /* Handle */ ::-webkit-scrollbar-thumb { -webkit-border-radius: 10px; border-radius: 10px; background: rgba(255,0,0,0.8); -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); } ::-webkit-scrollbar-thumb:window-inactive { background: rgba(255,0,0,0.4); } </style> <style> div#page { max-width: 900px; margin-left: auto; margin-right: auto; padding: 20px; } .back-to-top { position: fixed; bottom: 1em; right: 0.5em; text-decoration: none; color: #000000; background-color: rgba(235, 235, 235, 0.80); font-size: 12px; padding: 0.8em; display: none; } .back-to-top:hover { background-color: rgba(135, 135, 135, 0.50); } </style> </head> <body> <div id="page"> <!-- [banner] --> <header id="banner"> <hgroup> <h1>Adding a dynamic "Back To Top" floating button with smooth scroll</h1> </hgroup> </header> <!-- [content] --> <section id="content"> <h1>The first heading</h1> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut nec felis sed velit auctor luctus id quis arcu. Ut dui augue, euismod nec justo a, pretium consequat nisi. Vivamus dictum nec quam in sollicitudin. Nullam non augue at risus condimentum consequat eu ut sem. Ut quis tortor quam. Nulla ullamcorper in metus egestas sagittis. In rhoncus feugiat sagittis. Cras eu arcu dui. Nulla non urna varius, facilisis sapien quis, tristique urna. </p> <h2>The first sub-heading</h2> <p> Duis tincidunt eleifend felis ac porttitor. Aenean facilisis elit eget orci vulputate scelerisque. Nulla justo sem, fringilla nec gravida vel, sollicitudin vitae libero. Donec vitae consequat lorem. Cras eros nunc, varius id dictum sit amet, posuere quis augue. Vivamus quis ipsum eget lectus porta vestibulum. Sed malesuada id orci eu rhoncus. Proin eleifend lacus non libero facilisis interdum. </p> <h2>The second sub-heading</h2> <p> Nulla luctus lorem et justo posuere, vitae ornare elit accumsan. Donec semper tincidunt lacus ut sagittis. Donec nec adipiscing nunc, quis rutrum tortor. Vivamus aliquam orci nulla, non ornare mauris eleifend et. Aliquam erat volutpat. Phasellus id nunc sapien. Suspendisse luctus pharetra lorem, quis scelerisque eros ultricies in. Vivamus hendrerit fermentum justo eget sagittis. Pellentesque cursus at turpis id cursus. Pellentesque sed rhoncus enim. Nam et ante feugiat, luctus enim in, tincidunt lectus. In feugiat neque quam. Curabitur mi ante, dictum non aliquam placerat, suscipit sed sem. Integer dictum, nulla vitae accumsan dignissim, augue justo laoreet diam, quis semper lectus orci vel mi. </p> <h3>The first sub-sub-heading</h3> <p> Vestibulum mollis elementum libero a blandit. Fusce placerat odio quis euismod elementum. Maecenas rhoncus quam viverra odio fringilla blandit. Curabitur erat mi, malesuada ac tempor eu, tincidunt vitae erat. Nunc consequat faucibus feugiat. Integer ornare dui metus, sed consectetur erat vulputate a. Sed porttitor eu magna in aliquet. Cras quis tempus lacus, ac fermentum lorem. </p> <h1>The second heading</h1> <p> Nullam dignissim nibh ac eros iaculis, quis aliquam nibh lacinia. Donec et ullamcorper nunc. Sed convallis aliquet ullamcorper. Donec non leo enim. Ut orci ante, viverra fringilla lorem nec, pretium volutpat lorem. Phasellus elit arcu, posuere at nibh at, facilisis adipiscing dolor. Duis hendrerit metus at turpis congue ornare. Aliquam orci nisi, malesuada at adipiscing non, pharetra a lectus. Mauris in rhoncus ipsum, et sagittis nulla. Duis laoreet luctus lorem, at malesuada sem bibendum at. Pellentesque ultrices massa eget lacus tempus, id ornare lacus fermentum. Sed id fermentum tellus. Suspendisse tincidunt posuere arcu quis fermentum. </p> <h2>The third sub-heading</h2> <p> Phasellus vitae lacinia sapien. Nam eget congue lorem. Donec viverra tortor eget tellus iaculis interdum. Vivamus sollicitudin egestas auctor. Vivamus sit amet justo sit amet eros sodales egestas. Nulla nec pharetra metus. Integer rutrum, ipsum in dignissim scelerisque, arcu est adipiscing tortor, nec varius eros mauris vel augue. In condimentum lobortis eros, sed facilisis neque imperdiet vel. Nullam ut commodo lectus, a luctus mi. Aliquam varius quis tortor a interdum. Aliquam erat volutpat. Nam pellentesque augue enim, eget posuere mi ultrices sodales. Vivamus vel varius quam. Donec sed ante placerat sapien consequat facilisis. Fusce vestibulum ipsum urna, nec tincidunt lacus hendrerit quis. Donec ornare dignissim risus. </p> <h2>The fourth sub-heading</h2> <p> Ut mauris mauris, porta bibendum dictum id, porttitor eu odio. Nam posuere in dui vitae pellentesque. Praesent commodo eros mattis posuere hendrerit. Suspendisse felis tellus, laoreet vitae erat non, laoreet gravida quam. Phasellus a augue non leo venenatis tempus. Curabitur ornare purus a mollis vulputate. Quisque vulputate euismod enim sed elementum. Duis id urna iaculis felis consequat vulputate. Mauris sollicitudin, leo eu sollicitudin porttitor, purus lacus sodales ipsum, vitae lobortis velit libero at libero. </p> <h1>The third heading</h1> <p> Quisque iaculis magna ac risus posuere ultricies. Sed tincidunt, sem ac pellentesque fringilla, sapien purus sagittis odio, eget aliquam ante lorem ac risus. In euismod dignissim leo ut eleifend. Proin accumsan velit quam. Phasellus sollicitudin nulla ligula, sit amet mollis lectus pellentesque consectetur. Nunc non dictum ante, fringilla lobortis nulla. Nullam ullamcorper volutpat velit, ut laoreet justo pellentesque ornare. Praesent aliquet eros eu magna sodales, ac pharetra erat dignissim. Nulla pulvinar neque at fermentum eleifend. </p> <h2>The fifth sub-heading</h2> <p> Praesent dictum interdum condimentum. Suspendisse in tortor blandit, lobortis libero eu, cursus libero. Donec vulputate ligula sit amet arcu porta imperdiet. Nam sodales, justo eu eleifend placerat, dui eros suscipit mi, quis congue dolor velit vitae nisi. Pellentesque mollis felis est. Etiam vitae justo laoreet, rutrum felis sed, porttitor dui. Sed cursus tincidunt turpis. Maecenas gravida commodo urna eget hendrerit. Ut suscipit mi sit amet turpis euismod, luctus suscipit turpis egestas. </p> <h1>The fourth heading</h1> <p> Mauris malesuada eros ac nisl pretium, at vehicula sem porttitor. Vestibulum porta erat leo, nec posuere enim pellentesque vel. Praesent libero est, laoreet quis scelerisque nec, egestas vel enim. Vivamus quis vulputate sapien. Interdum et malesuada fames ac ante ipsum primis in faucibus. Vivamus consequat ligula lectus, sed fermentum elit auctor vitae. Duis iaculis sagittis est sit amet semper. Morbi rutrum fermentum vulputate. Proin tincidunt elementum sem, a faucibus dui malesuada sit amet. Vivamus vel enim laoreet, iaculis nunc ac, tristique nisl. Nulla consequat arcu et dolor porta, non ullamcorper augue pharetra. Interdum et malesuada fames ac ante ipsum primis in faucibus. Integer sed nibh lectus. Sed pulvinar nunc magna, eget placerat mi pharetra ac. Vestibulum hendrerit, nulla nec vestibulum aliquam, arcu tortor blandit ipsum, eget sollicitudin nulla tellus quis libero. Duis sodales fringilla lacus vel auctor. </p> <h2>The sixth sub-heading</h2> <p> Vivamus erat turpis, condimentum vitae neque sit amet, tincidunt malesuada odio. Mauris mollis ante vitae quam condimentum lobortis. Integer sodales odio sit amet metus tempus, vel dignissim libero sagittis. Suspendisse ornare libero elit, quis sollicitudin leo pellentesque id. Sed pharetra mattis sapien nec condimentum. Mauris convallis arcu eget massa fringilla, nec pellentesque dolor semper. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vestibulum vitae odio a sem iaculis tempor. Fusce placerat viverra lorem mollis fermentum. Sed porta sit amet sapien eu venenatis. </p> <h3>The second sub-sub-heading</h3> <p> Aenean ut ipsum ultrices, sollicitudin massa quis, bibendum magna. Sed id porttitor diam, et vestibulum tortor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus vel magna dolor. Etiam cursus nibh ligula, id vestibulum metus varius feugiat. Etiam vitae dolor ligula. Aliquam eu consectetur lorem. Quisque nulla nulla, facilisis semper laoreet non, eleifend in dolor. </p> <a href="#" class="back-to-top"><span class="glyphicon glyphicon-chevron-up"></span></a> </section> <script> jQuery(document).ready(function() { var offset = 220; var duration = 500; jQuery(window).scroll(function() { if (jQuery(this).scrollTop() > offset) { jQuery('.back-to-top').fadeIn(duration); } else { jQuery('.back-to-top').fadeOut(duration); } }); jQuery('.back-to-top').click(function(event) { event.preventDefault(); jQuery('html, body').animate({scrollTop: 0}, duration); return false; }) }); </script> </div> <!-- [/page] --> <script src="//code.jquery.com/jquery.js"></script> <script src="js/bootstrap.min.js"></script> </body> </html> This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=351259.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=349304.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=354724.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=357042.0 not sure if this will find an answer but I am posting anyway. Any help is appreciated....my coder has left the team and no matter how I invite her to come and do some bug squashing, her new schedules won't fit a re-visit into my little aplication...I am eager to delve into the codes at my very low knowledge of php. I have initiated reading and is still trying to teach myself...but of course not as fast as the app needs the patch...here's the meat: This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=330185.0 I'm working on learning AJAX, all is fine with that script as it's from a book. The issue I'm having is the PHP server side code to get a response from the server. I'm still rather new to all of this so try to explain any response given in a noob friendly manner. So I have the following so far: // Connection Values $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Get the variable sent by AJAX script if (isset($_GET['username'])) { // Secure the information $passname = mysqli_real_escape_string($dbc, trim($_GET['username'])); // Lookup the username in the database $query = "SELECT username FROM information WHERE username = '$passname'"; $data = mysqli_query($dbc, $query); // Allow some time to get the response sleep(2); // If 1 is returned that name exsists, if 0 then we can move forward if (mysqli_num_rows($data) == 0) { // Send okay back to the ajax script so it knows to stop bothering the user echo 'okay'; } else { // Send denied back to the ajax script so the user knows that name is taken echo 'denied'; } } Hi, I have set up 2 php pages page 1 - add_entry2.php In this page I have a invoice table created where I can dynamically add/delete rows. This has a View Bill button which takes me to page 2- add_entry3.php In this page it shows up the rows added in page 1 in read only format, so if the user wants to modify the data that he/she entered then he must Click on <back> that i have provided in the page 2 which will direct him to page 1 Now the problem starts here on click of Back the dynamically added rows dissappear..which is frustrating..I know its something to do with my code..but can anyone help me fix it. One more thing is that i dont want to store the data into DB till the finalise button is clicked on page 2 so that means till page 2 is submitted nothing goes to DB from Page 1. I am able to retain values if I use the code Code: [Select] <form action="add_entry2.php" name="eval_edit" method="post" format="html"> i,e if I submit back to the same page and retrieve values form $_POST but If I use the code Code: [Select] <input type="button" value="Back" onClick="history.go(-1);return true;">to get back to add_entry2.ph it looses all the values. Is there any other way to code the BACK link retaining my $_POST values(Do you think $_SESSION would work in this case?) This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=308101.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=317717.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=353240.0 |