PHP - Trouble Creating Active Links With Php And .inc Files
Hi Everyone,
I'm semi-new to php and trying to create a site where I have only one includes file for my navigation (main_nav.inc) and 2-3 includes files (main_template.inc) that act as templates. I then call the the nav and the template in my index.php file. Everything was working fine until I decided I should use php have my links appear active depending on which page the user is on. Everything works totally fine if I insert the code for my nav (including both the html and php) into my main_template.inc file but when I make that code into it's own includes file (main_nav.inc), I get an error. I believe the issue is with using both single and double quotes in my code and wrapping that code in single quotes in my main_nav.inc file. Here is the code from my main_nav.inc file: <?php $main_nav = ' <div id="mainNav"><ul id="mainNav"> <li><a href="index.php" <?php if ($page=='index.php') { ?> class="active" <?php } ?>>Welcome</a></li> <li><a href="healthcare.php" <?php if ($page=='healthcare.php') { ?> class="active" <?php } ?>>Healthcare</a></li> </ul></div> '; // end main_nav ?> I think that since the code is wrapped in single quotes, I can only use double quotes in my code. This is the only difference I can figure out between inserting the code into the template directly (which works perfectly fine) and inserting it as a separate inc file. When I use the main_nav.inc file I get the following error: Parse error: syntax error, unexpected T_STRING in /home/content/k/a/l/kalilaks3/html/includes/main_nav.inc on line 11 I tried changing the quotes around ($page=='index.php') to ($page=="index.php") but that causes the browser to literally read the name of the link a class="active">Welcome I also tried variations of escaping quotes such as ($page==\"index.php\") and even escaping the other quotes and wrapping everything in double quotes as opposed to single quotes. Here is my code for my main_template.inc file <?php $page = basename($_SERVER['SCRIPT_NAME']); $page_title = "Welcome"; include_once ("includes/main_nav.inc"); // sets variable include_once ("home_template.inc"); // sets all variables ?> And here is my index.php file: <!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 content="healthcare" name="keywords"></meta> <meta content="healthcare" name="description"></meta> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title><?php echo $page_title; ?></title> <link rel = "stylesheet" href = "_css/layout.css"></link> <script type="text/javascript" src="scripts/script.js"></script> </head> <body> <div id = "header"><div id = "globalHeader"> <?php echo $main_nav; ?> </div></div> </body> </html> Any help or suggestions would be greatly appreciated!!! I would love to get this figured out so that I only have to create my navigation once for all my sites! Similar TutorialsHello I need help with making our dropdown links stay visible when active. Site: London tshirt .com Code: [Select] <dl id="nav"> <dt class="nav"><b>London Tshirts</b></dt> <dd> <ul> <li><a href="/Unisex">Unisex</a></li> <li><a href="/Slimfit">Slimfit</a></li> <li><a href="/Kids">Kids</a></li> </ul> </dd> <dt class="nav"><b>Alternative Tshirts</b></dt> <dd> <ul class="nav"> <li><a href="/England">England</a></li> <li><a href="/Humour">Humour</a></li> <li><a href="/Popular">Popular</a></li> </ul> </dd> <dt class="nav"><b>Magnets</b></dt> <dd> <ul class="nav"> <li><a href="/magnets-ceramic">Ceramic</a></li> <li><a href="/magnets-metal">Metal</a></li> <li><a href="/magents-plastic">Plastic</a></li> </ul> </dd> <dt class="nav"><b>Keyrings</b></dt> <dd> <ul class="nav"> <li class="current"><a href="/keyrings-ceramic">Ceramic</a></li> <li class="current"><a href="/keyrings-metal">Metal</a></li> <li><a href="/keyrings-plastic">Plastic</a></li> </ul> </dd> <dt class="nav"><b>Other gifts</b></dt> <dd> <ul class="nav"> <li><a href="/Hats">Hats</a></li> <li><a href="/Models">Models</a></li> <li><a href="/Bags">Bags</a></li> </ul> </dd> </dl> Thanks P.S. I typed my question, then went to verification, but could not read the letters so requested a new image, this refreshed the page and I lost my message?? Hi All
I have a a directory website but numereous listings don't have their own website so they are requesting a single page to show a summary of their business and products.
I know how to do most of it the part I am unsure of is:
I have a form where they upload text, images, etc to a database and upload the images. what I would like to do is to save it as a file under a subdirectory. Is it possible to save a file php file using php
Thank you in advance
Lional
i am able to create csv's and can do so with no trouble .. but what i am having difficulty with is being able to auto save the csv and then email it all in one script. anybody every dealt with something like this? I have a script that will create a directory just fine but, I found a different script that I am trying to have it create a directory if necessary otherwise it will echo that the directory exists. As of right now I am just getting a 'Warning: mkdir() [function.mkdir]: File exists' My current code: Code: [Select] if (!file_exists($folder)) { mkdir ("../images/upload/upimg/$folder", 0777); mkdir ("../images/upload/thimg/$folder", 0777); }else { echo "Directory previously created, file uploaded successfully."; } Any help would be appreciated. I'm looking for any guidance on how to dynamically create css files. I want users to be able to select colors for fonts/backgrounds, borders, etc. from a form which they will submit and it will create a css file and put it in a certain folder. Can someone point me in the right direction? I am trying to create a gallery page, one photo on the page with Next/Previous links either above or below but am having a little local difficulty. This is what I have:- Code: [Select] //>>> Set up arrays and variables <<< $piccies = array(); $exif = array(); $exifdata = array(); $pic = 0; $img =''; $date = ''; $time = ''; $caption = ''; $copyright =''; $imageid = 1; $first = 1; $last = 5; $self = $_SERVER['PHP_SELF'] . "?imageid="; //>>> Read images from folder and assign to the array $piccies[] <<< $piccies = read_folder(); //>>> Find image and extract the Exif info <<< $exif = read_exif_info($piccies, $pic); //>> Populate with required info from $exifdata with required info from $exif $exifdata = populate_exif_data($exif, $date, $time); $img = substr_replace($img, "", 0, 2); ?> <div id="pict"> <img src="<?php echo $img; ?>" /> <?php echo "<p>" . $caption . "</p>"; if ($imageid < $last) { echo "<a href=" . $self . ($imageid + 1) . "><h2>Next</h2></a>"; } if ($imageid > $first) { echo "<a href=" . $self . ($imageid - 1) . "><h2>Previous</h2></a>"; } ?> </div> It puts the 'Next' link in fine, but when clicked the link goes to the Parent directory:- Index of /php/gallery [ICO] Name Last modified Size Description [DIR] Parent Directory - [ ] functions.php 27-Oct-2011 09:25 2.1K [ ] gallery index.php 27-Oct-2011 09:45 1.8K [DIR] images/ 26-Oct-2011 16:00 - and when I look at the source I see that the link has not been constructed as I expected. This is the source:- Code: [Select] <div id="pict"> <img src="images/blue sky.jpg" /> <p>Blue Sky over Auld Reekie</p><a href=/php/gallery test.php?imageid=2><h2>Next</h2></a></div> where '/php/gallery test.php' is showing I expected 'images/filename.jpg' etc. and I just can't figureout what I have done wrong... I need php code that creates pdf file with table inside. Hi. This is my first post, so feel free to lecture me on forum etiquette and conventions. I'm trying to create a form, several items of which are file upload <input>s. Here is the relevant code from the form. <label for="facefile">Filename:</label> <input type="file" name="facefile" id="facefile" /> This form has an action="validateform.php". In the file for validateform.php I can't seem to reference "facefile". I just try doing <?php echo($_FILES["facefile"]["name"]); ?> And I get Notice: Undefined index: facefile in validateform.php on line 1 The Issue (note: sorry for double post in the regex forum.) My users can post comments. I want to turn the hidden links within those comments into clickable URLs. I have the following function to do this: Code: [Select] if (!function_exists('create_link')) { function create_link($url) { $pattern = "#((http|https|ftp)://(\S*?\.\S*?))(\s|\;|\)|\]|\[|\{|\}|,|\"|'|:|\<|$|\.\s)#ie"; $link_title = character_limiter(preg_replace($pattern, "$3", $url), 50); $link = preg_replace($pattern, "'<a href=\"$1\" target=\"_blank\">{LINK_TITLE}</a>$4'", $url); if ($link == $url) { $url = 'http://' . $url; $link = preg_replace($pattern, "'<a href=\"$1\" target=\"_blank\">{LINK_TITLE}</a>$4'", $url); } if ($link != $url) { $result = str_replace('{LINK_TITLE}', $link_title, $link); } else { $result = FALSE; } return $result; } } I know that the regex is pretty bad. It kind of works, but makes every single thing with a period into a link, and messes up sometimes with target= portion where it will actually display that. I've tried a bunch of other regex's but every single one gives me problems, typically like "php unknown modifier ]" or ")" or something. here's how I call this function when users hit submit in the comment field: Code: [Select] $words = preg_split("/[\s,]+/", $comment); foreach ($words as $word) { if ($link = create_link($word)) { $comment = str_replace($word, $link, $comment); I just want to convert the right links into links. is something like: ^(((ht|f)tp(s?))\://)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$ any better? I don't know, nothing seems to work. Hi all. I work at a university library where I am the default web coding person. Although I know far more than anyone else who works here, my skills are not exactly at the guru level. At the moment I'm fighting with libcURL, trying to use a (secured) submission form to upload files from faculty to a remote server. (Of course, I had one that worked which uploaded to a safe directory on our web server, but that was deemed insufficient. ) I have managed to connect to the FTP server with cURL, and I have managed to create files on that server which have the same name as the files uploaded in the form. However, for some reason that escapes me, the files created on the FTP server are empty files. The server is using Server 2003 and IIS 6, and I am able to successfully upload to it using Filezilla, so I suspect the problem is with my code. I have searched Google for help with this, but all I can get is examples of how to upload which are the same as the one I already have, and how to delete a file using cURL, which is not what I want to do. The problem does seem to be somewhere in the file transfer process. die($_Files['syllabus']['size']); gives me the correct file size, and I tried moving the file onto the (local) webserver before transfering it via FTP, and the server one was fine--the FTPed version still showed up empty. If anybody has any idea what's going on, your help would be greatly appreciated. //the syllabus file from the form $syllabus=$_FILES['syllabus']['name']; //the syllabus as it will appear on the server (to make it a clickable link in the e-mail sent //to our processing librarian later in the script. Removing this did not fix the problem anyway.) $REMsyllabus = str_replace(' ', '-', $_FILES['syllabus']['name']); //formatted URL, with FTP information defined just before the syllabus and REMsyllabus files. $SYLremoteurl = "ftp://${ftpuser}:${ftppasswd}@${ftpserver}/${REMsyllabus}"; $ch = curl_init(); $fp = fopen($syllabus, 'r'); curl_setopt($ch, CURLOPT_URL, $SYLremoteurl); curl_setopt($ch, CURLOPT_UPLOAD, 1); curl_setopt($ch, CURLOPT_INFILE, $fp); curl_setopt($ch, CURLOPT_INFILESIZE, $_FILES['syllabus']['size']); curl_exec ($ch); $error_no = curl_errno($ch); curl_close ($ch); if ($error_no == 0) { $error = 'File uploaded succesfully.'; } //if else { $error = 'File upload error: '.$error_no; }//else } //if else { $error = 'No syllabus file selected.'; }//else This is pretty much the example code from the libcURL PHP section web page, so I'm not entirely sure why it doesn't work. Thanks in advance for any help anybody can offer! I am looking for some help with extracting links from log files, as it is a pain to do this manually (which I do right now). I basically have some log files which I need to check for ERROR messages and copy and paste the found URL's into another text file. My log file format looks like this: Code: [Select] INFO <11 Feb 2012 00:00:23,822> <index> <D2> <Processing URL : http://www.domain1.com/> INFO <11 Feb 2012 00:00:23,842> <index> <D4> <Indexed: http://www.domain2.com/> <Time:146 msecs> INFO <11 Feb 2012 00:00:23,842> <index> <D4> <Processing URL : http://www.domain3.com/> ERROR <11 Feb 2012 00:00:23,924> <index> <D1> <http://www.domain4.org/operas/2003-2004/mourning/composer.aspx: > org.apache.commons.httpclient.HttpRecoverableException: org.apache.commons.httpclient.HttpRecoverableException: Error in parsing at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1965) at org.apache.commons.httpclient.HttpMethodBase.processRequest(HttpMethodBase.java:2659) at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1093) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:674) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:529) at com.searchblox.scanner.http.HTTPScanner.b(Unknown Source) at com.searchblox.scanner.http.HTTPScanner.scan(Unknown Source) at com.searchblox.scanner.http.HTTPScanner.work(Unknown Source) at com.searchblox.scanner.Scanner.run(Unknown Source) at java.lang.Thread.run(Unknown Source) INFO <11 Feb 2012 00:00:23,968> <index> <D5> <Indexed: http://domain6.com/~cdobie/kearnsindex.htm> INFO <11 Feb 2012 00:00:23,968> <index> <D5> <Indexed: http://domain7.com/~cdobie/kearnsindex.htm> INFO <11 Feb 2012 00:00:32,988> <index> <D1> <Processing URL : http://www.domain8.com/> INFO <11 Feb 2012 00:00:33,072> <index> <D5> <Indexed: http://www.domain9.com/> <Time:128 msecs> INFO <11 Feb 2012 00:00:33,072> <index> <D5> <Processing URL : http://www.domain10.com/> ERROR <11 Feb 2012 00:00:33,116> <index> <D2> <http://www.domain11.com/: Connection timeout> org.apache.commons.httpclient.HttpConnection$ConnectionTimeoutException at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:736) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:661) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:529) at com.searchblox.scanner.http.HTTPScanner.b(Unknown Source) at com.searchblox.scanner.http.HTTPScanner.scan(Unknown Source) at com.searchblox.scanner.http.HTTPScanner.work(Unknown Source) at com.searchblox.scanner.Scanner.run(Unknown Source) at java.lang.Thread.run(Unknown Source) INFO <11 Feb 2012 00:00:33,154> <index> <D1> <Indexing http://www.domain12.com/ ...> INFO <11 Feb 2012 00:00:33,159> <index> <D1> <http://www.domain13.com/ - Last-Modified date: Sat Feb 11 00:00:33 CET 2012> ERROR <11 Feb 2012 00:00:33,207> <index> <D6> <http://www.domain14.com/: Connection timeout> Now what I am after is some piece of code which basically saves the http://domain.com/ part to a text file IF the line starts with ERROR. There are many different error reasons, so the strings are all different at the start and at the end, so maybe you know a way to open a log file, look out for the word ERROR at the beginning of a line and if that's the case, either save the whole line to another text file or if possible just the domain part (which would be even more great) If possible, please post a fully functional code block, as I am extremely bad with anything that has to do with regex, opening and closing files etc. Your help would be greatly appreciated I attached a sample log file to this post in case it helps (same as the lines above) Hello, I am completely new to php so please forgive me ahead of time. I am trying to create a link button on a website for a client that only directs to a certain external website on certain days and hours. Specifically, this is a web radio button that the client only wants to link to the web radio site when their live broadcast is on the air during certain hours on the weekend (i.e. Sundays 8-10 PM). Any other time, the client wants the web radio button to link to a default page since the web radio station plays unrelated music all other hours of the week. Does anyone know the best way to create such a time sensitive link for a button on a webpage? Thanks. Hi there I've been working with some code to display a single record on page. This all works fine and I'm able to pull what I want from the database. My problems is trying to use that data and turning it into something else like a link. I have a field in the database called image url which contains rows of image urls. So here is the problem area of the code: Code: [Select] <?php //////Displaying Data///////////// $id=$_GET['id']; // Collecting data from query string if(!is_numeric($id)){ // Checking data it is a number or not echo "Data Error"; exit; } $fetch=mysql_query("select * from productfeeds where ProductID=$id "); $row=mysql_fetch_object($fetch); echo mysql_error(); echo "<table>"; echo " <tr><td><b>ProductID</b></td><td>$row->ProductID</td></tr> <tr><td><b>ProductName</b></td><td>$row->ProductName</td></tr> <tr><td><b>ProductPrice</b></td><td>$row->ProductPrice</td></tr> //problem area for me <tr><td><b>Image</b></td><td>$row->ImageURL</td></tr> echo "</table>"; I'm trying to edit this part of the code: <tr><td><b>Image</b></td><td>$row->ImageURL</td></tr> I've tried this: <tr><td><b>Image</b></td><td><a href='{$row['URL']}'> <img src='{$row['ImageURL']}'></a> and <tr><td><b>Image</b></td><td><a href='$row['URL']'> <img src='$row['ImageURL']'></a> //removed brackets but I'm just getting errors. Can you guys help please? Thank you very much. Hi guys, I'm currently in the process of making a simple social networking type site for a uni project and have basically everything i want except the ability to use AJAX to link to my profiles in the search bar. I have this code to generate my XML: Code: [Select] <?php // create simplexml object $xml = new SimpleXMLElement('<rss version="2.0"></rss>'); // add channel information $xml->addChild('channel'); $xml->channel->addChild('title', 'The Social Network'); $xml->channel->addChild('link', 'http://reecesayer.com/projects/template/XML/news.rss'); $xml->channel->addChild('description', 'example'); // query database for article data include("phpfunctions.php"); db_connect(); $link = "www.reecesayer.com/projects/template/testprofile.php?id="; $select='SELECT email, id FROM users'; $result = mysql_query($select) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { // add item element for each article $item = $xml->channel->addChild('item'); $item->addChild('email', $row['email']); $item->addChild('link', $row['id']); //I wanted to add a link before the $row['id'] } // save the xml to a file $xml->asXML('profiles.xml'); header ('Location: http://reecesayer.com/projects/template/XML/profiles.xml'); ?> I need to add a partial URL (http://reecesayer.com/projects/template/testprofile.php?id=) before the row is called so that when the email is searched it provides a link to the profile depending upon the id (http://reecesayer.com/projects/template/testprofile.php?id=8) Is there an easier way to do this or am i going the long way around? I'm only storing the data in XML as i saw a tutorial for a livesearch script on another site. Cheers, Reece Hello I have a simple question about file handling... Is it possible to list all files in directories / subdirectories, and then read ALL files in those dirs, and put the content of their file into an array? Like this: array: [SomePath/test.php] = "All In this php file is being read by a new smart function!"; [SomePath/Weird/hello.txt = "Hello world. This is me and im just trying to get some help!";and so on, until no further files exists in that rootdir. All my attempts went totally crazy and none of them works... therefore i need to ask you for help. Do you have any ideas how to do this? If so, how can I be able to do it? Thanks in Advance, pros So far I have managed to create an upload process which uploads a picture, updates the database on file location and then tries to upload the db a 2nd time to update the Thumbnails file location (i tried updating the thumbnails location in one go and for some reason this causes failure) But the main problem is that it doesn't upload some files Here is my upload.php <?php include 'dbconnect.php'; $statusMsg = ''; $Title = $conn -> real_escape_string($_POST['Title']) ; $BodyText = $conn -> real_escape_string($_POST['ThreadBody']) ; // File upload path $targetDir = "upload/"; $fileName = basename($_FILES["file"]["name"]); $targetFilePath = $targetDir . $fileName; $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION); $Thumbnail = "upload/Thumbnails/'$fileName'"; if(isset($_POST["submit"]) && !empty($_FILES["file"]["name"])){ // Allow certain file formats $allowTypes = array('jpg','png','jpeg','gif','pdf', "webm", "mp4"); if(in_array($fileType, $allowTypes)){ // Upload file to server if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){ // Insert image file name into database $insert = $conn->query("INSERT into Threads (Title, ThreadBody, filename) VALUES ('$Title', '$BodyText', '$fileName')"); if($insert){ $statusMsg = "The file ".$fileName. " has been uploaded successfully."; $targetFilePathArg = escapeshellarg($targetFilePath); $output=null; $retval=null; //exec("convert $targetFilePathArg -resize 300x200 ./upload/Thumbnails/'$fileName'", $output, $retval); exec("convert $targetFilePathArg -resize 200x200 $Thumbnail", $output, $retval); echo "REturned with status $retval and output:\n" ; if ($retval == null) { echo "Retval is null\n" ; echo "Thumbnail equals $Thumbnail\n" ; } }else{ $statusMsg = "File upload failed, please try again."; } }else{ $statusMsg = "Sorry, there was an error uploading your file."; } }else{ $statusMsg = 'Sorry, only JPG, JPEG, PNG, GIF, mp4, webm & PDF files are allowed to upload.'; } }else{ $statusMsg = 'Please select a file to upload.'; } //Update SQL db by setting the thumbnail column to equal $Thumbnail $update = $conn->query("update Threads set thumbnail = '$Thumbnail' where filename = '$fileName'"); if($update){ $statusMsg = "Updated the thumbnail to sql correctly."; echo $statusMsg ; } else { echo "\n Failed to update Thumbnail. Thumbnail equals $Thumbnail" ; } // Display status message echo $statusMsg; ?> And this does work on most files however it is not working on a 9.9mb png fileĀ which is named "test.png" I tested on another 3.3 mb gif file and that failed too? For some reason it returns the following Updated the thumbnail to sql correctly.Updated the thumbnail to sql correctly. Whereas on the files it works on it returns REturned with status 0 and output: Retval is null Thumbnail equals upload/Thumbnails/'rainbow-trh-stache.gif' Failed to update Thumbnail. Thumbnail equals upload/Thumbnails/'rainbow-trh-stache.gif'The file rainbow-trh-stache.gif has been uploaded successfully. Any idea on why this is? <html> <?php $id = $_GET['id']; $dbusername="web148-matt"; $dbpassword="matt"; $dbdatabase="web148-matt"; mysql_connect(localhost,$dbusername,$dbpassword); @mysql_select_db($dbdatabase) or die( "Unable to select database"); mysql_query("UPDATE count SET clicks=clicks+1 WHERE id='$id'"); $sql = mysql_query("SELECT link FROM count WHERE id='$id'"); $fetch = mysql_fetch_row($sql); $result = mysql_query("SELECT * FROM count"); while($row = mysql_fetch_array($result)) { echo "<a href=" .$row['link']. ">Link</a>"; } ?> <a href='http://www.google.com'>Google</a> <a href='/index.php?id=2'>link2</a> </html> I am using WPSQT plugin in my blog site .I code some files in PHP also.how to add that files in plugin files.
Hello guys, before I start I'm a relativity new user of PHP so this really could be something extremely simple, I just can't seem to find it, Basically on my website i have php login script, when you're logged on every page you visit checks a file called auth.php, This will tell create a session called, "$SESSION" Inventive i know... That will tell the browser if the user is logged in or not, so it can decide whether or not to create a Login button, or a Log out button, Here's the code i have so far. if ( $SESSION == '' ) { echo "<a href='logout.php" ."Log out"; } else { echo "<a href='login-form.php" ."Log in"; } Now, I believe i'm on the right lines? But i'm not fully sure how to basically in English say, If that session is working or exists, Then do this, if not, do this. I mention again, I'm very new to PHP so any help would be very appreciated! |