Passing a parameter to the server

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

nmccamy
New php-forum User
New php-forum User
Posts: 4
Joined: Fri Feb 18, 2011 5:45 pm

Passing a parameter to the server

Postby nmccamy » Sat Feb 19, 2011 1:18 am

I'm new at this and trying to learn, so bear with me. I know how to code a simple form on the client side and have the server side send an e-mail based on the form contents, as shown in the following code:

Code: Select all

<form
   action="test.php"
   method=  "post">
   Name: <input type="text" name="fname" />
   <input type="submit" value = "Send"/>
</form>


Code: Select all

<?php
$to = "nm@mail.com";
$subject = "test.";
$message = $_POST["fname"];
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Your request has been sent.";?>


What I would like to do is have the server send an e-mail whenever a client visits a particular page. So basically I want to pass the name of the page as a string to the server and have the server e-mail that string. How do I do that?

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Passing a parameter to the server

Postby johnj » Fri Mar 11, 2011 9:50 pm

You can get the name of the file using,$_SERVER['SCRIPT_NAME']

reyborn
New php-forum User
New php-forum User
Posts: 9
Joined: Wed Mar 30, 2011 7:36 am
Contact:

Re: Passing a parameter to the server

Postby reyborn » Wed Mar 30, 2011 8:00 am

Getting the server variable script_name will only get the name of the page but not include the passed variables.

You need to get the variable passed and the script name and concantenate it as one string.





reyBorn Online Portal
http://reygcalantaol.com

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Passing a parameter to the server

Postby johnj » Thu Mar 31, 2011 6:14 am

@reyborn - I don't understand why we need to pass the variable? When ever a user visits a page (say page1.html), the server needs to send an email to somebody saying that page1.html has been visited. I think, all we need here is the name of the page that has been visited - correct me if I am wrong.

One way to do this will be - when page1.html is visited, a hidden variable is set to the current page name and the form gets auto submitted to some server.php where $_POST['hiddenvariable'] will give the script name.


Return to “Your Scripts”

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest