Seting cookies

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
glav
Forum Newbie
Posts: 13
Joined: Sat Feb 25, 2006 1:54 pm

Seting cookies

Post by glav »

Hi, I have a problem with cookies. Does some old scripts that worked on PHP 4 not work on PHP 5? I have the latest PHP but for some reason cookies are not being set and when I use the log-in section of the script the log-in page just refreshes. If i input wrong user and pass I get an error but the correct info only refreshes the page. I am running the latest stable release of Apache, MySQL and PHP. These scripts ran perfect a year ago on older versions of Apache, MySQL and PHP. I have read all the docs and I am nearly sure I have setup every thing OK. I do have some scripts that work fine on new versions and even the scripts with the log-in problem work fine apart from this. And I am running this on my own XP machine which I never did before. Last time I tested on DonHost.

Please Please Help.

Thanks,
Glav
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post your code?
glav
Forum Newbie
Posts: 13
Joined: Sat Feb 25, 2006 1:54 pm

Tomorrow

Post by glav »

I will but I did not bring it with me so It'll have to be tomorrow. But it is with a few scripts. I post one.

Thanks
glav
Forum Newbie
Posts: 13
Joined: Sat Feb 25, 2006 1:54 pm

Here is the script

Post by glav »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Here is one script. It is tforum. I have used it for years. I loaded phpbb and it worked and also w-agaro but not tforum.

Code: Select all

###STEP 1

<form action="../login.php" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr valign="top">
		<td align="center" valign="top">
			<span style="font-weight:bold;">You don't have admin permission.</span>
			<?php echo $txt['username']?>: <input type="text" name="username" size=10 maxlength=25>
			<?php echo $txt['password']?>: <input type="password" name="password" size=10 maxlength=15>
			<input type="hidden" name="forwardurl" value="<?php echo $fSettings['ScriptURL'],'/'?>admin/index.php">
			<input type="submit" name="submit" value="Login">
		</td>
	</tr>
</table>
</form>


###STEP 2

<?php
include('./includes/tf-inc.php');
if ($_COOKIE['userid'] != 0)
{	Redirect($_POST['forwardurl']);
}
else
{	LoginPage($txt['errInvalidUser'],$_POST['forwardurl']);
}
?>

###STEP 3

<?php
// Include some Files
include('./db.php');
include('./includes/functions.php');
include('./includes/usergrouppermdefs.php');
if (!isset($noutput))
{	include('./language/text.php');
	include('./includes/template_parser.php');
}
// Initialize some Globals
define('CRLF',"\r\n");
$GLOBALS['query_count'] = 0;
$GLOBALS['start_time'] = Getmicrotime();
$GLOBALS['cookie_count'] = 0;
// Get Settings
$fSettings = GetSettings();
include('./includes/gzip_begin.php');
$fSettings['ScriptPath'] = '.';
// Basic Entities
$ent['ScriptURL'] = $fSettings['ScriptURL'];
$ent['SiteURL'] = $fSettings['SiteURL'];
$ent['title'] = $ent['ForumName'] = $fSettings['ForumName'];
$ent['Version'] = $fSettings['Version'];
$ent['bodyadd'] = '';
// Clean SGlobals
Clean_SGlobals($_GET);
Clean_SGlobals($_POST);
include('./includes/grab_globals.php');
GetIDs();
//UhOh('Just testing!');
// Forward URL
if (!count($_POST))
{	$ent['forwardurltext'] = substr(ArrayToURL($_GET),0,-1);
	$ent['forwardurltext'] = ($ent['forwardurltext']) ? $_SERVER['PHP_SELF'].'?'.$ent['forwardurltext'] : $_SERVER['PHP_SELF'];
}
else
{	$ent['forwardurltext'] = 'index.php';
}
$ent['forwardurlenc'] = URLEncode($ent['forwardurltext']);
$ent['forwardurl'] = MakeHiddenField('forwardurl',$ent['forwardurltext']);
// User Stuff
CookieRead();
switch(basename($_SERVER['PHP_SELF']))
{	case 'login.php':
		Login();
		break;
	case 'logout.php':
		Logout();
		break;
	case 'index.php':
	case 'viewboard.php':
		UpdateReadTopics();
		break;
}
$CurrentUser = CheckUserInfoCookie();
// Theming 
if (!$CurrentUser['Theme'] || $CurrentUser['Theme'] == 'default')
{	$ent['Theme'] = 'default';
	$ent['ThemeURL'] = $fSettings['ScriptURL'];
	$ent['ThemePath'] = $fSettings['ScriptPath'];
}
else
{	$ent['Theme'] = $CurrentUser['Theme'];
	$ent['ThemeURL'] = $fSettings['ScriptURL'].'/themes/'.$ent['Theme'];
	$ent['ThemePath'] = $fSettings['ScriptPath'].'/themes/'.$ent['Theme'];
}
if (!isset($noutput))
{	include($ent['ThemePath'].'/templates/buttons.php');
}
// More User Stuff
$CurrentUser['LastAction'] = TranslateAction(basename($_SERVER['PHP_SELF']));
$ent['CurrentUser'] = $CurrentUser['UserName'];
$ent['UserID'] = $CurrentUser['UserID'];
if ($UserInfo['GroupID']==5 || isBanned())
{	UhOh('errBanned');
}
if ($fSettings['shutdown']=='y' && !CheckBit($CurrentUser['GPermMask'],$UGPermDefs,'canviewlockedforum'))
{	SomeMessage($txt['ForumShutdown'],$txt['ForumShutdownMsg']);
}
if (isset($PermissionRequired))
{	if (!CheckBit($CurrentUser['GPermMask'],$UGPermDefs,$PermissionRequired))
	{	NoPerm();
	}
}
if ($_COOKIE['userid']==0)
{	$ent['usernamebox'] = MakeSmallUserPassBox('text','username','');
	$ent['passwordbox'] = MakeSmallUserPassBox('password','password','');
	$ent['loginbutton'] = MakeButton($txt['Login']);
	$ent['quicklogin'] = ParseTemp(ReadTemplate('quicklogin'),$ent);
}
else
{	$ent['logoutbutton'] = MakeButton($txt['Logout']);
	$ent['quicklogin'] = ParseTemp(ReadTemplate('quicklogout'),$ent);
}
$ent['adminpanel'] = ($CurrentUser['isadmin']) ? '<a href="admin/index.php">'.$buttons['adminpanel'].'</a><p>' : '';
?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

unfortunately, it's a bit hard to tell what problem you could have with cookies because your code is calling script defined functions regarding them.
Post Reply