-
Posts
2,527 -
Joined
-
Last visited
Posts posted by DeanWhitehouse
-
-
Can u have a look at this code and see why it doesn't work
<?php require_once '../includes/main.inc.php'; require_once '../includes/db_connect.php'; require_once '../includes/config_table.inc.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']; // 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" ); echo "<meta http-equiv='refresh' content='0; url=../index.php'>"; } 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=../admin/admin_centre.php'>"; } } 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(); ?>
admin centre code
<?php require_once '../includes/main.inc.php'; require_once '../includes/db_connect.php'; require_once '../includes/config_table.inc.php'; require_once '../includes/header.php'; require_once '../includes/footer.php'; require_once '../nav_bar.php'; if ($_SESSION['is_valid'] == true){ if ($_SESSION['user_level'] == 2){ echo "incorrect permissions"; } if ($_SESSION['user_level'] == 1){ echo "<table class='admin'><form method='post' action='writ_pref.php'> <tr><td> Home Page:</td><td> <input type='text' name='main_page' value='$main_page'><br></td></tr> <tr><td> Site Name:</td><td> <input type='text' name='site_title' value='$site_title'><br></td></tr> <tr><td> Disclaimer: </td><td> <input type='text' name='site_disclaimer' value='$site_disclaimer'><br></td></tr> <tr><td> Intro:</td><td> <input type='text' name='intro' value='$intro'><br></td></tr> <tr><td></td><td><input type='submit' value='Continue' name='check'> </td></tr></form> </table>"; } } else { echo "login"; } //table where user enters the sites details ?>
Any ideas
i have worked out that the login form doesn't work now.
the form requries all the files mentioned, so when u added this
function print_error($err_message) { require_once '../includes/header.php'; require_once '../includes/footer.php'; require_once '../nav_bar.php'; echo $err_message; exit; }
it stopped the code working.
-
ok then, write it yourself
-
er im not sure, all my code is in PHP not html but i think i no what to change.
Also is there a way of redirecting back to the page the user was on.
E.g they login on home.php
and they get redirected to home.php
not to the a set page.
Would i use $_server
-
Please PM me and i can write the code for you. For $10
-
I didn't write the cookie code so i do not no what to change in it etc.
this is the whole login code, without the form
<?php require_once '../includes/main.inc.php'; require_once '../includes/db_connect.php'; require_once '../includes/config_table.inc.php'; require_once '../includes/header.php'; require_once '../includes/footer.php'; require_once '../nav_bar.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']; $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" ); echo "<meta http-equiv='refresh' content='0; url=../index.php'>"; } 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=../admin/admin_centre.php'>"; } } else{ echo 'Login failed. Username and Password did not match database entries.'; } } else { echo "Form was not completed. Please go back and make sure that the form was fully completed."; } mysql_close(); ?>
-
ok, when i tried this code, i get a cannot modify header error for a split second then it works.
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=../index.php'>"; } 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=../admin/admin_centre.php'>"; } }
-
erm because i have already sent a header on the first page, therefore won't i recieve an error.
here is some of the code if this helps
in the login code
if ($user_level == 1) { echo "<meta http-equiv='refresh' content='2; url=../includes/setcookie.php?u=$username&p=$user_password'>"; } elseif ($user_level == 2){ echo "<meta http-equiv='refresh' content='2; url=../includes/setcookie.php?u=$username&p=$user_password'>"; } } else{ echo 'Login failed. Username and Password did not match database entries.'; }
cookie code
<?php $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=../admin/admin_centre.php'>"; ?>
-
erm, i can do, but at the moment i am using
<meta http-equiv='refresh' content='0; url=../admin/admin_centre.php'>
-
Erm, i kinda understand, can i show you what happens,
http://deanwhitehouse.awardspace.co.uk/login.php
the admin username is:
Blade280891
and password:
Natasha
the non-admin username is:
Bob
and password:
BOB
How would i create the cookies in the same page, do i put my create cookie code into the if, instead of the redirection code??
-
So to not take up room on the forum, i will post my question here.
I have a login page, when the user has logged in the page redirects to the create cookie page then this page redirects to the "next page",
my problem is that there is a gap when redirecting where you can see the login page once logged in, how can i make it so that when you log in you go straight to the "next page" and the cookie is created.
-
O rite, i didn't think cookies would work that way, i thought they just store the data i didn't no you can keep users logged in with it.
-
If i am right cookies are used for remeber me functions, but i think sites now use sessions to keep people logged in as the remeber me function, and cookies to remeber there username and/or password.
Is this right?
-
no one?
-
Anyone no?
-
wow, i charge way to low mine is about $14 per hour/£7.50 per hour.
-
how would i do that for when people enter data into a form, and submit it, as this will be data saved from the form
-
when you submit the password to check it encrypt it with md5 before checking
-
o yer, didn't notice that. My bad.
-
I would say you should use a javascript style changer with cookies to save the data.
-
Yer, mine should of worked though, i think
-
Hi, i am creating a CMS/Website template system.
I want it so that when the users enter say the title message into a form, but when i test this, the data is displayed on one line( <br> ).
How can i make it so that when they enter the data, it saves it as HTML format(in the sense of breaklines)
Here are the codes i am using
$intro = "Welcome to my portfolio, this site has been entirerly coded by me Please have a look at other pages";
<html> <head> <? require_once 'includes/main.inc.php'; require_once 'includes/db_connect.php'; require_once 'includes/config_table.inc.php'; require_once 'includes/header.php'; require_once 'includes/footer.php'; require_once 'nav_bar.php'; ?> </head> <table id="time"><tr><td><?php echo gmdate('l jS \of F Y');?><br><?php echo gmdate('h:i:s A');?></td></tr></table> </html> <?php if (is_dir(install)) { echo "<p class='exists'><br>Please remove the install folder</p>"; } else { echo "Please go to the admin centre to cutomise the site"; } echo "$intro"; ?>
-
ok, try this
these lines should work
<?php mysql_connect($conn) or die('Could not connect: ' . mysql_error()); mysql_query($sql_update) $sql_update "UPDATE users SET datetime=date("Y.m.d - H:i:s") WHERE username='$_SESSION[username]'") or die ("could not execute the query."; ?>
-
it seems ok
-
Try changing these
echo "<iframe src='fileB.php' width='800' height='300' scrolling='auto' frameborder='1'>";
echo "<table width='$tablewidth' border='1'><br>";
Remeber Me???
in PHP Coding Help
Posted
could this code be a problem,
this is header
footer
and nav bar
and home.php
is it because the session_start(); is in the header?