ejery Posted May 12, 2007 Share Posted May 12, 2007 this is part of login.php: ========================================================================= <?php ob_start(); $con = mysqli_connect('localhost', 'root', 'xxxxxx'); if ($con) { mysqli_select_db($con, 'admininfo'); $user = $_REQUEST["_user"]; $pass = $_REQUEST["_pass"]; } else { echo '<br><br>Error...'; } $query = mysqli_query($con, "SELECT passwords FROM adminlist WHERE username='$user'"); if (mysqli_num_rows($query) == 1) { $nam = 1; } else { $nam = 0; } $dbarray = mysqli_fetch_array($query,MYSQLI_BOTH); if ($pass == $dbarray['passwords']) { $pas = 1; } else { $pas = 0; } if ($nam == 1 && $pas == 1) { //session_start(); setcookie('uid', $user, time() + 14400, '/'); //$_SESSION['uid'] = $user; } ?> <html> <head> <title>asd</title> <?php if ($nam == 1 && $pas == 1) { echo '<meta http-equiv="refresh" content="3; URL=http://localhost/ad.php">'; } else { echo '<meta http-equiv="refresh" content="3; URL=http://localhost/adminlogin.php">'; } ?> =============================================================================[/size] this is what the ad page show when the login page redirected to ad.php: ============================================================================ Notice: Undefined index: uid in C:\htdocs\ad.php on line 3 ============================================================================ ad.php code: ============================================================= <?php //session_start(); echo $_COOKIE['uid]; //echo $_SESSION['uid']; ?> ============================================================== what is the problem?? when i use the SESSION or cookies it resulting the same "Notice: Undefined index: uid in C:\htdocs\ad.php on line 3" for your information im using: 1) PHP 5 2) Apache 2.2.4 3) MySQL 5 i really apperciate your help... thank u... Quote Link to comment https://forums.phpfreaks.com/topic/51045-_sessionsetcookies-problem/ Share on other sites More sharing options...
chigley Posted May 12, 2007 Share Posted May 12, 2007 Try uncommenting the session_start() lines as your code can't read the $_SESSION[] variables without it. Also, another error I just spotted: echo $_COOKIE['uid]; should be echo $_COOKIE['uid']; Quote Link to comment https://forums.phpfreaks.com/topic/51045-_sessionsetcookies-problem/#findComment-251202 Share on other sites More sharing options...
ejery Posted May 12, 2007 Author Share Posted May 12, 2007 that is pasting problem... i think u not really understand... Quote Link to comment https://forums.phpfreaks.com/topic/51045-_sessionsetcookies-problem/#findComment-251206 Share on other sites More sharing options...
chigley Posted May 12, 2007 Share Posted May 12, 2007 I'm confused as to what you're trying to do. Surely you realise that you can't read/write to $_SESSION[] variables without a session_start() line first, which in your snippet you have commented out. Quote Link to comment https://forums.phpfreaks.com/topic/51045-_sessionsetcookies-problem/#findComment-251208 Share on other sites More sharing options...
ejery Posted May 12, 2007 Author Share Posted May 12, 2007 ohh....ok.. actuly im using two method... first is Session and second is Cookies... when i use the first method i commented on the cookies method.. in the other hand i commented on the session... there is two file there: 1) login.php (purpose: to check if user log in is authorized or not, if authorized login.php redirect to ad.php [im using meta tag to do this]). method i use: (1) $_SESSION = $user; (2) setcookie('uid', $user, time() + 444444, '/'); 2) ad.php (purpose: showing the name of the logged in person.. i used to method: (1) echo $_SESSION['uid']; (2) echo $_COOKIE['uid'] when the login.php redirected to (using the meta tag) ad.php... it result: Notice: undefined index 'uid'...bla...bla.... what is the problem?? should i change some parameters in php.ini.... thnaks.. Quote Link to comment https://forums.phpfreaks.com/topic/51045-_sessionsetcookies-problem/#findComment-251211 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.