There is the function: $url = getenv("HTTP_REFERER");
The question is for knowers of php (I'm not the knower of php. That is why, please, tell detailed answer if possible):
User came from 1.htm to 2.htm. Then there is submit form on 2.htm which calls 3.php for action.
IS it possible to pass the url address of 1.htm to 3.php ($url in 3.php)?
If you have some time you can help very much.
Need help
Moderator: General Moderators
- Buddha443556
- Forum Regular
- Posts: 873
- Joined: Fri Mar 19, 2004 1:51 pm
Something like this would go one all page you would want to pass. Those that aren't forms.
I'm guessing here that you have REQUEST_URI variable available if not you'll need to put this somewhere it will always execute ...
Also remember visitor that don't have a session (or whatever) need a default "last_page" ... so to speak.
Hope this helps.
Code: Select all
// set last page session variable
$_SESSION['last_page'] = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];Code: Select all
if (!isset($_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME']
. ( $_SERVER['QUERY_STRING'] ? '?' : '' )
. $_SERVER['QUERY_STRING'];
}Code: Select all
if( isset( $_SESSION['last_page'] ) === false
|| empty( $_SESSION['last_page'] ) === true ) {
$last_page = "http://www.domain.com/index.php";
} else {
$last_page = $_SESSION['last_page'];
}
// do something interesting with $last_page hereThank you Buddha
May be you can check everything? If "yes", see below:
(I'm extremely sorry if there are some bugs. I'm just a beginer)
If you have the idea what should I put in 1.htm (and other same pages), 2.htm and 3.php, please, write me here.
markl - added code/php tags
(I'm extremely sorry if there are some bugs. I'm just a beginer)
Code: Select all
-------------------- 1. htm content ----------------------------------
<html><head>...</head>
<body>
<form target="_blank" action="2.htm" method="post">
<input type="submit" value="Tell your friends about this page"></form></body>
//(so, I need this page url (http://1.htm) to pass it into the letter to friends which 3.php will generate and send)
-----------------------1.htm content END------------------------------
-----------------------2.htm content ------------------------------
<form method="post" name="tellfriends" action="3.php">
Your name *<input type="text" name="sendername">
Your email address * <input type="text" name="senderemail">
Your friend(s) names
1: <input type="text" name="name">
2: <input type="text" name="name2">
3: <input type="text" name="name3">
Your friend(s) email address(es)
<input type="text" name="email">
<input type="text" name="email2">
<input type="text" name="email3">
<input type="submit" value="Send">
</form>
// so this form is one for the whole site. the users will come to it from many pages. that is why I need that the url address of the http://1.htm (and other possible pages from which the users will come) would be pass as well as the data of this form on 2.htm to 3.php for action
-----------------------2.htm content END------------------------------Code: Select all
-----------------------3.php content ------------------------------
<?PHP
$ip = getenv("REMOTE_ADDR");
//set variables
// Your site name for use in the email
$site_name="www.russianpaintings.net";
// Your message for the email
$text=" Dear $name, \n \n I want to recommend you this page $(1.htm_url_datahere)";
// Your message for the email2
$text2=" Dear $name2, \n \n I want to recommend you this page $(1.htm_url_datahere)";
// Your message for the email3
$text3=" Dear $name3, \n \n I want to recommend you this page $(1.htm_url_datahere)";
// Title of email
$title="A message from your friend $sendername";
// Thank you page for users
$thankspage="submitted.htm";
//Admin email
$admemail="root108@mail.ru";
//Admin title
$admtitle="Send to friends data";
// Admin message for the email
$admtext="The following e-mails and names were used on Tell to friend page redirected from \n \n $(1.htm_url_datahere) \n \n $sendername $senderemail ip: $ip \n $name $email \n $name2 $email2 \n $name3 $email3";
// START CODE, DO NOT CHANGE ANYTHING BELOW THIS LINE
// check email addresses
$x1 = ereg("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$",$senderemail);
if($x1==0)
# if no valid email address entered, display no email message
{
echo "<div align=center>You <b>must</b> specify a valid email address for yourself.
<a href=javascript:history.back(-1)>Return to the form</a>.</div>";
exit;
}
if ($email<>"") {
$x2 = ereg("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$",$email);
if($x2==0)
# if no valid email address entered, display no email message
{
echo "<div align=center>!!ERROR!!<br>The first email address you entered is invalid.
<a href=javascript:history.back(-1)>Return to the
form</a>.</div>";
}
}
if ($email2<>"")
{
$x3 = ereg("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$",$email2);
if($x3==0)
# if no valid email address entered, display no email message
{
echo "<div align=center>!!ERROR!!The second email address you entered is invalid.
<a href=javascript:history.back(-1)>Return to the
form</a>.</div>";
}
}
if ($email3<>"")
{
$x4 = ereg("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$",$email3);
if($x4==0)
# if no valid email address entered, display no email message
{
echo "<div align=center>!!ERROR!!The third email address you entered
is invalid. <a href=javascript:history.back(-1)>Return to the form</a>.</div>";
}
}
if (($x2!=0) || ($x3!=0) || ($x4!=0))
{
mail("$email", "$title", "$text", "From: "$sendername" $senderemail\n");
mail("$email2", "$title", "$text2", "From: "$sendername" $senderemail\n");
mail("$email3", "$title", "$text3", "From: "$sendername" $senderemail\n");
mail("$admemail", "$admtitle", "$admtext", "From: "$admemail\n");
// return thank you page
header("Location: $thankspage");
}
?>
-----------------------3.php content END------------------------------markl - added code/php tags