Vlad
Vlad

Reputation: 860

how can php know which html-file called it

If we have 2 html files (i.e. one.html and two.html) and within both we have a form which calls the same php file on submit, like:

<form method="post" action="example.php"> 

, how can example.php know which html file called it?

I'm new to php so any comments are appreciated.

Upvotes: 0

Views: 102

Answers (2)

Ren&#233; H&#246;hle
Ren&#233; H&#246;hle

Reputation: 27295

There are some ways to solve this problem. It is possible to read the referer from $_SERVER['HTTP_REFERER'].

Or you set a parameter in your form to identify from where you come.

<form method="post" action="example.php?id=xy">

in your example.php you can read the $_GET['id'] and do something with a if statement or a switch.

Upvotes: 2

gview
gview

Reputation: 15361

See http://php.net/manual/en/reserved.variables.server.php

The $_SERVER['HTTP_REFERER'] variable, while not trustworthy from a security standpoint, will provide you what you want in most cases.

You could also put a hidden input in your form and pass a variable with the form name or some id that you could use.

Upvotes: 3

Related Questions