session - PHP if/else is not functioning properly -
i trying use if/else statement in php. trying if $_session['usr']; equal current directory ($dir_auth2) variable user trying access. can access directory or index.php have in it. else, if $_session['usr']; != current directory, redirect them home page. currently, when user types in else's directory, not theres can access it.
<?php session_name('tzlogin'); session_set_cookie_params(2*7*24*60*60); session_start(); //this if statement below problem if($_session['usr'] == $dir_auth1) { //this demo.php home page header("location: demo.php"); } else { echo "you logged in " . $dir_auth1; } $dir = getcwd(); $dir1 = str_replace('/home/pophub/public_html/', '/', $dir); $dir_auth = getcwd(); $dir_auth1 = str_replace('/home/pophub/public_html/gallry/', '', $dir_auth); echo $_session['usr']; echo $dir_auth1; $dir_user = getcwd(); $dir_user1 = str_replace('/home/pophub/public_html/gallry', '', $dir_user); ?>
either haven't posted whole script or don't define $dir_auth2 anywhere. bad since rely on value in
if($_session['usr'] == $dir_auth2) { also, should use die() after calling header()
header("location: demo.php"); die();
Comments
Post a Comment