Hello, I have a config.php page located @ /home/account1/public_html/includes/config.php. config.php: <?php $page_break = ' - '; $page_slogan = 'Slogan'; ?> PHP: I need a php code that will make admin.php witch is password protected to change $page_break & $page_slogan? Thanks,
What exactly are you trying to do? You could just simply change the $page_slogan manually by accessing it via FTP or your file manager, and why use a page_break? HTML has <hr> that you can set the length, or you could just simple type '-' on your web page.
the page the needs all the information use's <?php $page_title = 'Home'; include 'includes/config.php'; ?> Content <?php include 'includes/footer.php'; ?> PHP: in config.php the title tag looks like <title><?php echo $page_title; ?><?php echo $page_break; ?><?php echo $page_slogan; ?></title> HTML: witch would echo somthing like <title>Home - Slogan</title> I need so i can log in to admin.php and there i can change $page_break & $page_slogan, ect...
Well, you need to store these values somewhere - preferably a database. If you don't have that, you need a lot more logic. What you need to do is create a form that sends the data input from the form into the database. If you don't have a database to play with, this is gonna be slightly more hasslesome, although you can rewrite the config-file each time you change stuff from the form (but again, this is a bad solution, and not something you want to do)
assuming that you submit the page_break and page_slogan via post .. you can use this code: <?php if(count($_POST) > 0) { $page_break = filter_input(INPUT_POST, 'page_break', FILTER_SANITIZE_STRING); $page_slogan = filter_input(INPUT_POST, 'page_slogan', FILTER_SANITIZE_STRING); $data = '<?php' . "\n"; $data .= '$page_break = \'' . $page_break . '\';' ."\n"; $data .= '$page_slogan = \'' . $page_slogan . '\';' ."\n"; $data .= '?>'; $fp = fopen('includes/config.php', 'w'); fwrite($fp, $data); fclose($fp); } ?> Code (markup): Don;t forget to make includes/config.php writable by web server. I hope that helps
Thanks that worked but when if using that i posted <script type="text/javascript"><!-- google_ad_client = "pub-3438406889490676"; google_ad_slot = "9467592827"; google_ad_width = 728; google_ad_height = 90; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> HTML: sent for $global_nav_728x90 it writes as <?php $global_nav_ad728x90 = ' '; ?> PHP: and if i make it on one line like <script type="text/javascript">google_ad_client = "pub-3438406889490676"; google_ad_slot = "9467592827"; google_ad_width = 728; google_ad_height = 90;</script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> HTML: it writes it as <?php $global_nav_ad728x90 = 'google_ad_client = "pub-3438406889490676"; google_ad_slot = "9467592827"; google_ad_width = 728; google_ad_height = 90; '; ?> HTML: so in case you need to see the code i'm using its: <?php if(count($_POST) > 0) { $global_nav_ad728x90 = filter_input(INPUT_POST, '$global_nav_ad728x90', FILTER_SANITIZE_STRING); $data = '<?php' . "\n"; $data .= '$global_nav_ad728x90 = \'' . $global_nav_ad728x90 . '\';' ."\n"; $data .= '?>'; $fp = fopen('includes/advertisement.php', 'w'); fwrite($fp, $data); fclose($fp); } ?> PHP: Thanks,
It is because of filtering the data... since you are not using it in database you can use it like this: $google = '<script type="text/javascript"><!-- google_ad_client = "pub-3438406889490676"; google_ad_slot = "9467592827"; google_ad_width = 728; google_ad_height = 90; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>'; $data = '<?php' . "\n"; $data .= '$global_nav_ad728x90 = \'' . $google . '\';' ."\n"; $data .= '?>'; $fp = fopen('includes/advertisement.php', 'w'); fwrite($fp, $data); fclose($fp); Code (markup): however this is not good practice because someone can inject code into the file and then access the file through the browser