Jump to content

PHP4->PHP5 Setting Cookies and fixing register global problems


Recommended Posts

Ok so I've narrowed my problems down to something with cookies.

 

Here is the code(problem with code follows).

 

<?
ini_set ('display_errors', 1);
include "config.inc.php";
include "english.inc.php";

if (array_key_exists('_submit_check', $_POST)) {
if ($_POST['name'] == $phpWebEd_username && $_POST['pass'] == $phpWebEd_userpass) {
	setcookie("auth", md5($_POST['name'].$_POST['pass']), 0, "/");
	if ($ed_type == "ax") setcookie("edtype", "ax", time() + 2592000, "/");
	else setcookie("edtype", "", time() - 100000 , "/");
	if (eregi("Apache", $HTTP_SERVER_VARS['SERVER_SOFTWARE'])) header("Location: index.php?check_cookie=1");
	else echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php?check_cookie=1\">";
	error_log (date("Y-m-d H:i") . "\t$name\t" . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "\r\n", 3, "logins.txt");
	exit();
}
else $errstr = $login_fail_str;
}

if ($check_cookie == 1) {
if ($_COOKIE['auth'] != "") {
	header("Location: $homepage_url");
	exit();
}
else $errstr = $cookie_warn_str; 
}
?>

 

Ok so the code is setting the cookie, but then it does

 

It's supposed to forward me to the homepage(then a script reads the cookie information).

Well I can't edit it anymore but the cookie setting function is working perfectly.  Now the only problem is forwarding after running index.php?check_cookie=1

 

so the problem code seems to be somewhere in here

 

if ($check_cookie == 1) {
if ($_COOKIE['auth'] != "") {
	header("Location: $homepage_url");
	exit();
}
else $errstr = $cookie_warn_str; 

Thats a great point.

 

Ok let me think about this.  The script posts the form to itself, when it posts with the correct information it sets the cookie then it refreshes the same page except adds ?check_cookie=1.  So that is where the check_cookie == 1.

 

the refresh to that page happens here

 

else echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php?check_cookie=1\">";

 

so why doesn't it go to the $homepage_url?

just for fun if you want to see it work go here

 

http://www.nickgarmon.com/admin

 

user admin

pass austin

 

if the page forwards you back to nickgarmon.com/index.php you know we got it working.  Otherwise it's not working.

 

edit.. still not working.  Does anyone have any suggestions to help debug?

I have an idea.  How do you get a variable that is passed in through the url.  Say I put index.php?johnny=50 would this automatically set the variable johnny=50?  Or do you have to some how tell the script to "get" this extra variable from the url?

 

Parse error: syntax error, unexpected '{' in /home//nickgarmon.com/admin/index.php on line 18

 

WHY??

 

here is code.. Line 18 is the if ($_COOKIE['auth'].... line

if ($check_cookie == 1) {
if ($_COOKIE['auth'] == md5($phpWebEd_username.$phpWebEd_userpass) {
	header("Location: info.php");
	exit();
}
else $errstr = $cookie_warn_str; 
}

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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