Redirect Back to last page viewed.

Hi, I have a comment form script, though it is written to go back to refresh the last page visited. But instead it just refreshes the page every 2 seconds. This is the code that I have at the moment:

[code]<?php
//Please set the following variables for your mysql database:
$db_hostname = “localhost”; //usually “localhost be default”
$db_username = “”; //your user name
$db_pass = “”; //the password for your user
$db_name = “”; //the name of the database

/MYSQL DATABASE CONNECTION/ TRACKING FUNCTIONS
--------------------------------------
/
// connect to database
$dbh = mysql_connect ($db_hostname, $db_username, $db_pass) or die ('I cannot connect to the database because: ’ . mysql_error());
mysql_select_db ($db_name);

$tuturl = $_POST[“tuturl”];
$tutid2 = $_POST[“tutid2”];
$name = $_POST[“name”];
$url = $_POST[“url”];
$email = $_POST[“email”];
$message = $_POST[“message”];

$sendcomment = mysql_query(“INSERT INTO comments SET tutorialid=’$tutid2’, name=’$name’, url=’$url’, email=’$email’, comment=’$message’, date=now()”);
if($sendcomment){
//header(“Location: $tuturl”);
echo “

Submission Successful

”;
echo “Your comment has been submitted. You will now be redirected back to the last page you visited. Thanks!”;
echo “”;
} else {
echo "There was an error with the submission. ";
}

?>[/code]

But the bit that I want to change is:echo "<meta http-equiv='refresh' content='2;URL=$tuturl'>";

because it is just refreshing the same page every 2 seconds. If you could help it would be great!

Thanks,

Ricky

What does the form HTML look like?

You can view the page at: http://augmentia.110mb.com/new_site/sunburst.php

and the output from the code is:

[code]

Current Comments


0 comments so far
			<th scope="row"><p class="req">Name:</p></th>
			<td><input class="form" tabindex="1" id="name" name="name" /></td>

	</tr>
	<tr>
			<th scope="row"><p class="opt">Email:</p></th>
			<td><input class="form" tabindex="2" id="email" name="email" /></td>
	</tr>
	<tr>

			<th scope="row"><p class="opt">URL:</p></th>

			<td><input class="form" tabindex="3" id="url" name="url" /></td>
	</tr>
	<tr valign="top">
			<th scope="row"><p class="req">Comments:</p><br /></th>
			<td><textarea class="formtext" tabindex="4" id="message" name="message" rows="10" cols="50"></textarea></td>
	</tr>

	<tr>	
			<td>&nbsp;</td>

			<td><input type="submit" name="post" class="submit" value="Submit Comment" /><br />
			<p>Emails are not visible to the public and are not required. </p>

Sorry, No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Leave your comment:

[/code]

Well, I see the problem already: what’s the value of $tuturl?

I have no idea… I didn’t write it, that is why it is in the beginner section. I just need to know how to redirect to the last viewed page

Did you contact the author of the script? Them should be the first point of contact for you, as we do not provide support on third-party scripts.

It is not a paid script. I found it on zimmertech.com He has not come up with a solution, so I was going to try here

Paid or not paid, it’s still third-party :wink:

What you need to do is give the tuturl variable a value in the HTML form. The value attribute of the input tag is empty and it shouldn’t be. It should contain the URL of the page the form is displayed on.

If the author of the script cannot think of this, they shouldn’t be publishing their scripts.

I get that, and I know that I need to make that produce the url of the page. But is there any way possible to do this dynamically, so that I dont have to edit the php file for every page I put it on?

I think $PHP_SELF is still operational, or perhaps you could use some of the $_SERVER indexes. Do some googling on these, I’m pretty sure you’ll come up with something fruitful :slight_smile:

Do You mean search for that server command thing? $_SERVER

Yep, or PHP_SELF. Either of those should give you a way to insert the script’s filename.

Actually I did it using:

"<meta http-equiv='refresh' content='4;URL=javascript:history.back();'>";

It isn’t perfect because it still needs to be refreshed, but until I come up with a better solution, that will do

Sponsor our Newsletter | Privacy Policy | Terms of Service