Page 1 of 1

$_SESSION/setcookies problem

Posted: Sat May 12, 2007 4:19 am
by ejery
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


this is part of login.php:

Code: Select all

<?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">'; }
?>
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:

Code: Select all

<?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...


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Re: $_SESSION/setcookies problem

Posted: Mon May 14, 2007 2:04 pm
by califdon
ejery wrote: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"
If that's not just a typo when you posted this message, you're missing a single quote at the end of uid in echo $_COOKIE['uid];

Then, why is session_start(); commented out?

One of the two items above may be causing your error.

If you post code again, please use the available PHP or Code brackets (on the toolbar) when you enter your message. It helps make reading the message easier.

Posted: Mon May 14, 2007 5:33 pm
by RobertGonzalez
Are you checking to make sure cookies are being set? Also, never just assume in your code that the value you are looking for is there. The error you are getting is because there is no known $_COOKIE array index by the name of 'uid'. Use isset() or empty() to see if they have a value before attempting to use the value.