-
Posts
2,527 -
Joined
-
Last visited
Posts posted by DeanWhitehouse
-
-
my offer is still there
-
as shown in the code i tried meta refresh and header and both present with the same issue, also i can't set the cookies either.
the header file needs to be changed or the something else.
-
o ok, then so for my CMS/Website Template would you recomend storing things like welcome message etc. in the database rather than a .inc.php file?
-
i disagree, i think it is easier to edit and access using .inc.php and databases (from what i have seen from PHP cms) are not generally used to store large pieces of data, like whole page content.
-
no problem.
i now have another problem, (acutally the reason i tried this way was to overcome the problem).
i need the form to redirect after the user logged in depending on there userclass.
It is meant to redirect to the page they where on, but the header information is already been sent by another file, can anyone see a way to get around this?
header.php
<?php session_start(); echo ("<title>$site_title</title>"); echo ("<link rel='stylesheet' type='text/css' href='../Themes/style.css' />"); echo ("<table class='title'><tr><td align='center'><h1>$custom_header</h1></td></tr></table>"); ?>
this is where the header information is already sent from
this is where i need to redirect
if ($user_level == 1) { $login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = '$_GET[p]'")); $userright = array($login_check['user_name'], $login_check['userlevel']); $s_userpass = serialize($userpass); setcookie( "$cookiename" , $s_userpass , time()+$custom_time , "" , "127.0.0.1" ); header("Location:http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]); $_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files $_SESSION['username'] = $row['user_name']; $_SESSION['user_level'] = $row['userlevel']; } elseif ($user_level == 2){ $login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = '$_GET[p]'")); $userright = array($login_check['user_name'], $login_check['userlevel']); $s_userpass = serialize($userpass); setcookie( "$cookiename" , $s_userpass , time()+$custom_time , "" , "127.0.0.1" ); echo "<meta http-equiv='refresh' content='0; url=../index.php'>"; $_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files $_SESSION['username'] = $row['user_name']; $_SESSION['user_level'] = $row['userlevel']; } }
-
yer, but this is for storing information that you want to edit, like the page title for example. He wasn't asking where to store user data.
-
Ah,how did you find it so fast
-
http://www.phpfreaks.com/forums/index.php/topic,192840.msg866700.html#msg866700
read this for more info on the .inc.php file
this code will write to the file( to edit it i am still unsure, as i beleive this rewrites the whole file)
<?php //it makes this file, if it doesn't exist $config_file = "../includes/config.inc.php"; $fw=fopen($config_file,"w+") or die("Unable to open file!"); // Unable to open file $config_host = "\$dbhost = \"".$dbhost."\";\n"; $config_user = "\$dbuser = \"".$dbuser."\";\n"; $config_pass = "\$dbpass = \"".$dbpass."\";\n"; $config_db = "\$dbname = \"".$dbname."\";"; $config_write = $config_host.$config_user.$config_pass.$config_db; fwrite($fw, "<?php\n".$config_write."\n?>"); fclose($fw); ?>
-
ok, thanks
i changed my code like this
<?php require_once '../includes/main.inc.php'; require_once '../includes/db_connect.php'; require_once '../includes/config_table.inc.php'; session_start(); // Only include the header and footers if you have to print errors function print_error($err_message) { require_once '../includes/header.php'; require_once '../includes/footer.php'; require_once '../nav_bar.php'; echo $err_message; exit; } if(isset($_POST['admin_login'])){ $user_name = $_POST["user_name"]; $user_password = $_POST["user_password"]; $verify_username = strlen($user_name); $verify_pass = strlen($user_password); if ($verify_pass > 0 && $verify_username > 0) { $salt = substr($user_password, 0, 2); $userPswd = crypt($user_password, $salt); $sql = "SELECT * FROM `$user` WHERE user_name='$user_name' AND user_password='$userPswd' LIMIT 1;"; $result = mysql_query($sql); if (mysql_num_rows($result) == 1){ $row = mysql_fetch_assoc($result); $user_level = $row['userlevel']; if ($user_level == 1) { $login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = '$_GET[p]'")); $userright = array($login_check['user_name'], $login_check['userlevel']); $s_userpass = serialize($userpass); setcookie( "$cookiename" , $s_userpass , time()+$custom_time , "" , "127.0.0.1" ); header("Location:http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]); $_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files $_SESSION['username'] = $row['user_name']; $_SESSION['user_level'] = $row['userlevel']; } elseif ($user_level == 2){ $login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = '$_GET[p]'")); $userright = array($login_check['user_name'], $login_check['userlevel']); $s_userpass = serialize($userpass); setcookie( "$cookiename" , $s_userpass , time()+$custom_time , "" , "127.0.0.1" ); echo "<meta http-equiv='refresh' content='0; url=../index.php'>"; $_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files $_SESSION['username'] = $row['user_name']; $_SESSION['user_level'] = $row['userlevel']; } } else{ print_error( 'Login failed. Username and Password did not match database entries.'); } } else { print_error( "Form was not completed. Please go back and make sure that the form was fully completed."); } mysql_close(); ?> <html> <table bgcolor='#999999' align='right'><form action="<?php $_SERVER['PHP_SELF']; ?>" method='POST'> <tr><td>Username: </td><td><input type='text' name='user_name' /><br /></td></tr> <tr><td>Password:</td><td> <input type='password' name='user_password' /><br /></td></tr> <tr><td><input type='submit' value='Continue' name='admin_login' /></td></tr> </form></table> </html>
but i get an error saying Parse error: syntax error, unexpected $end in /home/www/deanwhitehouse.awardspace.co.uk/admin/admin_login.php on line 78
this is the bottom line.
-
erm, a better example.
page 1 code
<?php require_once 'edited.inc.php'; echo"$user_edited"; ?>
edited.inc.php
<?php $user_edited = "Stuff for users to edit"; ?> then you have a script, (which i have if you need) that will write this data into the edited.inc.php the data there can be taken from a form. Bit like mysql, without the database.
-
Is it possible to have a login(input) form and the login(proccessor) in the same file??
And if so, can i been shown an example and how to post the form to self
-
i am using a .inc.php file for editable content and writing to it when it is changed
e.g.
i have a form that submits the data. $data
then i have a code that writes this data to the .inc.php file
then i include the file on everypage
then refer to the content by
echo "$data";(or something similar)
then make a form for them to edit it.
-
<?php require_once '../includes/main.inc.php'; require_once '../includes/db_connect.php'; require_once '../includes/config_table.inc.php'; session_start(); // Only include the header and footers if you have to print errors function print_error($err_message) { require_once '../includes/header.php'; require_once '../includes/footer.php'; require_once '../nav_bar.php'; echo $err_message; exit; } $user_name = $_POST["user_name"]; $user_password = $_POST["user_password"]; $verify_username = strlen($user_name); $verify_pass = strlen($user_password); if ($verify_pass > 0 && $verify_username > 0) { $salt = substr($user_password, 0, 2); $userPswd = crypt($user_password, $salt); $sql = "SELECT * FROM `$user` WHERE user_name='$user_name' AND user_password='$userPswd' LIMIT 1;"; $result = mysql_query($sql); if (mysql_num_rows($result) == 1){ $row = mysql_fetch_assoc($result); $user_level = $row['userlevel']; if ($user_level == 1) { $login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = '$_GET[p]'")); $userright = array($login_check['user_name'], $login_check['userlevel']); $s_userpass = serialize($userpass); setcookie( "$cookiename" , $s_userpass , time()+$custom_time , "" , "127.0.0.1" ); header("Location:".$_SERVER[REQUEST_URI]); $_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files $_SESSION['username'] = $row['user_name']; $_SESSION['user_level'] = $row['userlevel']; } elseif ($user_level == 2){ $login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = '$_GET[p]'")); $userright = array($login_check['user_name'], $login_check['userlevel']); $s_userpass = serialize($userpass); setcookie( "$cookiename" , $s_userpass , time()+$custom_time , "" , "127.0.0.1" ); echo "<meta http-equiv='refresh' content='0; url=../index.php'>"; $_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files $_SESSION['username'] = $row['user_name']; $_SESSION['user_level'] = $row['userlevel']; } } else{ print_error( 'Login failed. Username and Password did not match database entries.'); } } else { print_error( "Form was not completed. Please go back and make sure that the form was fully completed."); } mysql_close(); ?>
this code is meant to when the admin(user level 1) logs in, redirect them to another page, but it resends the form when it gets there and says "Form was not completed. Please go back and make sure that the form was fully completed." but it does create the session and log them in, but doesn't redirect properly,any ideas?
-
then if they come from an external site, have it echo a link to index.php on your site??
-
does anyone no??
-
i use sql database and .inc.php file(this is simpiler and requires less work)
-
erm, well, using this code i get the error, not all fields field in, but the session is created for the admin so it has logged in, but resent so thats why the error is showing.
to see for your self,
http://deanwhitehouse.awardspace.co.uk/admin/admin_centre.php
Username:
Blade280891
Password:
Natasha
case sensitive. The error appears at the top left, and refresh to see the admin centre
<?php require_once '../includes/main.inc.php'; require_once '../includes/db_connect.php'; require_once '../includes/config_table.inc.php'; session_start(); // Only include the header and footers if you have to print errors function print_error($err_message) { require_once '../includes/header.php'; require_once '../includes/footer.php'; require_once '../nav_bar.php'; echo $err_message; exit; } $user_name = $_POST["user_name"]; $user_password = $_POST["user_password"]; $verify_username = strlen($user_name); $verify_pass = strlen($user_password); if ($verify_pass > 0 && $verify_username > 0) { $salt = substr($user_password, 0, 2); $userPswd = crypt($user_password, $salt); $sql = "SELECT * FROM `$user` WHERE user_name='$user_name' AND user_password='$userPswd' LIMIT 1;"; $result = mysql_query($sql); if (mysql_num_rows($result) == 1){ $row = mysql_fetch_assoc($result); $user_level = $row['userlevel']; if ($user_level == 1) { $login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = '$_GET[p]'")); $userright = array($login_check['user_name'], $login_check['userlevel']); $s_userpass = serialize($userpass); setcookie( "$cookiename" , $s_userpass , time()+$custom_time , "" , "127.0.0.1" ); header("Location:".$_SERVER[REQUEST_URI]); $_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files $_SESSION['username'] = $row['user_name']; $_SESSION['user_level'] = $row['userlevel']; } elseif ($user_level == 2){ $login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = '$_GET[p]'")); $userright = array($login_check['user_name'], $login_check['userlevel']); $s_userpass = serialize($userpass); setcookie( "$cookiename" , $s_userpass , time()+$custom_time , "" , "127.0.0.1" ); echo "<meta http-equiv='refresh' content='0; url=../index.php'>"; $_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files $_SESSION['username'] = $row['user_name']; $_SESSION['user_level'] = $row['userlevel']; } } else{ print_error( 'Login failed. Username and Password did not match database entries.'); } } else { print_error( "Form was not completed. Please go back and make sure that the form was fully completed."); } mysql_close(); ?>
-
yer because it is resending the data. is there anyway to stop it doing this, as i don't think/no if i can add a header instead of the meta refresh
-
Another problem,
this code
if ($user_level == 1) { $login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = '$_GET[p]'")); $userright = array($login_check['user_name'], $login_check['userlevel']); $s_userpass = serialize($userpass); setcookie( "$cookiename" , $s_userpass , time()+$custom_time , "" , "127.0.0.1" ); echo "<meta http-equiv='refresh' content='0; url=$_SERVER[REQUEST_URI]'>"; $_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files $_SESSION['username'] = $row['user_name']; $_SESSION['user_level'] = $row['userlevel']; } elseif ($user_level == 2){ $login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = '$_GET[p]'")); $userright = array($login_check['user_name'], $login_check['userlevel']); $s_userpass = serialize($userpass); setcookie( "$cookiename" , $s_userpass , time()+$custom_time , "" , "127.0.0.1" ); echo "<meta http-equiv='refresh' content='0; url=../index.php'>"; $_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files $_SESSION['username'] = $row['user_name']; $_SESSION['user_level'] = $row['userlevel']; } }
how can i stop it reposting the data, as it does store the session, but when it takes you back to the page it reposts the data(which is blank)
-
fixed, i just added session_start(); to the top of the login script, as all my other pages contain the session_start(); part in the header.php file
-
heres a much as i will say. the value $construction needs to be saved somewhere then called form that location. simple if you no how to do it
-
Ok, i don't have a clue about what you just said,lol,
soz,
shall i just add the session start to the top of everypage??
-
huh? u kinda lost me, is that not waht i already have
-
erm no, but because they are only included if there is an error, they won't run. How can i get around this, without having to recode alot of it?
Editing pages
in PHP Coding Help
Posted
no, not what i meant, i mean this
this is editable, would this be better to be saved in .inc.php file or mysql