简体   繁体   English

单击URL到不加载并停留在当前页面的php页面(仅加载cookie)

[英]Clicking URL to php page (to load cookies only) that does not load and stay in current page

I want to create an hyperlink() to a PHP file in server that runs the PHP without open a new page, staying in the page where I click the hyperlink. 我想在运行PHP的服务器中创建指向PHP文件的超链接(),而无需打开新页面,而是停留在单击超链接的页面中。

Consideration 1: Without JS or jQuery, etc in the page where the <a> is. 注意事项1: <a>所在的页面中没有JS或jQuery等。 Consideration 2: PHP code has to run completely without open it in a new page. 注意事项2:PHP代码必须完全运行,而无需在新页面中打开它。 web user do not feel changes in the current page and stay in the same page. 网络用户不会感觉到当前页面的变化,而是停留在同一页面上。

HTML: HTML:

<a href="http://localhost/test_site/php/create_cookie.php?name=Alan&lastname=Harper">Save your name for future access.</a>

PHP: PHP:

<?php //create_cookie.php
`$cookie_name = "user_name";
$cookie_value = $_GET['name'] . " " . $_GET['lastname'];
setcookie($cookie_name, $cookie_value, time() + 86400, "/");
$_COOKIE['$cookie_name'] = $cookie_value;`

?> ?>

Just redirect back in the PHP-file to the file with the link, and set the redirect-time to 0. 只需将PHP文件重定向回带有链接的文件,并将重定向时间设置为0。

Something like header('location: <originalfile>'); 类似于header('location: <originalfile>'); at the bottom of the php-file. 在php文件的底部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM