简体   繁体   中英

How to display alert if user has't logged in

I have a package page. all users can access it. those who want to order this package must log in first. when the user hasn't logged in and they click the booking button a warning will appear. "You must log in". how can I set like that. this is the packages https://i.imgur.com/CSSszbo.png

The simplest way to do this is:

While creating links check if the user is logged in or not. If user is logged in then add url of the package, otherwise add a simple javascript code to open popup.

If you are using session then you might need to add something like this:

if (isset($_SESSION['user'])){ ?>
    <a href="http://www.example.com">Booking</a><?php
}
else{ ?>
    <a href="#" onclick="alert('You must log in')">Booking</a><?php
}

Also you would need to add redirection for non logged in users on the package page as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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