PHP - Including The Header.php File When Using A Sub Folder
The root directory:
header.php
stylesheet.css
In the following example I am trying to include the header.php file in a sub folder.
When I include the header.php like in the following example then the stylesheet.css file will not work anymo
<?php include("../header.php"); ?>The stylesheet.css file is included in the head tags of the header.php file. Is the above example the right way to do it? If yes, how can I do it so the stylesheet.css file will work too. Similar Tutorialsprobably another overly-newbie-ish question, but I built a series of pages for inputting data. Page 1 inputs data to table 1, pulls the item id and passes it to page 2 to input to table 2. This all works fine. But now I want to add a header and footer to include the site design. And when I add my <? include("header.php"); ?>, it stops working. I tried naming the header something else, in case it was just a duplicate name somewhere, but the problem is still there. When i submit, it goes to the next page and generates this error: Warning: Cannot modify header information - headers already sent by (output started at header.php:62) in file.php on line 65 Is there a way to include a header without it creating this issue? Or do I put it lower down in the code? Here's the main idea of the code: Code: [Select] if (isset($_POST['submitted'])) { $errors = array(); $descriptor1 = trim($_POST['plant_id']); $descriptor2 = trim($_POST['existence_status']); $descriptor3 = etc. etc. if (empty($errors)) { require ('connection.php'); $query = "INSERT INTO habits (plant_id, existence_status, reproduction_methods, etc.) VALUES ('$descriptor1', '$descriptor2', etc.)"; $result = @mysql_query ($query); $plant_id=mysql_insert_id(); header ("Location: thisfile.php?var1=$plant_id"); and, if it helps any, here's the header file: Code: [Select] <div id="ugg" style="background-color:#CDE472; height:80px; padding:10px;"> <h1>Twigzy</h1> </div> <style type="text/css" media="screen"> /**************** menu coding *****************/ #menu { width: 100%; background: #eee; float: left; } #menu ul { list-style: none; margin: 0; padding: 0; width: 12em; float: left; } #menu a, #menu h2 { font: bold 11px/16px arial, helvetica, sans-serif; display: block; border-width: 1px; border-style: solid; border-color: #ccc #888 #555 #bbb; margin: 0; padding: 2px 3px; } #menu h2 { color: #fff; background: #324F17; text-transform: uppercase; } #menu a { color: #000; background: #efefef; text-decoration: none; } #menu a:hover { color: #a00; background: #fff; } #menu li {position: relative;} #menu ul ul { position: absolute; z-index: 500; } #menu ul ul ul { position: absolute; top: 0; left: 100%; } div#menu ul ul, div#menu ul li:hover ul ul, div#menu ul ul li:hover ul ul {display: none;} div#menu ul li:hover ul, div#menu ul ul li:hover ul, div#menu ul ul ul li:hover ul {display: block;} </style> <!--[if IE]> <style type="text/css" media="screen"> #menu ul li {float: left; width: 100%;} </style> <![endif]--> <!--[if lt IE 7]> <style type="text/css" media="screen"> body { behavior: url(csshover.htc); font-size: 100%; } #menu ul li a {height: 1%;} #menu a, #menu h2 { font: bold 0.7em/1.4em arial, helvetica, sans-serif; } </style> <![endif]--> <!-- start menu HTML --> <div id="menu"> <ul> <li><a href="link"">Home</a> </li> </ul> <ul> <li><h2>About</h2> <ul> <li><a href="link0.com">About site</a> </li> </ul> </li> </ul> <ul> <li><h2>Search for a plant</h2> <ul> <li><a href="link1.php">Basic Search</a></li> <li><a href="link2.php">Search by Leaf</a></li> <li><a href="link3.php">Search by Flower</a></ul> </li> </ul> <ul> <li><h2>Login</h2> <ul> <li><a href="link4.php">Login</a></li> <li><a href="asdf.html">asdfasdf</a><!-- fully working sample --> <ul> <li><a href="test.html">asdf</a> </li> </ul> </li> </ul> </li> </ul> </div> How can i find out parent (including) file of included file? Lets imagine that we want to for example auto_prepend file to each file on our server that would write out the name of file its being executed. I know, i can use PHP_SELF but what if i want to write name of file which is already included? I have a web page and i want on it show its name even if it was included, but not the included page itself is showing name but auto_prepend file to each php file, its duty of this auto_prepend_file to write it out i dont want myself to echo it on each page? do you feel me? Hi everyone.... I have a simple search.php And I want to include that in my html output page. I tried using <?php include ('search.php'); ?> Below is my HTML code which is part of a php file...what am I doing wrong here? Code: [Select] // Final Output echo <<<__HTML_END <html> <head> <title>Photography</title> </head> <body> <table width='100%' border='0' align='center' style='width: 100%;'> $result_final <?php include("search.php");?> </table> </body> </html> __HTML_END; how to get the name of the file including a file from the included file, This one has me mixed up a bit.. I am trying to record site activity information from a common.php file using a user object. But since the file is included into different php files based on different situations I need a dynamic way of finding the file name that is including it. I could be over complicating things but right now this seems like the best solution other wise I'll have to rewrite the code on every page i write. Is there a function for doing this? Or if someone gets what I'm trying to do if they could point me to the direction of some more information on it. Thanks. I have a page using forms to help build listing templates for eBay. I have a folder where I have hundreds of logos stored. I know the logo names but not their extensions. . . . I have to test each potential (jpg, jpeg, gif, png, etc.) until I guess right. Here is an example code for the web form:
<form action="extension_test2.php" method="post"> <p>Logo: <input name="e" value="" type="text" size="15" maxlength="30" /><p> <input name="Submit" type="Submit"/> </form> and the form's result: <? $e =$_POST['e']; if(!empty($e)) { echo '<img src="http://www.gbamedica...ebayimg/logos/'.$e.'">'; }; ?> Here is a link to the example: http://www.gbamedica...ension_test.php Use "olympus.jpg" for test. I am looking for code that can determine the file type and dynamically add the extension. Can it be done? See if I can explain this right.
I am currently using static files for a very basic set of pages.
Right now i have a main file that has three includes. a header include, body and footer.
Due to needing to add pages, i don't want to keep adding more and more files. instead I want to use php to change one of the includes based on the url.
so thissite.com/index.php?lesson1 would change this
<?php include("header.php"); ?> <?php include("content-lessons.html"); ?> <?php include("footer.php"); ?>to this <?php include("header.php"); ?> <?php include("lesson1.html"); ?> <?php include("footer.php"); ?>or whichever way would be the best way to set the second include. my guess was that if the second line had something like this? if(isset($_GET['lesson1'])){ include('include/in-'.$_GET['lesson1.html']can someone give me a starting place here? i am pretty sure i can pick ti up if someone gets me going in the right direction. thanks a ton. Edited by story97, 12 January 2015 - 09:03 PM. I don't know if this relevant to php or css in my template folder I have file named (index.template.php). It contains this code <?php echo '<!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="Keywords" content="BHL-SimpleTool Content Manager System" /> <meta name="Author" content="BHL-SimpleTool is coded by Othman A. Taha" /> <meta name="Description" content="Site Powered by BHL-SimpleTool CMS" /> <title>BHL-SimpleTool v1.0 - Alpha</title> <link rel="stylesheet" href="themes/default/style.css" media="all" type="text/css" /> <link rel="stylesheet" href="themes/default/forms/forms.css" media="all" type="text/css" /> <link rel="stylesheet" href="modules/forum/Themes/default/style.css" type="text/css" /> <link rel="stylesheet" href="inc/jq/css/style.css" type="text/css" /> <script language="javascript" type="text/javascript" src="js/bbcodes.js"></script> <script language="javascript" type="text/javascript" src="js/smileys.js"></script> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/easySlider1.5.js"></script> </head> <body> <div id="wrapper"> my website run here </div> </body> </html>'; ?> It works fine( I made the top-margin to be 0px). But when I include index.template.php in my main (index.php) the top margin show a big margin from the top Note: I included (index.template.php) in my main (index.php) like this: <?php function __autoload($class_name) { require_once 'classes/Sessions' . '.php'; } $sessInfo = new Sessions(); $sessInfo->RunAllBhlSimpeToolStuff(); ?> Or is it all pieced together into one file then executed? I ask because I'm thinking of a weird way to handle errors on my site that would integrate with the interface smoothly without much work on my part. Every page on my site requires template_top.php at the start of the script and template_bottom.php at the bottom. I believe this is a pretty common thing to do, and it standardizes all my menus and interfaces and whatever else, plus it gives me a nice place to deliver messages to the user. What I want to do is something like this simplified example: template_top.php: <?php // layout stuff here try { ?> index.php: <?php require_once('template_top.php'); // a wild error appears! throw new Exception('oh no!'); require_once('template_bottom.php'); ?> template_bottom.php: <?php } catch (Exception $e) { echo 'An error occured! Message: ' . $e->getMessage(); } // layout stuff here ?> So that's where my question comes in. Both template files contain code that, if executed on it's own, is invalid. Pieced together in my pages though, it forms correct code. I'd really like to do this since all I'd have to do if my script encounters a problem is throw an Exception and everything is instantly handled without me having to fight with display issues. If this isn't possible, does anybody have any better suggestions? Suppose, i have created a sub.domain.com and i want to include a file 'config.php' from root directory i.e domain.com . While i tried include("../config.php"); i wasn't successful. Anyone can help me please?? I need the solution very urgently, so please help me soon. pracasify@yahoo.com facebook.com/agptj Hi, I have a form where a user selects a file to attach to the email. At the moment when you select a file it uploads from the user device. How do i change this so that a user can attach a file from a folder on the server. For example the folder name is uploadinvoice so when the user selects the browse button to attach a file it opens up the uploadinvoice folder on the server so the user can select the file from there ?
Thanks
coding i have at moment function ValidateEmail($email) { $pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i'; return preg_match($pattern, $email); } if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['formid']) && $_POST['formid'] == 'form1') { $mailto = $_POST['youremail']; $mailfrom = isset($_POST['myemail']) ? $_POST['myemail'] : $mailto; $subject = 'Message'; $message = 'Message'; $success_url = './test.php'; $error_url = ''; $eol = "\n"; $error = ''; $internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha_code", "recaptcha_challenge_field", "recaptcha_response_field", "g-recaptcha-response"); $boundary = md5(uniqid(time())); $header = 'From: '.$mailfrom.$eol; $header .= 'Reply-To: '.$mailfrom.$eol; $header .= 'MIME-Version: 1.0'.$eol; $header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol; $header .= 'X-Mailer: PHP v'.phpversion().$eol; try { if (!ValidateEmail($mailfrom)) { $error .= "The specified email address (" . $mailfrom . ") is invalid!\n<br>"; throw new Exception($error); } $message .= $eol; foreach ($_POST as $key => $value) { if (!in_array(strtolower($key), $internalfields)) { if (!is_array($value)) { $message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol; } else { $message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol; } } } $body = 'This is a multi-part message in MIME format.'.$eol.$eol; $body .= '--'.$boundary.$eol; $body .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol; $body .= 'Content-Transfer-Encoding: 8bit'.$eol; $body .= $eol.stripslashes($message).$eol; if (!empty($_FILES)) { foreach ($_FILES as $key => $value) { if ($_FILES[$key]['error'] == 0) { $body .= '--'.$boundary.$eol; $body .= 'Content-Type: '.$_FILES[$key]['type'].'; name='.$_FILES[$key]['name'].$eol; $body .= 'Content-Transfer-Encoding: base64'.$eol; $body .= 'Content-Disposition: attachment; filename='.$_FILES[$key]['name'].$eol; $body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES[$key]['tmp_name']))).$eol; } } } $body .= '--'.$boundary.'--'.$eol; if ($mailto != '') { mail($mailto, $subject, $body, $header); } header('Location: '.$success_url); } catch (Exception $e) { $errorcode = file_get_contents($error_url); $replace = "##error##"; $errorcode = str_replace($replace, $e->getMessage(), $errorcode); echo $errorcode; } exit;
} Hello all, i am go9090go. Today i made a domains for a jar file people can upload from my website. I made this to make the jar file close source and its easy to update. Now i made a java classloader and everything i made works. The classloader call a php document with the password and username. The pass and name will be checked inside a databse and if its inside i use header() to load the jar file. But when i just go to my main domain i get the index of the site and people can easly download the jar file without have to walk thru the php pass checker. So i want to place the jar file inside a protected folder,and i want that only way you get acces to this jar is by the php file. How can i get a file from a protected folder? here is the php used when the jar file is not inside a protected folder: <?php $DBName = "name";//name database $DBUser = "name";//user $DBPassword = "pass"; //passs $DBHost = "host"; //might be different mysql_connect($DBHost, $DBUser, $DBPassword); mysql_select_db($DBName); $username = $_GET['username']; $password = $_GET['password']; $IP = $_SERVER['REMOTE_ADDR']; $string = "Java"; $pos = strpos($agent, $string); if (!strpos($_SERVER['HTTP_USER_AGENT'], "Java")) { echo("Your Auth has been banned for trying to breach security."); //mysql_query("delete from users where username='$username'"); exit(); } $query = "select * from users where name='$username' and pass='$password'"; mysql_query($query); $num = mysql_affected_rows(); if ($num > 0) { header('Location:script/Script.jar'); } ?> now i want to use the header to a file inside a folder that is protected : so how can i make the header() methode to open script.jar inside a protected folder. The folder haves name and pass: blabla,balbla for exempel thanks for help if (!file_exists('../images/flags/imNum.txt')) { $file1 = fopen('../images/flags/imNum.txt','c'); fclose($file1); } why won't that work =\ it makes no sense to me Hi all, i want to download a file from the server but instead of storing it in the downloads i want it to store it directly in the folder i want and i also dont want to show any download window that appears while we download any file. Friend please help..... Hello, I'm trying to have my index.php to open/run another test.php file. I'm having my own server that I play with, that I run Ubuntu on. So the index.php are located at /var/www/ directory, but I want to run a file that are located at /testing/test.php The final test.php is file for showing pictures, and I don't want to out all the pictures under the /var/www/ location. It's alot of photos. I don't know much about php but I have been trying this: <?php header("Location: /var/www/testing/test.php"); //These below are desperat old tries. //header("Location: ./testing/test.php"); //header("Location: ../testing/test.php"); //$handle = fopen("/privat/Web_pictures/test.php", "r"); //"/testing/test.php" // header("Location: ./test.php"); //This one actually works, but I'm still in the wrong folder (/var/www/) echo "test "; // NN4 requires that we output something... exit(); ?> Thankful for help! This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=308625.0 I upload an image and put every information inside $_SESSION['tmp'] and $_SESSION['path'] then once user click on button then i use move_uploaded_file($_SESSION['tmp'],$_SESSION['path']) but file uploaded not appeared in my upload folder, and again i try to echo everything but all information still kept well in $_SESSION is there something missing here? thanks When I use require('../config.php'); It does not works on my machine but it works on shared hosting Can someone help me what must be the issue? Thanks in advance CSJakharia I'm trying to extract the contents of a zip file to a folder. I found the ZipArchive class and followed the examples to get it to work for the most part. But I want to extract the files in the folder inside the zip file but leave the folder out. So it should extract just the files to my given destination. I found this on php.net. Code: [Select] If you want to copy one file at a time and remove the folder name that is stored in the ZIP file, so you don't have to create directories from the ZIP itself, then use this snippet (basically collapses the ZIP file into one Folder). <?php $path = 'zipfile.zip' $zip = new ZipArchive; if ($zip->open($path) === true) { for($i = 0; $i < $zip->numFiles; $i++) { $filename = $zip->getNameIndex($i); $fileinfo = pathinfo($filename); copy("zip://".$path."#".$filename, "/your/new/destination/".$fileinfo['basename']); } $zip->close(); } ?> For some reason that 'copy' line is not working for me. Obviosly I've changed the variables in the line to the correct variables. Can someone help me out. Thanks Mike Hi everyone, I'm still learning, but getting intermediate in PHP now, but it is still challenge to learn. I'm trying to have php check to see if one file inside folder in server, seem I could not get it right, but I tested it on other site, it works, but not this script, I don't understand why it won't work...maybe logical is wrong? here my code: if ($_POST['video']) { $path1 = "UPLOADS/Home/"; $path2 = "UPLOADS/Breakfast/"; $path3 = "UPLOADS/Spider/"; $scan1 = scandir($path1); $scan2 = scandir($path2); $scan3 = scandir($path3); $count1 = count($scan1) - 3; $count2 = count($scan2) - 3; $count3 = count($scan3) - 3; if($count1 > 0) { header('location:exist.html'); }elseif ($count2 > 0) { header('location:exist.html'); }elseif ($count3 > 0) { header('location:exist.html'); } But other site, it works: $scan = scandir($path); $count = count($scan) - 3; echo $count; if($count > 1){ echo "Hello yourself!<br />"; } Anyone will help will be appreciate! Thank you! Gary Edited April 3, 2019 by sigmahokiesHey, i need help storing an image in my database via the URL(image location) at the moment my php code is storing the image in a folder on the directory called upload. here is the code: <?php // Where the file is going to be placed $target_path = "upload /"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $target_path = "upload/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> Click <a href="products.php">HERE</a> to go back to form if someone could help me i'd be very grateful |