Jump to content

DeanWhitehouse

Members
  • Posts

    2,527
  • Joined

  • Last visited

Posts posted by DeanWhitehouse

  1. 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.

  2. 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'];
    	}
    }

  3. 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);
    
    ?>

  4. 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.

  5. 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.
    

  6. 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.

  7. <?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?

  8. 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();
    ?> 

  9. 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)

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