bgbs Posted November 10, 2008 Share Posted November 10, 2008 I need to create a button link which determines where to go depending whether the user is signed in or not. So if he is not signed in, it takes him to registration, if he is, it takes him to a payment page. Is it possible to do something like that? Link to comment https://forums.phpfreaks.com/topic/132189-create-special-php-link/ Share on other sites More sharing options...
dropfaith Posted November 10, 2008 Share Posted November 10, 2008 use a php session and if the session is set send user to payment if session unset send users to register edit that up a bit should work <?php session_start( ); if(!isset($_SESSION["username"])){ header('Location: /register.php'); } else { header('Location: /payment.php'); } ?> Link to comment https://forums.phpfreaks.com/topic/132189-create-special-php-link/#findComment-687030 Share on other sites More sharing options...
premiso Posted November 10, 2008 Share Posted November 10, 2008 Entirely possible: Example: <?php session_start(); if (isset($_SESSION['loggedin']) && $_SESSION['loggedin']) { header('Location: registration.php'); }else { header('Location: payment.php'); } ?> Link to comment https://forums.phpfreaks.com/topic/132189-create-special-php-link/#findComment-687031 Share on other sites More sharing options...
bgbs Posted November 10, 2008 Author Share Posted November 10, 2008 wow, this looks complicated. Thanks for your help guys But where do I stick this code? Here is the button link. Button is generated by CSS. <div class="signuplink"><a href="register.php">To become a Premium Member - SIGN UP NOW </a> </div> So I erase the href and put in the php code in there? Link to comment https://forums.phpfreaks.com/topic/132189-create-special-php-link/#findComment-687085 Share on other sites More sharing options...
nitation Posted November 10, 2008 Share Posted November 10, 2008 at the top of every page i guess. Remember session_start(); my appear before outputting any html tags. Link to comment https://forums.phpfreaks.com/topic/132189-create-special-php-link/#findComment-687091 Share on other sites More sharing options...
blueman378 Posted November 10, 2008 Share Posted November 10, 2008 <?php session_start( ); if(!isset($_SESSION["username"])){ echo '<div class="signuplink"><a href="register.php">To become a Premium Member - SIGN UP NOW</a> </div>'; } else { echo '<div class="paymentlink"><a href="payment.php">Continue to checkout</a> </div>'; } ?> try that Link to comment https://forums.phpfreaks.com/topic/132189-create-special-php-link/#findComment-687118 Share on other sites More sharing options...
bgbs Posted November 10, 2008 Author Share Posted November 10, 2008 Ok, I tried that, but I get this error Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/wass/public_html/pricing.php:16) in /home/wass/public_html/inc.pricing.php on line 101 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/wass/public_html/pricing.php:16) in /home/wass/public_html/inc.pricing.php on line 101 Link to comment https://forums.phpfreaks.com/topic/132189-create-special-php-link/#findComment-687187 Share on other sites More sharing options...
premiso Posted November 10, 2008 Share Posted November 10, 2008 session_start() has to be called before any code is displayed to the browser, once that happens you cannot use that function or you will get the error. Move session_start to line one, like in the example above. Link to comment https://forums.phpfreaks.com/topic/132189-create-special-php-link/#findComment-687193 Share on other sites More sharing options...
bgbs Posted November 11, 2008 Author Share Posted November 11, 2008 For some reason its still not working. after I placed the code at the top it gives me this error now Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/wass/public_html/pricing.php:15) in /home/wass/public_html/inc.pricing.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at /home/wass/public_html/pricing.php:15) in /home/wasc/public_html/inc.pricing.php on line 4 Link to comment https://forums.phpfreaks.com/topic/132189-create-special-php-link/#findComment-687945 Share on other sites More sharing options...
dropfaith Posted November 11, 2008 Share Posted November 11, 2008 that error has been explained there cannot be anything whitespace included above the session start http://www.waynewhitty.com/blog.php?post=3 beginers sessions oddly enough its a link from a members site oooo Link to comment https://forums.phpfreaks.com/topic/132189-create-special-php-link/#findComment-688093 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.