Jump to content

$_SESSION/setcookies problem


ejery

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/51045-_sessionsetcookies-problem/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.