amsgwp Posted October 24, 2007 Share Posted October 24, 2007 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). Quote Link to comment https://forums.phpfreaks.com/topic/74635-php4-php5-setting-cookies-and-fixing-register-global-problems/ Share on other sites More sharing options...
amsgwp Posted October 24, 2007 Author Share Posted October 24, 2007 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; Quote Link to comment https://forums.phpfreaks.com/topic/74635-php4-php5-setting-cookies-and-fixing-register-global-problems/#findComment-377255 Share on other sites More sharing options...
steve448 Posted October 24, 2007 Share Posted October 24, 2007 Where have you previously set $check_cookie to 1? Your cookie will not be visible until the next page so you can't use if($_COOKIE['auth'] != "") on the same page it was set. Quote Link to comment https://forums.phpfreaks.com/topic/74635-php4-php5-setting-cookies-and-fixing-register-global-problems/#findComment-377366 Share on other sites More sharing options...
amsgwp Posted October 25, 2007 Author Share Posted October 25, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/74635-php4-php5-setting-cookies-and-fixing-register-global-problems/#findComment-377417 Share on other sites More sharing options...
unidox Posted October 25, 2007 Share Posted October 25, 2007 Try this: if ($check_cookie == 1) { if ($_COOKIE['auth'] != "") { header("Location: " . $homepage_url . ""); exit(); } else $errstr = $cookie_warn_str; Quote Link to comment https://forums.phpfreaks.com/topic/74635-php4-php5-setting-cookies-and-fixing-register-global-problems/#findComment-377418 Share on other sites More sharing options...
amsgwp Posted October 25, 2007 Author Share Posted October 25, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/74635-php4-php5-setting-cookies-and-fixing-register-global-problems/#findComment-377421 Share on other sites More sharing options...
amsgwp Posted October 25, 2007 Author Share Posted October 25, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/74635-php4-php5-setting-cookies-and-fixing-register-global-problems/#findComment-377432 Share on other sites More sharing options...
amsgwp Posted October 25, 2007 Author Share Posted October 25, 2007 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; } Quote Link to comment https://forums.phpfreaks.com/topic/74635-php4-php5-setting-cookies-and-fixing-register-global-problems/#findComment-377530 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.