开发者

How to generate a pop-up window if a user is not logged in?

开发者 https://www.devze.com 2023-03-15 02:54 出处:网络
开发者_开发技巧In an HTML page: <a href=\"/files/getfile.php?name=abc.zip\">file download</a>

开发者_开发技巧In an HTML page:

<a href="/files/getfile.php?name=abc.zip">file download</a>

in PHP script(getfile.php):

if('notlogged')
{
  echo 'please, loggin~'; //pop up, possible?
  return false;
}

So my question is, When user click the anchor tag, can I pop up a login window if user didn't log?

I knew I can pre-check in Javascript before calling the PHP script whether user logged or not.

But, it's not my case for use; the PHP script should have to throw pop up code.

The page user is viewing should not changed — just pop up login window.


The PHP script is executed on the server site, so it cannot generate a popup window when the link is clicked. You can accomplish your goal one of two ways:

  1. Use Javascript to generate an AJAX call to your PHP script, and popup a login window as necessary.

  2. Use header( "Location: /your/login/script.php" ) in getfile.php to send the user to a login page, but with no popup.


You can try this:

<?php if(loggedin){?>
  <a href="/files/getfile.php?name=abc.zip">file download</a>
<?php
} else {
?>
  <a href="javascript:;" onclick="popup();">file download</a>
<?php } ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消