9 Replies - 2798 Views - Last Post: 02 March 2013 - 09:03 AM Rate Topic: -----

#1 Vompaudi  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 23-November 12

"create new site" option for PHP admin panel

Posted 26 February 2013 - 09:37 AM

So, I have made own admin panel on freetime. In admin panel is possible to edit existing pages and parts such as header, footer, link list, sidebar in text field where is code of page. But most important is missing: Creating new site, saving it wit given name by user in "name"-field and saving it to same directory where other sites are and as php file.


Here some images from this panel:

IMAGE 1: http://img707.images...716/nimeton.png

IMAGE 2: http://img213.images...nimetontoka.png


Really big and warm thank you for help :)/>

Is This A Good Question/Topic? 0
  • +

Replies To: "create new site" option for PHP admin panel

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3712
  • View blog
  • Posts: 5,963
  • Joined: 08-June 10

Re: "create new site" option for PHP admin panel

Posted 26 February 2013 - 01:26 PM

Hey.

So these pages are actual PHP pages, and your admin panel just alters the contents of the pages?

If so, then creating a new page would just be a matter of creating a new PHP file. You can do that by simply calling the file_put_contents function, passing the filename as the first parameter and the contents as the second parameter.
<?php
$filePath = "/path/to/where/the/pages/are/pageName.php";
$contents "<!DOCTYPE html><html>...</html>";

// You'd first want to make sure the page doesn't already exist!
if (file_exists($filePath)) {
    die("Page already exists!");
}

// And then you can just write it.
if (file_put_contents($filePath, $contents)) {
    echo "Success!";
}
else {
    echo "Failure!";
}


Was This Post Helpful? 0
  • +
  • -

#3 Vompaudi  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 23-November 12

Re: "create new site" option for PHP admin panel

Posted 27 February 2013 - 07:23 AM

But how is defined the text field for name?
Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3712
  • View blog
  • Posts: 5,963
  • Joined: 08-June 10

Re: "create new site" option for PHP admin panel

Posted 27 February 2013 - 08:28 AM

What do you mean? Are you asking how you can get the name from the user to the PHP code? That would just be your basic HTML form with an <input> field. Look through this tutorial if you need a refresher on that.
Was This Post Helpful? 0
  • +
  • -

#5 Vompaudi  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 23-November 12

Re: "create new site" option for PHP admin panel

Posted 27 February 2013 - 08:49 AM

No, in PHP code. I mean, when user types for name i.e. "testpage", and then saves, it will be saved as "testpage.php" to same directory with other sites.
Was This Post Helpful? 0
  • +
  • -

#6 Vompaudi  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 23-November 12

Re: "create new site" option for PHP admin panel

Posted 02 March 2013 - 04:02 AM

Still waiting the answer for my question...

There is the field where user gives name for page. It is the filename also.

http://img163.images...431/dfhfdfd.png

How do I "link" that text field to that PHP code, so code makes the name from it. And how saving in .php format?

Source of this page:

<?php

require_once("login.php");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title></title>

</head>

<body>
<div id="keskitys">

<div id="ylapalkki">
  <div align="center">
    <p><img src="../images/logo.png" width="519" height="180" /></p>
    <p>T&auml;ll&auml; sivulla voit luoda uuden sivun.</p>
  </div>
  <p class="perus">&nbsp;</p>
</div>

<div id="asia">
<div id="teksti">
  <form id="paivitys" name="update" method="post" action="confirmuusisivu.php">
  
 
    <p>
<input type="text" name="sitename" value="Name of site" maxlenght="30"size="50">
	<br><br>
      <textarea name="sisalto" cols="80" rows="10">
  <?php
 
readfile("../codeofblankpage.txt");							
					?>
  </textarea>
      </p>
    <p>
      <input name="valinta" type="hidden" value="">
      <br />
      <br />
      <input name="update" type="submit" id="update" value="Add site"/>
      </p>
  </form>
</div>
</div>
</div>
</body>
</html>

Was This Post Helpful? 0
  • +
  • -

#7 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3712
  • View blog
  • Posts: 5,963
  • Joined: 08-June 10

Re: "create new site" option for PHP admin panel

Posted 02 March 2013 - 04:09 AM

When you submit that form, PHP will receive your page name inside the $_POST["sitename"] element. In the example code I posted in my first reply there is a $filePath variable, containing the destination where your new page is supposed to be put. All that needs to happen for that path to use the user submitted file name instead of the hard-coded one is for you to replace the file name part of the path with the user supplied value.
Was This Post Helpful? 0
  • +
  • -

#8 Vompaudi  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 23-November 12

Re: "create new site" option for PHP admin panel

Posted 02 March 2013 - 04:54 AM

But I think it is impossible to make creating new site.

1. How to add the new page to admin panel for editing and adding content to it?
2. confirm page about succeeded edit.
Was This Post Helpful? 0
  • +
  • -

#9 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3712
  • View blog
  • Posts: 5,963
  • Joined: 08-June 10

Re: "create new site" option for PHP admin panel

Posted 02 March 2013 - 06:15 AM

No, it's far from impossible. Relatively speaking, in fact, it's a fairly easy thing to accomplish.

"1. How to add the new page to admin panel for editing and adding content to it?"
The admin panel shouldn't need to be altered in any way. It should be checking which pages actually exist on the hard drive and giving you the option to edit those.

To figure out which pages exist, look into the glob function, or the DirectoryIterator.

"2. confirm page about succeeded edit. "
What is the problem with this, exactly?
Was This Post Helpful? 0
  • +
  • -

#10 Vompaudi  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 23-November 12

Re: "create new site" option for PHP admin panel

Posted 02 March 2013 - 09:03 AM

Always when user press update button, it redirect to it's own confirm site. "Updating of front page succeeded" Maybe I change this text to appear under the button.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1