Passing a URL as a variable html to php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bigno34
Forum Newbie
Posts: 5
Joined: Tue May 21, 2002 9:43 pm

Passing a URL as a variable html to php

Post by bigno34 »

Code: Select all

Hello,

I have a web site with a number of ordinary HTML pages containing articles. I recently discovered a PHP script that allows web pages to be emailed to a friend. I like this idea however, the original script worked within a PHP page. Get the script at (I've only kept the email portion):

http://www.phptr.com/essential/php/code/chapter6.zip

Because other sites have links to my pages and I'd rather not have those links going dead (404 Errors) if I changed the extention from .htm to .php. So I don't like the idea of changing my file names to be able to execute php code.

Get to the point...


Ok, ok...

To get this idea to work I have 2 pages, 1st, an ordinary HTML page with a form (NO PHP code !!) and a submit button that sends a hidden variable ($article, that page's URL actually) to a php page.

The php page picks up the $article variable and has a form as well with three text fields, one for friend's email address, one for the submitter's email address and a comments field.

I am able to get the variable (with the URL in it) to pass to the php form page (using a print $article; it returns the right path), however I'm not able to get the php script to open the page. The operation dies and I get a "Can't open file" message. I've tried using get and post form methods with no difference.

If I hardcode the SAME path into the php form (instead of using the passed variable) everything works.

What gives ?? I've asked around a bit already and it seems this can't be done...

See my code below...

bigno34
=====================================================================

HTML page (this is the form with transmits the URL)


<form name="FormName" action="../../modules/env_art.php" method="post">
		<input type="hidden" value="http://www.samizdat.qc.ca/vc/sexe/hs1.htm" name="article">Pour envoyer cet article &agrave; un ami, cliquez <input type="submit" value="ici" name="submitButtonName">.
		</form>



PHP page (this page is supposed to pick up the URL in the variable)
filename = "env_art.php"

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Envoyez l'article11</title>
	</head>

	<body topmargin="10," leftmargin="10" marginheight="10" marginwidth="10" background="../medias_inter/pat1.gif">

		<h2>Envoyez l'article</h2>
		<p>
		<form action="env_art.php" method="POST">
		</p><br><br>
		<table border="0" cellpadding="0" cellspacing="5" width="400">
			<tr>
				<td width="300" align="right">Couriel de 
Hello,

I have a web site with a number of ordinary HTML pages containing articles. I recently discovered a PHP script that allows web pages to be emailed to a friend. I like this idea however, the original script worked within a PHP page. Get the script at (I've only kept the email portion):

http://www.phptr.com/essential/php/code/chapter6.zip

Because other sites have links to my pages and I'd rather not have those links going dead (404 Errors) if I changed the extention from .htm to .php. So I don't like the idea of changing my file names to be able to execute php code.

Get to the point...


Ok, ok...

To get this idea to work I have 2 pages, 1st, an ordinary HTML page with a form (NO PHP code !!) and a submit button that sends a hidden variable ($article, that page's URL actually) to a php page.

The php page picks up the $article variable and has a form as well with three text fields, one for friend's email address, one for the submitter's email address and a comments field.

I am able to get the variable (with the URL in it) to pass to the php form page (using a print $article; it returns the right path), however I'm not able to get the php script to open the page. The operation dies and I get a "Can't open file" message. I've tried using get and post form methods with no difference.

If I hardcode the SAME path into the php form (instead of using the passed variable) everything works.

What gives ?? I've asked around a bit already and it seems this can't be done...

See my code below...

bigno34
=====================================================================

HTML page (this is the form with transmits the URL)


<form name="FormName" action="../../modules/env_art.php" method="post">
		<input type="hidden" value="http://www.samizdat.qc.ca/vc/sexe/hs1.htm" name="article">Pour envoyer cet article &agrave; un ami, cliquez <input type="submit" value="ici" name="submitButtonName">.
		</form>



PHP page (this page is supposed to pick up the URL in the variable)
filename = "env_art.php"

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Envoyez l'article11</title>
	</head>

	<body topmargin="10," leftmargin="10" marginheight="10" marginwidth="10" background="../medias_inter/pat1.gif">

		<h2>Envoyez l'article</h2>
		<p>
		<form action="env_art.php" method="POST">
		</p><br><br>
		<table border="0" cellpadding="0" cellspacing="5" width="400">
			<tr>
				<td width="300" align="right">Couriel de votre destinataire:</td>
				<td width="100"><input type="text" name="to" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right">Votre couriel:</td>
				<td width="100"><input type="text" name="from" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right" valign="top">Un bref commentaire pour votre destinataire:</td>
				<td width="100"><textarea name="comment" cols="40" rows="4"></textarea></td>
			</tr>
		</table>
		<input type="submit" name="submit" value="Envoyez!">
		</form>
		</p>
<?

		//this is just to see if the variable got thru ok
   print "*" . $article . "*";

if(isset($submit)):
//next 3 lines may be useless...
	$article = str_replace("%2F","/",$article);
	$article = str_replace("%3A",":",$article);
	$article = trim( $article );

	($file = fopen( $article, "r" )) or die ("Can't open file");
	$data = fread( $file, 200000 );
	fclose($file);
	//$stripped_data = strip_tags($data);
	$body = "Commentaires d'un[e] ami[e]: " . $comment . "<p>" . $data . "<p>" . "Ce texte est tire du site Samizdat\nhttp://www.samizdat.qc.ca";
	$subject = "Un article pour toi de la part d'un(e) ami(e)";
	mail($to, $subject, $body, "FROM: $from\nX-Mailer: samizdat.qc.ca\nContent-type: text/html");
	print"<h2>The article has been sent !</h2>"
	?>
		<p>
		<?
		endif;
	?>
	&am
Hello,

I have a web site with a number of ordinary HTML pages containing articles. I recently discovered a PHP script that allows web pages to be emailed to a friend. I like this idea however, the original script worked within a PHP page. Get the script at (I've only kept the email portion):

http://www.phptr.com/essential/php/code/chapter6.zip

Because other sites have links to my pages and I'd rather not have those links going dead (404 Errors) if I changed the extention from .htm to .php. So I don't like the idea of changing my file names to be able to execute php code.

Get to the point...


Ok, ok...

To get this idea to work I have 2 pages, 1st, an ordinary HTML page with a form (NO PHP code !!) and a submit button that sends a hidden variable ($article, that page's URL actually) to a php page.

The php page picks up the $article variable and has a form as well with three text fields, one for friend's email address, one for the submitter's email address and a comments field.

I am able to get the variable (with the URL in it) to pass to the php form page (using a print $article; it returns the right path), however I'm not able to get the php script to open the page. The operation dies and I get a "Can't open file" message. I've tried using get and post form methods with no difference.

If I hardcode the SAME path into the php form (instead of using the passed variable) everything works.

What gives ?? I've asked around a bit already and it seems this can't be done...

See my code below...

bigno34
=====================================================================

HTML page (this is the form with transmits the URL)


<form name="FormName" action="../../modules/env_art.php" method="post">
		<input type="hidden" value="http://www.samizdat.qc.ca/vc/sexe/hs1.htm" name="article">Pour envoyer cet article &agrave; un ami, cliquez <input type="submit" value="ici" name="submitButtonName">.
		</form>



PHP page (this page is supposed to pick up the URL in the variable)
filename = "env_art.php"

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Envoyez l'article11</title>
	</head>

	<body topmargin="10," leftmargin="10" marginheight="10" marginwidth="10" background="../medias_inter/pat1.gif">

		<h2>Envoyez l'article</h2>
		<p>
		<form action="env_art.php" method="POST">
		</p><br><br>
		<table border="0" cellpadding="0" cellspacing="5" width="400">
			<tr>
				<td width="300" align="right">Couriel de votre destinataire:</td>
				<td width="100"><input type="text" name="to" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right">Votre couriel:</td>
				<td width="100"><input type="text" name="from" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right" valign="top">Un bref commentaire pour votre destinataire:</td>
				<td width="100"><textarea name="comment" cols="40" rows="4"></textarea></td>
			</tr>
		</table>
		<input type="submit" name="submit" value="Envoyez!">
		</form>
		</p>
<?

		//this is just to see if the variable got thru ok
   print "*" . $article . "*";

if(isset($submit)):
//next 3 lines may be useless...
	$article = str_replace("%2F","/",$article);
	$article = str_replace("%3A",":",$article);
	$article = trim( $article );

	($file = fopen( $article, "r" )) or die ("Can't open file");
	$data = fread( $file, 200000 );
	fclose($file);
	//$stripped_data = strip_tags($data);
	$body = "Commentaires d'un[e] ami[e]: " . $comment . "<p>" . $data . "<p>" . "Ce texte est tire du site Samizdat\nhttp://www.samizdat.qc.ca";
	$subject = "Un article pour toi de la part d'un(e) ami(e)";
	mail($to, $subject, $body, "FROM: $from\nX-Mailer: samizdat.qc.ca\nContent-type: text/html");
	print"<h2>The article has been sent !</h2>"
	?>
		<p>
		<?

Hello,

I have a web site with a number of ordinary HTML pages containing articles. I recently discovered a PHP script that allows web pages to be emailed to a friend. I like this idea however, the original script worked within a PHP page. Get the script at (I've only kept the email portion):

http://www.phptr.com/essential/php/code/chapter6.zip

Because other sites have links to my pages and I'd rather not have those links going dead (404 Errors) if I changed the extention from .htm to .php. So I don't like the idea of changing my file names to be able to execute php code.

Get to the point...


Ok, ok...

To get this idea to work I have 2 pages, 1st, an ordinary HTML page with a form (NO PHP code !!) and a submit button that sends a hidden variable ($article, that page's URL actually) to a php page.

The php page picks up the $article variable and has a form as well with three text fields, one for friend's email address, one for the submitter's email address and a comments field.

I am able to get the variable (with the URL in it) to pass to the php form page (using a print $article; it returns the right path), however I'm not able to get the php script to open the page. The operation dies and I get a "Can't open file" message. I've tried using get and post form methods with no difference.

If I hardcode the SAME path into the php form (instead of using the passed variable) everything works.

What gives ?? I've asked around a bit already and it seems this can't be done...

See my code below...

bigno34
=====================================================================

HTML page (this is the form with transmits the URL)


<form name="FormName" action="../../modules/env_art.php" method="post">
		<input type="hidden" value="http://www.samizdat.qc.ca/vc/sexe/hs1.htm" name="article">Pour envoyer cet article &agrave; un ami, cliquez <input type="submit" value="ici" name="submitButtonName">.
		</form>



PHP page (this page is supposed to pick up the URL in the variable)
filename = "env_art.php"

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Envoyez l'article11</title>
	</head>

	<body topmargin="10," leftmargin="10" marginheight="10" marginwidth="10" background="../medias_inter/pat1.gif">

		<h2>Envoyez l'article</h2>
		<p>
		<form action="env_art.php" method="POST">
		</p><br><br>
		<table border="0" cellpadding="0" cellspacing="5" width="400">
			<tr>
				<td width="300" align="right">Couriel de votre destinataire:</td>
				<td width="100"><input type="text" name="to" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right">Votre couriel:</td>
				<td width="100"><input type="text" name="from" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right" valign="top">Un bref commentaire pour votre destinataire:</td>
				<td width="100"><textarea name="comment" cols="40" rows="4"></textarea></td>
			</tr>
		</table>
		<input type="submit" name="submit" value="Envoyez!">
		</form>
		</p>
<?

		//this is just to see if the variable got thru ok
   print "*" . $article . "*";

if(isset($submit)):
//next 3 lines may be useless...
	$article = str_replace("%2F","/",$article);
	$article = str_replace("%3A",":",$article);
	$article = trim( $article );

	($file = fopen( $article, "r" )) or die ("Can't open file");
	$data = fread( $file, 200000 );
	fclose($file);
	//$stripped_data = strip_tags($data);
	$body = "Commentaires d'un[e] ami[e]: " . $comment . "<p>" . $data . "<p>" . "Ce texte est tire du site Samizdat\nhttp://www.samizdat.qc.ca";
	$subject = "Un article pour toi de la part d'un(e) ami(e)";
	mail($to, $subject, $body, "FROM: $from\nX-Mailer: samizdat.qc.ca\nContent-type: text/html");
	print"<h2>The article has been sent !</h2>"
	?>
		<p>
		<?
		endif;
	?>
	</body>
Hello,

I have a web site with a number of ordinary HTML pages containing articles. I recently discovered a PHP script that allows web pages to be emailed to a friend. I like this idea however, the original script worked within a PHP page. Get the script at (I've only kept the email portion):

http://www.phptr.com/essential/php/code/chapter6.zip

Because other sites have links to my pages and I'd rather not have those links going dead (404 Errors) if I changed the extention from .htm to .php. So I don't like the idea of changing my file names to be able to execute php code.

Get to the point...


Ok, ok...

To get this idea to work I have 2 pages, 1st, an ordinary HTML page with a form (NO PHP code !!) and a submit button that sends a hidden variable ($article, that page's URL actually) to a php page.

The php page picks up the $article variable and has a form as well with three text fields, one for friend's email address, one for the submitter's email address and a comments field.

I am able to get the variable (with the URL in it) to pass to the php form page (using a print $article; it returns the right path), however I'm not able to get the php script to open the page. The operation dies and I get a "Can't open file" message. I've tried using get and post form methods with no difference.

If I hardcode the SAME path into the php form (instead of using the passed variable) everything works.

What gives ?? I've asked around a bit already and it seems this can't be done...

See my code below...

bigno34
=====================================================================

HTML page (this is the form with transmits the URL)


<form name="FormName" action="../../modules/env_art.php" method="post">
		<input type="hidden" value="http://www.samizdat.qc.ca/vc/sexe/hs1.htm" name="article">Pour envoyer cet article &agrave; un ami, cliquez <input type="submit" value="ici" name="submitButtonName">.
		</form>



PHP page (this page is supposed to pick up the URL in the variable)
filename = "env_art.php"

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Envoyez l'article11</title>
	</head>

	<body topmargin="10," leftmargin="10" marginheight="10" marginwidth="10" background="../medias_inter/pat1.gif">

		<h2>Envoyez l'article</h2>
		<p>
		<form action="env_art.php" method="POST">
		</p><br><br>
		<table border="0" cellpadding="0" cellspacing="5" width="400">
			<tr>
				<td width="300" align="right">Couriel de votre destinataire:</td>
				<td width="100"><input type="text" name="to" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right">Votre couriel:</td>
				<td width="100"><input type="text" name="from" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right" valign="top">Un bref commentaire pour votre destinataire:</td>
				<td width="100"><textarea name="comment" cols="40" rows="4"></textarea></td>
			</tr>
		</table>
		<input type="submit" name="submit" value="Envoyez!">
		</form>
		</p>
<?

		//this is just to see if the variable got thru ok
   print "*" . $article . "*";

if(isset($submit)):
//next 3 lines may be useless...
	$article = str_replace("%2F","/",$article);
	$article = str_replace("%3A",":",$article);
	$article = trim( $article );

	($file = fopen( $article, "r" )) or die ("Can't open file");
	$data = fread( $file, 200000 );
	fclose($file);
	//$stripped_data = strip_tags($data);
	$body = "Commentaires d'un[e] ami[e]: " . $comment . "<p>" . $data . "<p>" . "Ce texte est tire du site Samizdat\nhttp://www.samizdat.qc.ca";
	$subject = "Un article pour toi de la part d'un(e) ami(e)";
	mail($to, $subject, $body, "FROM: $from\nX-Mailer: samizdat.qc.ca\nContent-type: text/html");
	print"<h2>The article has been sent !</h2>"
	?>
		<p>
		<?
		endif;
	?>
	</bod
Hello,

I have a web site with a number of ordinary HTML pages containing articles. I recently discovered a PHP script that allows web pages to be emailed to a friend. I like this idea however, the original script worked within a PHP page. Get the script at (I've only kept the email portion):

http://www.phptr.com/essential/php/code/chapter6.zip

Because other sites have links to my pages and I'd rather not have those links going dead (404 Errors) if I changed the extention from .htm to .php. So I don't like the idea of changing my file names to be able to execute php code.

Get to the point...


Ok, ok...

To get this idea to work I have 2 pages, 1st, an ordinary HTML page with a form (NO PHP code !!) and a submit button that sends a hidden variable ($article, that page's URL actually) to a php page.

The php page picks up the $article variable and has a form as well with three text fields, one for friend's email address, one for the submitter's email address and a comments field.

I am able to get the variable (with the URL in it) to pass to the php form page (using a print $article; it returns the right path), however I'm not able to get the php script to open the page. The operation dies and I get a "Can't open file" message. I've tried using get and post form methods with no difference.

If I hardcode the SAME path into the php form (instead of using the passed variable) everything works.

What gives ?? I've asked around a bit already and it seems this can't be done...

See my code below...

bigno34
=====================================================================

HTML page (this is the form with transmits the URL)


<form name="FormName" action="../../modules/env_art.php" method="post">
		<input type="hidden" value="http://www.samizdat.qc.ca/vc/sexe/hs1.htm" name="article">Pour envoyer cet article &agrave; un ami, cliquez <input type="submit" value="ici" name="submitButtonName">.
		</form>



PHP page (this page is supposed to pick up the URL in the variable)
filename = "env_art.php"

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Envoyez l'article11</title>
	</head>

	<body topmargin="10," leftmargin="10" marginheight="10" marginwidth="10" background="../medias_inter/pat1.gif">

		<h2>Envoyez l'article</h2>
		<p>
		<form action="env_art.php" method="POST">
		</p><br><br>
		<table border="0" cellpadding="0" cellspacing="5" width="400">
			<tr>
				<td width="300" align="right">Couriel de votre destinataire:</td>
				<td width="100"><input type="text" name="to" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right">Votre couriel:</td>
				<td width="100"><input type="text" name="from" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right" valign="top">Un bref commentaire pour votre destinataire:</td>
				<td width="100"><textarea name="comment" cols="40" rows="4"></textarea></td>
			</tr>
		</table>
		<input type="submit" name="submit" value="Envoyez!">
		</form>
		</p>
<?

		//this is just to see if the variable got thru ok
   print "*" . $article . "*";

if(isset($submit)):
//next 3 lines may be useless...
	$article = str_replace("%2F","/",$article);
	$article = str_replace("%3A",":",$article);
	$article = trim( $article );

	($file = fopen( $article, "r" )) or die ("Can't open file");
	$data = fread( $file, 200000 );
	fclose($file);
	//$stripped_data = strip_tags($data);
	$body = "Commentaires d'un[e] ami[e]: " . $comment . "<p>" . $data . "<p>" . "Ce texte est tire du site Samizdat\nhttp://www.samizdat.qc.ca";
	$subject = "Un article pour toi de la part d'un(e) ami(e)";
	mail($to, $subject, $body, "FROM: $from\nX-Mailer: samizdat.qc.ca\nContent-type: text/html");
	print"<h2>The article has been sent !</h2>"
	?>
		<p>
		<?
		endif;
	?>
	</body>

</html&ith a number of ordinary HTML pages containing articles. I recently discovered a PHP script that allows web pages to be emailed to a friend. I like this idea however, the original script worked within a PHP page. Get the script at (I've only kept the email portion):

http://www.phptr.com/essential/php/code/chapter6.zip

Because other sites have links to my pages and I'd rather not have those links going dead (404 Errors) if I changed the extention from .htm to .php. So I don't like the idea of changing my file names to be able to execute php code.

Get to the point...


Ok, ok...

To get this idea to work I have 2 pages, 1st, an ordinary HTML page with a form (NO PHP code !!) and a submit button that sends a hidden variable ($article, that page's URL actually) to a php page.

The php page picks up the $article variable and has a form as well with three text fields, one for friend's email address, one for the submitter's email address and a comments field.

I am able to get the variable (with the URL in it) to pass to the php form page (using a print $article; it returns the right path), however I'm not able to get the php script to open the page. The operation dies and I get a "Can't open file" message. I've tried using get and post form methods with no difference.

If I hardcode the SAME path into the php form (instead of using the passed variable) everything works.

What gives ?? I've asked around a bit already and it seems this can't be done...

See my code below...

bigno34
=====================================================================

HTML page (this is the form with transmits the URL)


<form name="FormName" action="../../modules/env_art.php" method="post">
		<input type="hidden" value="http://www.samizdat.qc.ca/vc/sexe/hs1.htm" name="article">Pour envoyer cet article &agrave; un ami, cliquez <input type="submit" value="ici" name="submitButtonName">.
		</form>



PHP page (this page is supposed to pick up the URL in the variable)
filename = "env_art.php"

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Envoyez l'article11</title>
	</head>

	<body topmargin="10," leftmargin="10" marginheight="10" marginwidth="10" background="../medias_inter/pat1.gif">

		<h2>Envoyez l'article</h2>
		<p>
		<form action="env_art.php" method="POST">
		</p><br><br>
		<table border="0" cellpadding="0" cellspacing="5" width="400">
			<tr>
				<td width="300" align="right">Couriel de votre destinataire:</td>
				<td width="100"><input type="text" name="to" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right">Votre couriel:</td>
				<td width="100"><input type="text" name="from" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right" valign="top">Un bref commentaire pour votre destinataire:</td>
				<td width="100"><textarea name="comment" cols="40" rows="4"></textarea></td>
			</tr>
		</table>
		<input type="submit" name="submit" value="Envoyez!">
		</form>
		</p>
<?

		//this is just to see if the variable got thru ok
   print "*" . $article . "*";

if(isset($submit)):
//next 3 lines may be useless...
	$article = str_replace("%2F","/",$article);
	$article = str_replace("%3A",":",$article);
	$article = trim( $article );

	($file = fopen( $article, "r" )) or die ("Can't open file");
	$data = fread( $file, 200000 );
	fclose($file);
	//$stripped_data = strip_tags($data);
	$body = "Commentaires d'un[e] ami[e]: " . $comment . "<p>" . $data . "<p>" . "Ce texte est tire du site Samizdat\nhttp://www.samizdat.qc.ca";
	$subject = "Un article pour toi de la part d'un(e) ami(e)";
	mail($to, $subject, $body, "FROM: $from\nX-Mailer: samizdat.qc.ca\nContent-type: text/html");
	print"<h2>The article has been sent !</h2>"
	?>
		<p>
		&amprecently discovered a PHP script that allows web pages to be emailed to a friend. I like this idea however, the original script worked within a PHP page. Get the script at (I've only kept the email portion):

http://www.phptr.com/essential/php/code/chapter6.zip

Because other sites have links to my pages and I'd rather not have those links going dead (404 Errors) if I changed the extention from .htm to .php. So I don't like the idea of changing my file names to be able to execute php code.

Get to the point...


Ok, ok...

To get this idea to work I have 2 pages, 1st, an ordinary HTML page with a form (NO PHP code !!) and a submit button that sends a hidden variable ($article, that page's URL actually) to a php page.

The php page picks up the $article variable and has a form as well with three text fields, one for friend's email address, one for the submitter's email address and a comments field.

I am able to get the variable (with the URL in it) to pass to the php form page (using a print $article; it returns the right path), however I'm not able to get the php script to open the page. The operation dies and I get a "Can't open file" message. I've tried using get and post form methods with no difference.

If I hardcode the SAME path into the php form (instead of using the passed variable) everything works.

What gives ?? I've asked around a bit already and it seems this can't be done...

See my code below...

bigno34
=====================================================================

HTML page (this is the form with transmits the URL)


<form name="FormName" action="../../modules/env_art.php" method="post">
		<input type="hidden" value="http://www.samizdat.qc.ca/vc/sexe/hs1.htm" name="article">Pour envoyer cet article &agrave; un ami, cliquez <input type="submit" value="ici" name="submitButtonName">.
		</form>



PHP page (this page is supposed to pick up the URL in the variable)
filename = "env_art.php"

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Envoyez l'article11</title>
	</head>

	<body topmargin="10," leftmargin="10" marginheight="10" marginwidth="10" background="../medias_inter/pat1.gif">

		<h2>Envoyez l'article</h2>
		<p>
		<form action="env_art.php" method="POST">
		</p><br><br>
		<table border="0" cellpadding="0" cellspacing="5" width="400">
			<tr>
				<td width="300" align="right">Couriel de votre destinataire:</td>
				<td width="100"><input type="text" name="to" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right">Votre couriel:</td>
				<td width="100"><input type="text" name="from" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right" valign="top">Un bref commentaire pour votre destinataire:</td>
				<td width="100"><textarea name="comment" cols="40" rows="4"></textarea></td>
			</tr>
		</table>
		<input type="submit" name="submit" value="Envoyez!">
		</form>
		</p>
<?

		//this is just to see if the variable got thru ok
   print "*" . $article . "*";

if(isset($submit)):
//next 3 lines may be useless...
	$article = str_replace("%2F","/",$article);
	$article = str_replace("%3A",":",$article);
	$article = trim( $article );

	($file = fopen( $article, "r" )) or die ("Can't open file");
	$data = fread( $file, 200000 );
	fclose($file);
	//$stripped_data = strip_tags($data);
	$body = "Commentaires d'un[e] ami[e]: " . $comment . "<p>" . $data . "<p>" . "Ce texte est tire du site Samizdat\nhttp://www.samizdat.qc.ca";
	$subject = "Un article pour toi de la part d'un(e) ami(e)";
	mail($to, $subject, $body, "FROM: $from\nX-Mailer: samizdat.qc.ca\nContent-type: text/html");
	print"<h2>The article has been sent !</h2>"
	?>
		&a
Hello,

I have a web site with a number of ordinary HTML pages containing articles. I recently discovered a PHP script that allows web pages to be emailed to a friend. I like this idea however, the original script worked within a PHP page. Get the script at (I've only kept the email portion):

http://www.phptr.com/essential/php/code/chapter6.zip

Because other sites have links to my pages and I'd rather not have those links going dead (404 Errors) if I changed the extention from .htm to .php. So I don't like the idea of changing my file names to be able to execute php code.

Get to the point...


Ok, ok...

To get this idea to work I have 2 pages, 1st, an ordinary HTML page with a form (NO PHP code !!) and a submit button that sends a hidden variable ($article, that page's URL actually) to a php page.

The php page picks up the $article variable and has a form as well with three text fields, one for friend's email address, one for the submitter's email address and a comments field.

I am able to get the variable (with the URL in it) to pass to the php form page (using a print $article; it returns the right path), however I'm not able to get the php script to open the page. The operation dies and I get a "Can't open file" message. I've tried using get and post form methods with no difference.

If I hardcode the SAME path into the php form (instead of using the passed variable) everything works.

What gives ?? I've asked around a bit already and it seems this can't be done...

See my code below...

bigno34
=====================================================================

HTML page (this is the form with transmits the URL)


<form name="FormName" action="../../modules/env_art.php" method="post">
		<input type="hidden" value="http://www.samizdat.qc.ca/vc/sexe/hs1.htm" name="article">Pour envoyer cet article &agrave; un ami, cliquez <input type="submit" value="ici" name="submitButtonName">.
		</form>



PHP page (this page is supposed to pick up the URL in the variable)
filename = "env_art.php"

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Envoyez l'article11</title>
	</head>

	<body topmargin="10," leftmargin="10" marginheight="10" marginwidth="10" background="../medias_inter/pat1.gif">

		<h2>Envoyez l'article</h2>
		<p>
		<form action="env_art.php" method="POST">
		</p><br><br>
		<table border="0" cellpadding="0" cellspacing="5" width="400">
			<tr>
				<td width="300" align="right">Couriel de votre destinataire:</td>
				<td width="100"><input type="text" name="to" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right">Votre couriel:</td>
				<td width="100"><input type="text" name="from" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right" valign="top">Un bref commentaire pour votre destinataire:</td>
				<td width="100"><textarea name="comment" cols="40" rows="4"></textarea></td>
			</tr>
		</table>
		<input type="submit" name="submit" value="Envoyez!">
		</form>
		</p>
<?

		//this is just to see if the variable got thru ok
   print "*" . $article . "*";

if(isset($submit)):
//next 3 lines may be useless...
	$article = str_replace("%2F","/",$article);
	$article = str_replace("%3A",":",$article);
	$article = trim( $article );

	($file = fopen( $article, "r" )) or die ("Can't open file");
	$data = fread( $file, 200000 );
	fclose($file);
	//$stripped_data = strip_tags($data);
	$body = "Commentaires d'un[e] ami[e]: " . $comment . "<p>" . $data . "<p>" . "Ce texte est tire du site Samizdat\nhttp://www.samizdat.qc.ca";
	$subject = "Un article pour toi de la part d'un(e) ami(e)";
	mail($to, $subject, $body, "FROM: $from\nX-Mailer: samizdat.qc.ca\nContent-type: text/html");
	print"<h2>The article has been sent !</h2>"
	?>
		<p>
		<?
		endif;
	?>
	</body>

&a
Hello,

I have a web site with a number of ordinary HTML pages containing articles. I recently discovered a PHP script that allows web pages to be emailed to a friend. I like this idea however, the original script worked within a PHP page. Get the script at (I've only kept the email portion):

http://www.phptr.com/essential/php/code/chapter6.zip

Because other sites have links to my pages and I'd rather not have those links going dead (404 Errors) if I changed the extention from .htm to .php. So I don't like the idea of changing my file names to be able to execute php code.

Get to the point...


Ok, ok...

To get this idea to work I have 2 pages, 1st, an ordinary HTML page with a form (NO PHP code !!) and a submit button that sends a hidden variable ($article, that page's URL actually) to a php page.

The php page picks up the $article variable and has a form as well with three text fields, one for friend's email address, one for the submitter's email address and a comments field.

I am able to get the variable (with the URL in it) to pass to the php form page (using a print $article; it returns the right path), however I'm not able to get the php script to open the page. The operation dies and I get a "Can't open file" message. I've tried using get and post form methods with no difference.

If I hardcode the SAME path into the php form (instead of using the passed variable) everything works.

What gives ?? I've asked around a bit already and it seems this can't be done...

See my code below...

bigno34
=====================================================================

HTML page (this is the form with transmits the URL)


<form name="FormName" action="../../modules/env_art.php" method="post">
		<input type="hidden" value="http://www.samizdat.qc.ca/vc/sexe/hs1.htm" name="article">Pour envoyer cet article &agrave; un ami, cliquez <input type="submit" value="ici" name="submitButtonName">.
		</form>



PHP page (this page is supposed to pick up the URL in the variable)
filename = "env_art.php"

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Envoyez l'article11</title>
	</head>

	<body topmargin="10," leftmargin="10" marginheight="10" marginwidth="10" background="../medias_inter/pat1.gif">

		<h2>Envoyez l'article</h2>
		<p>
		<form action="env_art.php" method="POST">
		</p><br><br>
		<table border="0" cellpadding="0" cellspacing="5" width="400">
			<tr>
				<td width="300" align="right">Couriel de votre destinataire:</td>
				<td width="100"><input type="text" name="to" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right">Votre couriel:</td>
				<td width="100"><input type="text" name="from" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right" valign="top">Un bref commentaire pour votre destinataire:</td>
				<td width="100"><textarea name="comment" cols="40" rows="4"></textarea></td>
			</tr>
		</table>
		<input type="submit" name="submit" value="Envoyez!">
		</form>
		</p>
<?

		//this is just to see if the variable got thru ok
   print "*" . $article . "*";

if(isset($submit)):
//next 3 lines may be useless...
	$article = str_replace("%2F","/",$article);
	$article = str_replace("%3A",":",$article);
	$article = trim( $article );

	($file = fopen( $article, "r" )) or die ("Can't open file");
	$data = fread( $file, 200000 );
	fclose($file);
	//$stripped_data = strip_tags($data);
	$body = "Commentaires d'un[e] ami[e]: " . $comment . "<p>" . $data . "<p>" . "Ce texte est tire du site Samizdat\nhttp://www.samizdat.qc.ca";
	$subject = "Un article pour toi de la part d'un(e) ami(e)";
	mail($to, $subject, $body, "FROM: $from\nX-Mailer: samizdat.qc.ca\nContent-type: text/html");
	print"<h2>The article has been sent !</h2>"
	?>
		<p>
		&am
Hello,

I have a web site with a number of ordinary HTML pages containing articles. I recently discovered a PHP script that allows web pages to be emailed to a friend. I like this idea however, the original script worked within a PHP page. Get the script at (I've only kept the email portion):

http://www.phptr.com/essential/php/code/chapter6.zip

Because other sites have links to my pages and I'd rather not have those links going dead (404 Errors) if I changed the extention from .htm to .php. So I don't like the idea of changing my file names to be able to execute php code.

Get to the point...


Ok, ok...

To get this idea to work I have 2 pages, 1st, an ordinary HTML page with a form (NO PHP code !!) and a submit button that sends a hidden variable ($article, that page's URL actually) to a php page.

The php page picks up the $article variable and has a form as well with three text fields, one for friend's email address, one for the submitter's email address and a comments field.

I am able to get the variable (with the URL in it) to pass to the php form page (using a print $article; it returns the right path), however I'm not able to get the php script to open the page. The operation dies and I get a "Can't open file" message. I've tried using get and post form methods with no difference.

If I hardcode the SAME path into the php form (instead of using the passed variable) everything works.

What gives ?? I've asked around a bit already and it seems this can't be done...

See my code below...

bigno34
=====================================================================

HTML page (this is the form with transmits the URL)


<form name="FormName" action="../../modules/env_art.php" method="post">
		<input type="hidden" value="http://www.samizdat.qc.ca/vc/sexe/hs1.htm" name="article">Pour envoyer cet article &agrave; un ami, cliquez <input type="submit" value="ici" name="submitButtonName">.
		</form>



PHP page (this page is supposed to pick up the URL in the variable)
filename = "env_art.php"

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Envoyez l'article11</title>
	</head>

	<body topmargin="10," leftmargin="10" marginheight="10" marginwidth="10" background="../medias_inter/pat1.gif">

		<h2>Envoyez l'article</h2>
		<p>
		<form action="env_art.php" method="POST">
		</p><br><br>
		<table border="0" cellpadding="0" cellspacing="5" width="400">
			<tr>
				<td width="300" align="right">Couriel de votre destinataire:</td>
				<td width="100"><input type="text" name="to" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right">Votre couriel:</td>
				<td width="100"><input type="text" name="from" size="24"></td>
			</tr>
			<tr>
				<td width="300" align="right" valign="top">Un bref commentaire pour votre destinataire:</td>
				<td width="100"><textarea name="comment" cols="40" rows="4"></textarea></td>
			</tr>
		</table>
		<input type="submit" name="submit" value="Envoyez!">
		</form>
		</p>
<?

		//this is just to see if the variable got thru ok
   print "*" . $article . "*";

if(isset($submit)):
//next 3 lines may be useless...
	$article = str_replace("%2F","/",$article);
	$article = str_replace("%3A",":",$article);
	$article = trim( $article );

	($file = fopen( $article, "r" )) or die ("Can't open file");
	$data = fread( $file, 200000 );
	fclose($file);
	//$stripped_data = strip_tags($data);
	$body = "Commentaires d'un[e] ami[e]: " . $comment . "<p>" . $data . "<p>" . "Ce texte est tire du site Samizdat\nhttp://www.samizdat.qc.ca";
	$subject = "Un article pour toi de la part d'un(e) ami(e)";
	mail($to, $subject, $body, "FROM: $from\nX-Mailer: samizdat.qc.ca\nContent-type: text/html");
	print"<h2>The article has been sent !</h2>"
	?>
		<p>
		<?
		endif;
	?>
	</body>

</html>


?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

use urlencode to escape all the nasty special-characters

Code: Select all

print('<input type="hidden" value="'.urlencode($link).'" name="article">');
put the result of this into your html-pages. you'll get the uncoded data with

Code: Select all

$article=urldecode($_REQUEST&#1111;'article']);
btw: my french isn't that good. What's your site all about? interesting link anyway ;)
bigno34
Forum Newbie
Posts: 5
Joined: Tue May 21, 2002 9:43 pm

Post by bigno34 »

You're asking me to put PHP code into my HTML page ????

This seems to confirm what other people had told me, that passing variables (URLs) only works from one php page to another.
The thing is I'm STARTING with an HTML page and ending up on another PHP page.

Isn't there a trick to unscramble the URL with some str_replace() ?? I had attempted this, but didn't really know what needed replacing.

About my site, it's an odd-ball evangelical site. Yes, in our "policitally correct" era that's taboo. Sorry I mentioned it...


Paul
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

You're asking me to put PHP code into my HTML page ????
no I didn't as you should write the RESULT of this code into your HTML-page. This may be done by a script but since I'm trying setup linux on my server I have no php at the moment to test. But I was thinking about regular expressions to find the hidden-input and replace the value with it's urlencoded-counterpart. I try to hurry with the setup but will not send you an untested script example that may run frankenstein on your site ;)
But if you'd like to do it by hand: In the 'example-link' you have to replace all '/' by %2F , ':' by %3A and '.' by %2E
<input type="hidden" value="http%3A%2F%2Fwww%2Esamizdat%2Eqc%2Eca%2Fvc%2Fsexe%2Fhs1%2Ehtm" name="article">
About my site, it's an odd-ball evangelical site
jepp, I gave them to altavista-translate to at least get a glimps.
bigno34
Forum Newbie
Posts: 5
Joined: Tue May 21, 2002 9:43 pm

passing a URL as a var

Post by bigno34 »

Well waddaya know, I flipped your idea upside down and it worked.

In env_art.php I added the following code

Code: Select all

$article = str_replace("%2F","/",$article);
$article = str_replace("%3A",":",$article);
$article = str_replace("%2E",".",$article);

BEFORE doing the fopen() thing and it send my article fine !

thanx for the suggestions !
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

then you can use the urldecode-function as it is exactly what it's doing (+ some other replaces, that may occur)
bigno34
Forum Newbie
Posts: 5
Joined: Tue May 21, 2002 9:43 pm

passing a URL as a var

Post by bigno34 »

Well waddaya know, I flipped your idea upside down and it worked.

In env_art.php I added the following code

Code: Select all

$article = str_replace("%2F","/",$article);
$article = str_replace("%3A",":",$article);
$article = str_replace("%2E",".",$article);
BEFORE doing the fopen() thing and it send my article fine !

thanx for the suggestions !
Last edited by bigno34 on Wed May 22, 2002 3:54 pm, edited 1 time in total.
bigno34
Forum Newbie
Posts: 5
Joined: Tue May 21, 2002 9:43 pm

Post by bigno34 »

Ohhhhh poor stupid me...

I hadn't noticed that I'd taken the comments off the hardcoding so my script wasn't using the variable from the HTML form any more.

When I put the comments back in, nothing works anymore...

I tried using urldecode as well to process the var but that doesn't work either.


Ughhhh !!
Post Reply