php - Struggling with checking if logged in -



php - Struggling with checking if logged in -

hi there i'm trying figure out how check if user logged in , if allow them come in page if not homecoming 'index.php'.

what i've done create duplicate pages of such 'index.php', 'index2.php', 'service.php' , 'service2.php' on , forth minor adjustments such no 'search bar'.

is still possible so? i'd 'check see if logged in' on pages '2' in them. such 'service2.php' or 'about2.php'

i've tried code

(keep in mind code not whole entire page)

if(check_login()) { echo 'you in!'; } else { header('location: login.php'); exit; } function check_login () { if(isset($_session['login'] && $_session['login'] != '') { homecoming true; } else { false; } }

only used code on pages want displayed

thanks in advance ! :)

update edit:

<?php include ('config.php'); include ('function.php'); $_session['login'] ?> <!doctype html> <html> <head> <title>honda | </title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <link href='http://fonts.googleapis.com/css?family=julius+sans+one' rel='stylesheet' type='text/css'> <link href="../css/style.css" rel="stylesheet" type="text/css" media="all" /> <!--slider--> <link href="../css/camera.css" rel="stylesheet" type="text/css" media="all" /> <script type='text/javascript' src='../js/jquery.min.js'></script> <script type='text/javascript' src='../js/jquery.mobile.customized.min.js'></script> <script type='text/javascript' src='../js/jquery.easing.1.3.js'></script> <script type='text/javascript' src='../js/camera.min.js'></script> <script> jquery(function(){ jquery('#camera_wrap_1').camera({ thumbnails: true }); jquery('#camera_wrap_2').camera({ height: '400px', loader: 'bar', pagination: false, thumbnails: true }); }); </script> </head> <body> <!--start header--> <div class="h_bg"> <div class="wrap"> <div class="wrapper"> <div class="header"> <div class="logo"> <a href="index.php"><img src="../images/logo.png"> </a> </div> <div class="cssmenu"> <ul> <li class="active"><a href="index.php"><span>home</span></a></li> <li><a href="about.php"><span>about</span></a></li> <li class="has-sub"><a href="service.php"><span>gallery</span></a> </li> <li class="last"><a href="contact.php"><span>contact</span></a></li> <div class="clear"></div> </ul> <div class="search"> <h2>search</h2> <form action="search.php" method="get"> <input type="text" name="search" value="" placeholder="enter search..."> <input type="submit" name="submit" value=""> </form> </div> <div class="search1"> <h2>login/register</h2> <form action="" method="post"> <label>username:</label> <input type="text" id="password" name="username" required /> <label>password:</label> <input type="password" id="password" name="password" required /> <input type="submit" value="login" name="submit" class="submit" /> <br><br> <center> <h2><p><a href="register.php">register</a></p></h2> </center> </form> </div> <?php if(isset($_post["submit"])){ if(!empty($_post['username']) && !empty($_post['password'])) { $username=$_post['username']; $password=$_post['password']; $password = strip_tags($password); $password = md5($password); // md5 used encrypt password create more secure. $con=mysql_connect('localhost','root','') or die(mysql_error()); mysql_select_db('aha') or die("cannot select db"); $query=mysql_query("select * login username='".$username."' , password='".$password."'"); $numrows=mysql_num_rows($query); if($numrows!=0) { while($row=mysql_fetch_assoc($query)) { $dbusername=$row['username']; $dbpassword=$row['password']; } if($username == $dbusername && $password == $dbpassword) { session_start(); $_session['sess_user']=$username; /* redirect browser */ header("location: member.php"); } } else { echo "<div class='results'>invalid username or password</div>"; } } else { echo "all fields required!"; } } ?> </div> <div class="clear"></div> </div> </div> </div> </div> <!-- start slider --> <div class="slider_bg"> <div class="wrap"> <div class="wrapper"> <div class="slider"> <!-- #camera_wrap_1 --> <div class="fluid_container"> <div class="camera_wrap camera_azure_skin" id="camera_wrap_1"> <div data-thumb="../images/thumbs/slider1.jpg" data-src="../images/slider/slider1.jpg"> </div> <div data-thumb="../images/thumbs/slider2.jpg" data-src="../images/slider/slider2.jpg"> </div> <div data-thumb="../images/thumbs/slider3.jpg" data-src="../images/slider/slider3.jpg"> </div> <div data-thumb="../images/thumbs/slider4.jpg" data-src="../images/slider/slider4.jpg"> </div> </div><!-- #camera_wrap_1 --> <div class="clear"></div> </div> <!-- end #camera_wrap_1 --> <div class="clear"></div> </div> </div> </div> </div> <!-- start content --> <div class="content_bg"> <div class="wrap"> <div class="wrapper"> <div class="main"> <!-- start content_right --> <div class="image group"> <div class="grids_of_2"> <div class="grid images_3_of_1"> <img src="../images/pic1.jpg"> </div> <div class="grid span_2_of_3"> <h3>how started</h3> <p class="para">honda motor co., ltd. (本田技研工業株式会社 honda giken kōgyō kk?, ipa: [hoɴda] ( listen); /ˈhɒndə/) japanese public multinational corporation known manufacturer of automobiles, motorcycles , powerfulness equipment. honda has been world's largest motorcycle manufacturer since 1959,[3][4] world's largest manufacturer of internal combustion engines measured volume, producing more 14 1000000 internal combustion engines each year.[5] honda became second-largest japanese automobile manufacturer in 2001.[6][7] honda 8th largest automobile manufacturer in world behind general motors, volkswagen group, toyota, hyundai motor group, ford, nissan, , psa in 2011.[8] honda first japanese automobile manufacturer release dedicated luxury brand, acura, in 1986. aside core automobile , motorcycle businesses, honda manufactures garden equipment, marine engines, personal watercraft , powerfulness generators, amongst others. since 1986, honda has been involved artificial intelligence/robotics research , released asimo robot in 2000. have ventured aerospace establishment of ge honda aero engines in 2004 , honda ha-420 hondajet, began production in 2012. honda has 3 joint-ventures in china (honda china, dongfeng honda, , guangqi honda). in 2013, honda invested 5.7% (us$ 6.8 billion) of revenues in research , development.[9] in 2013, honda became first japanese automaker net exporter united states, exporting 108,705 honda , acura models while importing 88,357</p> </div> <div class="clear"></div> </div> <div class="grids_of_2 top"> <div class="grid images_3_of_1"> <img src="../images/pic2.jpg"> </div> <div class="grid span_2_of_3"> <h3>ceo of honda</h3> <p class="para">kawamoto acted alter honda's corporate culture, rushing through market-driven product development resulted in recreational vehicles such odyssey[disambiguation needed] , cr-v, , refocusing away of numerous sedans , coupes popular honda's engineers not buying public. shocking alter honda came when kawamoto ended honda's successful participation in formula 1 after 1992 season, citing costs in lite of takeover threat mitsubishi want create more environmentally-friendly company image.[21] later, 1995 gave rising honda aircraft company goal of producing jet aircraft under honda's name</p> </div> <div class="clear"></div> </div> </div> </div> </center> <div class="clear"></div> </div> </div> </div> </div> <div class="footer_bg"> <div class="wrap"> <div class="wrapper"> <div class="footer"> <div class="copy"> <p class="w3-link">©&nbsp;</p> </div> <div class="f_nav"> <ul> <li><a href="#">skype</a></li> <li><a href="#">linked in</a></li> <li><a href="#">twitter</a></li> <li><a href="#">facebook</a></li> </ul> </div> <div class="clear"></div> </div> </div> </div> </div> </body> </html> </body> </html>

you missing paranthesis in isset in check login function, function made simpler.

// i'd set function in mutual file. function check_login() { homecoming isset($_session['login']) && $_session['login'] != ''; } // in other files include mutual file, , if (!check_login()) { header('location: login.php'); exit; }

php mysql

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -