Jump to content

[SOLVED] php under construction admin


dezkit

Recommended Posts

Cmon guys, he's not asking a fully working facebook clone, he just needs some guides. It feels like being in an auction here.

 

mate u need to have a config.php file where u can define a constant with the site maintaince value (on/off). In the admin panel make a checkbox and depending to its state (checked or not) write that value to config.php using php file handling functions, fopen() fread() and fwrite(). U dont need a mysql db for this. Just write the complete file with the <?php ?> tags, the constant and everything ure planning to put into. About the login, make a form with one input (type=password) and when it is set check if it is 123456, then redirect:

 

<?php
if(isset($_POST['password'])){
   if($_POST['password'] == '123456'){
        header("Location: admin.php");
   } else{
        echo 'Incorrect password';
   }
}
?>

 

Hope these helped.

Link to comment
Share on other sites

wow to everyone on this forum.... except a few select people...

 

your question is fairly simple...

 

create a table in MYSQL called 'test', with 2 columns, "id" and "answer"

and insert a row into it with id=1 and answer=yes

 

on the page...connect to the db, select a db, and  do this

$result = mysql_query("SELECT answer FROM test WHERE id='1'") or die(mysql_error());

$row = mysql_fetch_array($result);

 

if($row['answer'] == 'yes'){

show yes answer info

}elseif($row['answer'] == 'no'){

show no answer info

}

 

 

to update it... create a form...then make action.php

on action.php, do something like this

 

$update = $_POST['answer']

mysql_query("UPDATE test SET `answer`='$update' WHERE `id`='1' ")

 

Link to comment
Share on other sites

Using a database is a way, but isnt it a bit overwhelming? Usually site-related config variables are best to be kept in a config file where can just be included and used like normal variables and u dont have additional queries too. Anyway it is an easier method, but not as efficient.

Link to comment
Share on other sites

wow to everyone on this forum.... except a few select people...

 

your question is fairly simple...

 

create a table in MYSQL called 'test', with 2 columns, "id" and "answer"

and insert a row into it with id=1 and answer=yes

 

on the page...connect to the db, select a db, and  do this

$result = mysql_query("SELECT answer FROM test WHERE id='1'") or die(mysql_error());

$row = mysql_fetch_array($result);

 

if($row['answer'] == 'yes'){

show yes answer info

}elseif($row['answer'] == 'no'){

show no answer info

}

 

 

to update it... create a form...then make action.php

on action.php, do something like this

 

$update = $_POST['answer']

mysql_query("UPDATE test SET `answer`='$update' WHERE `id`='1' ")

 

 

thanks man, even though it didn't work, thanks for your time and patience to write this code, unlike some people.  ;D

Link to comment
Share on other sites

To cut it short. Make a config.php (or config.inc.php to distinguish included files) file:

 

<?php
//config.php
define('CONSTRUCTION', 'no');
?>

 

Then in the admin panel make a list or checkbox or whatever with yes, no value. Im going for the list (which im sure u know how to make):

 

<?php
if(isset($_POST['construction'])){
   $construction = $_POST['construction'];
   $handle = fopen('config.php', 'w+'); //open the file for writing
   $content = "<?php define('CONSTRUCTION', '{$construction}'); ?>"; //the content to be written
   fwrite($handle, $content); //write it
   fclose($handle);
}
?>

 

To use it:

 

<?php
include('config.php');
if(CONSTRUCTION == 'yes'){
   echo 'Site is under construction';
} else{
   //other code
}
?>

 

Hope it makes things clear.

Link to comment
Share on other sites

Then in the admin panel make a list or checkbox or whatever with yes, no value. Im going for the list (which im sure u know how to make):

 

like this?

 

admin.php

<?php
if(isset($_POST['construction'])){
    $construction = $_POST['construction'];
    $handle = fopen('config.php', 'w+'); //open the file for writing
    $content = "<?php define('CONSTRUCTION', '{$construction}'); ?>"; //the content to be written
    fwrite($handle, $content); //write it
    fclose($handle);
}
?>

<form action="">
<select name="construction">
<option value="yes">yes</option>
<option value="no">no</option>
</select>
<input type="submit" value="submit">
</form>

Link to comment
Share on other sites

this is what i have so far

vvvvvvvvvvvvvvv

 

 

index.php

<?php
include('config.php');
if(CONSTRUCTION == 'yes'){
    echo 'Site is under construction';
} else{
    echo 'LOL';
}
?>

 

 

config.php

<?php
//config.php
define('CONSTRUCTION', 'no');
?>

 

admin.php

<?php
if(isset($_POST['construction'])){
    $construction = $_POST['construction'];
    $handle = fopen('config.php', 'w+'); //open the file for writing
    $content = "<?php define('CONSTRUCTION', '{$construction}'); ?>"; //the content to be written
    fwrite($handle, $content); //write it
    fclose($handle);
}
?>

<form action="">
<select name="construction">
<option value="yes">yes</option>
<option value="no">no</option>
</select>
<input type="submit" value="submit">
</form>

 

 

 

 

 

it doesn't seem to work

Link to comment
Share on other sites

Modify as suggested and if it still doesnt work, tell where it is stuck. Does it get post data? Does it write config.php after the submit? Is config.php in the same directory as the other files? Does it trigger any error?

Link to comment
Share on other sites

<?php
if(isset($_POST['construction'])){
    $construction = $_POST['construction'];
    $handle = fopen('config.php', 'w+'); //open the file for writing
    $content = "<?php define('CONSTRUCTION', '{$construction}'); ?>"; //the content to be written
    fwrite($handle, $content); //write it
    fclose($handle);
}
?>

<form action="<?php $_SERVER['PHP_SELF']; ?>" method='POST'>
<select name="construction">
<option value="yes">yes</option>
<option value="no">no</option>
</select>
<input type="hidden" name="construction" value="true"><input type="submit" value="Submit">
</form>

Link to comment
Share on other sites

Modify as suggested and if it still doesnt work, tell where it is stuck. Does it get post data? Does it write config.php after the submit? Is config.php in the same directory as the other files? Does it trigger any error?

 

actually, it doesn't do anything...

 

but you know what, i'll scim through php.net and i will learn everysingle function.

 

thanks everybody!

 

topic solved.

Link to comment
Share on other sites

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.