I have a PHP page with a form, whose action is another PHP file (send.php).
When this page is loaded it sends data from the form to a MySQL table.
Now in this send.php I have 2 links. But I want to know if the user that just sent info through the form also clicks on the links.
My idea was to create a new table and execute the mysql query again, but in a new table, in order to compare who did the 2 actions (form and click on links) and who did just the form one.
First idea was to create a session after the form query, so with JavaScript I can trigger a query again after clicking on one of the links.
But the links forward to an external page (they are social media sharing links).
Any ideas how to do this?
Update: Now im trying with
<a href="shared.php" onclick="window.open('https://site_to_open');">Link Text</a>
Problem is that after first query in current page (send.php), variables doesn't keep stored.
I also tried with:
session_start();
$_SESSION['name'] = $_POST['name'];
But variables are not stored too.
Notice: Undefined variable: _SESSION in [...]
答案 0 :(得分:0)
您可以让链接指向本地脚本,并将实际外部链接附加为参数。在该脚本中,只需记录点击或您想要做的任何事情。最后,使用通常的标题重定向到外部网站('Location:...');东西。
欢呼:)答案 1 :(得分:0)
好的,所以我用更新中解释的方法解决了这个问题。我的问题是在第二页shared.php中没有使用session_start();
。现在它的工作就像一个魅力。那些试图尝试尝试这个的人的代码:
在send.php中:
session_start();
$_SESSION['name'] = $_POST['name'];
$_SESSION['email'] = $_POST['email'];
mysqli_query($conexion,"SELECT * FROM people");
mysqli_query($conexion,"INSERT INTO people (name,email) VALUES ('".$_POST['nombre']."', '".$_POST['email']."')");`
然后,在shared.php中:
session_start();
mysqli_query($conexion,"SELECT * FROM shared");
mysqli_query($conexion,"INSERT INTO shared (name,email) VALUES ('".$_SESSION['name']."', '".$_SESSION['email']."')");`