PHP - Hiding Text On A Page
Hi there,
Is it possible to hide text on a page using PHP? For example, hide the word "hello" every time it appears on the page? Or have it display in a different color? Similar TutorialsHi I want to hide the login box's of my webpage once you login. I have thought of two ways of doing it but which one would you say is better practice? 1. use a PHP if statement to echo 'Display: none on css' - when viewing source code it still shows the form but not displayed on page itself 2. use a PHP if statement around the whole <form></form> so it physically doesnt write the html if already logged in? Or if anyone has a better way it would be appreciated if you would share it? Thanks in advance Hi people, I really hope you guys can help me out today. I'm just a newbe at php and i'm having real trouble. Bassically all I want to do is have a user type in a company name in a html form. If what the user types in the form matches the company name in my php script i want the user to be sent to another page on my site. If what the user types in the form doesnt match the company name in my php script i want the user to be sent to a differnt page like an error page for example. this is my html form: Code: [Select] <form id="form1" name="form1" method="post" action="form_test.php"> <p>company name: <input type="text" name="company_name" id="company_name" /> </p> <p> <input type="submit" name="button" id="button" value="Submit" /> </p> </form> And this is the php code I'm trying to process the information on: Code: [Select] <?php $comp_name = abc; if(isset ($_POST["company_name"])){ if($_POST["company_name"] == $comp_name){ header("Location: http://www.hotmail.com"); exit(); } else{ header("Location: http://www.yahoo.com"); exit(); } } ?> The thing is i'm getting this error when i test it: Warning: Cannot modify header information - headers already sent by (output started at D:\Sites\killerphp.com\form_test.php:10) in D:\Sites\killerphp.com\form_test.php on line 17 Please can some one help me out, i'm sure this is just basic stuff but i just cant get it to work Cheers. Hi people! I have this code: if ($_POST['remember'] == true) { // COOKIES ON! $time = time() + 20000; setcookie(user, $username, $time); setcookie(pass, $password, $time); header("Location: index.php"); echo "<h1 class='welcome'>Welcome ".$_COOKIE['user']." |</h1>"; echo "<div id='divlogin' style='visibility:hidden'></div>"; echo "<a href='logout.php'><h1 class='logout'><b>Logout</b></h1></a>"; }elseif ($_POST['remember'] == false){ echo "<div id='divlogin' style='visibility:hidden'></div>"; echo "Div hidden!"; } "remember" - is a checkbox. So, if the checkbox is checked then I will activate the cookies and hide the divlogin (till now everything is fine), but if the checkbox isn't checked, I will just hide the divlogin (and this don't happen), however, the echo "Div hidden!" works nicely. The code detects if the checkbox is checked or not, the only problem is that if isn't checked the div doens't hide. Any ideas? Thanks Hi All, Bit of a strange one but i would like to be able to supply a URL to a page. This page will always contain an image and the copyright that goes with it for example http://www.geograph.org.uk/photo/693325 The copyright lies undearneath I would like to get some php code that would automatically grab the image and copy this to a directory on mt site and also take the creative commons copyright notice as a string ( which i will then display along side the image when i add it to my site) How can i do this through php I know that the word "copyright" only ever appears once on the page ( as part of the bit im trying to grab) so can i use this somehow to grab the whole string? Basically im being lazy and would like to automate the process of grabbing the image and copywrite without having to download it to my computer first and reload to my server ( as i will be doing this quite a lot) Any ideas much appreciated Thanks So I have a database with BLOBs (jpeg images). I also have a handy PHP page to display the image given an image ID. This page works fine, by getting the data, setting the content-type header to "image/jpeg", and echoing the data. Now here's the rub: I need the page to also display other information, in text / html format (i.e. show image, and below it show time the image was taken and other information also stored in the database. Because the content-type header has been set as "image/jpeg", I can't display this additional content. How can I make this work? Thanks! I'm normally fairly proficient with PHP, but I haven't done any coding in quite a while, so I'm a little rusty. I have an entire page of text from which I need to extract a single value. Here is a small portion of the page in question: Code: [Select] Total Rank: 128 Total Points: 4,978 Next Rank: 20 For instance, I need to extract the values "128" "4978" and "20" and store them in variables. These values change all the time, so I'm not sure what the best way to go about this is... maybe a regular expression ? If that's the case, I've never been too good with them, so any help would be appreciated. I currently have a mailing list that my boss uses, when he adds an email there is no 'sucess message' to let him know it has worked.
The mailing list just redirects back to the add subscribers page. I wondered if its possible to add a request so when he adds an email I can redirect the url to this:
?page=addemail&message=your email was added
and then echo $message where I want it to appear.
I have added $message = $_REQUEST['message']; to my page but nothing is happening. Can I not use request like this?
Hello, What if I wanted to publish a php program but want to hide the code so that even buyers would not get a look at it despite having the program fully functioning on their servers, is there a means through which I can hide the code so that it won't be shown even when the .php files are opened in a text editor? Hi! I have got an array which contains messages for different types of errors on my website (for login errors and such). My problem is however, that when the array is empty it still shows the message box (the CSS). here is the code I am using: Code: [Select] public function showMessages() { if (count($this->_messages > 0)) { echo '<div id="messages">'; foreach ($this->_messages as $msg) { echo $msg . '<br />'; } echo '</div>'; } } I am starting to think that I need to be doing this in JavaScript. I would prefer to do it using PHP only, if it is possible though. Thanks for the help! Hi all I have a website which has a payment system on it, I use sagepay, paypal and a few others. They all have relatively similar forms, in which the total amount to be paid is passed in a hidden form field, such as <input type="hidden" name="amount" value="25"> all the payment gateways I use have the same or similar method to send the total amount (ie: 25) for example, my paypal form is like <form action="https://www.paypal.com/cgi-bin/webscr" name="paypal_form" method="post">"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="item_name" value="items"> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="notify_url" value="complete.php"> <input type="hidden" name="return" value="complete.php"> <input type="hidden" name="cancel_return" value="complete.php"> <input type="submit" name="submit" value="PayPal" /> </form> this is all fine, apart from the user can use things like "firebug" to alter the total to be paid, so they can change $25 to $4 for example. So my question is, is there anyway with PHP to send over these form values are hidden variables. My idea was to post my form fields apart from the "cost" to a PHP script, then get PHP to grab the total from the database and dump the value in cost field and send it along with the other posted values. So really, is there anyway to get PHP to process a form data in a hidden enviroment, so my payment form URL is something like process.php and then process.php on my server deals with the sending of the paypal form data, but in a way that the user cannot see this data, so they basically never get to see the paypal form and any of its contents. Hopefully that kind of makes sense I have tried so many ideas, but cannot seem to find a solution, although when I do, hopefully the same method can be used on all my payment forms. Thanks tons in advance When I display my database entries, I want to hide some of the data. As you can see in this example: http://www.beat-the-spread.net/week1.php What I'd like to do is leave all the cells blank where the spread is zero. Here's the code I'm using: Code: [Select] while($row = mysql_fetch_array( $result )) { $i=1; if ($row['game_id']='$i') { echo "<tr><td>"; echo $row['date']; echo "</td><td>"; echo $row['team_name']; echo "</td><td>"; echo $row['owner']; echo "</td><td>"; echo $row['pt_spread']; echo "</td><td>"; echo $row['team_pts']; echo "</td><td>"; echo $row['team_bet']; echo "</td><td>"; echo $row['team_cover']; echo "</td><td>"; echo $row['owner_pts']; echo "</td></tr>"; if ($table_row_count % 2 && $table_row_count != 0) { echo ' <tr style="height: 8px"></tr> '; } $table_row_count++; } $i++; } echo "</table>"; I've been fooling with this for a couple hours and can't seem to find a decent way to do this. Can anybody help with this? Thanks. How can I move my intro text shown in step 2 to the same place in step 1? I am trying to force home landing page text onto this wordpress themes (weblizar Enigma) standard page (which doesnt seem to allow for this even with settings/reading/static/home page option selected wordpress settings)
The landing page just seems to be wigitised.
In a nutshell, I want to have a "page" of text on home page below banner slider and instead of "BLOG" and blog text. Hope this makes sense.
Not getting help from theme author and I have been pointed towards .phpfreaks
This is the website below....
http://www.cloudchasing.co.uk
Thankyou in advance guys
This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=347332.0 Hi, I have a lovely wordpress theme on my website. Unfortunately I can not get text or the home page itself into the landing page, is there any way to do this at all? I want to the home page text to sit under the
I have contacted the theme author with no help. I want the text to sit underneath the four image buttons (below banner slider)
This is the website http://www.cloudchasing.co.uk/
Hope this makes sense, many thanks for help in advance.
Karl
Hi, Wonder if someone could help with the problem below. Got a main page that includes a header, footer and a link to a database. I can get the two Includes to work but can't seem to display the database fields in the body of the page. What has me baffled is that it appears to be connecting to the database, (Opening the connection to the database server The connection worked. The link is: Resource id #3) but no text (see below for database text) is appearing on the screen. Yet I'm not getting a "page_not_found" message. I can go to the database in MYSQL console and query it successfully. Read and (hopefully) applied the section Debugging: A Beginner's Guide, but still can't see the problem. Any help greatly appreciated. Bren --------------------CODE FOR MAIN PAGE START------------------- <?php $page_name = $_REQUEST['name']; /*http://localhost/exemples/page.php?name=about_us*/ // Get the body of the page mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $sql = "SELECT * from pages WHERE name='$page_name'"; print "Opening the connection to the database server<br>"; $link = mysql_connect("localhost","root", ""); print "The connection worked. The link is: $link <br>"; /* --------------What is being selected from the database-------------- +----------+------------------------------------------------------------------------+ | name | body | +----------+------------------------------------------------------------------------+ | about_us | <h1>About Us</h1> ACME Toys has been established in 1850 to provide toys | to children all over the world +----------+------------------------------------------------------------------------+ 1 row in set (0.00 sec) ---------------------------------------------------------------------- */ $result = mysql_query($sql) or die(mysql_error() ); // If the page is not found, redirect to a static page if(mysql_num_rows($result) == 0 ) { header("Location: page_not_found.html"); } $row = mysql_fetch_assoc( $result ); $body = stripslashes( $row["body"] ); // Include the header include("c:/wamp/www/exemples/header.php"); // Print the body of the page echo $body; // Include the footer include("c:/wamp/www/exemples/footer.php"); ?> --------------------CODE FOR MAIN PAGE END------------------- I have a dynamic menu (jglidemenu) installed on my site. It works fine on my HTML pages but on my PHP pages the font formatting from the menu's style sheet isn't working and I haven't been able to figure out why. Here's a page where the menu is working correctly: http://www.greenbayeasthighschool.com and here's a page where the formatting fails: http://www.greenbayeasthighschool.com/staff_by_lastname.php This is my first attempt at creating a page with PHP. Is it not possible to use CSS formatting on a page that includes PHP content? Thanks in advance for any help. First and foremost, I am a PHP novice so, if there's better or more efficient way of doing what I'm trying to do, please feel free to point it out I came across an old PHP script that was used to crawl a site and check the response code on the pages found. I have modified it to do a duplicate content check. It's using the similar_text function to compare 1 page's content (specified by the user) against the content of each page it finds. It's a little slow but, its working. The only problem that I'm having is that it stops after about the first 10 links and I can't figure out why. Any help is greatly appreciated. Code: [Select] <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div class="row"><label for="page1" class="small label"><strong>Page? </strong>: </label><input type="text" name="page1" id="page1" value="" size="40" /></div> <div class="row"><label for="url" class="small label"><strong>Please Enter URL </strong>: </label><input type="text" name="url" id="url" value="" size="40" /></div> <div class="row"><label for="maxlinks" class="small label"><strong>Number of links to get </strong>: </label><input type="text" name="maxlinks" id="maxlinks" value="25" size="3" maxlength="3" /></div> <div class="row"><label for="linkdepth" class="small label"><strong>Links Maximum depth</strong> : </label> <select name="linkdepth" id="linkdepth" ><option value="1">1</option> <option value="2" selected="selected">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> </select></div> <input type="submit" name="submit" style="font-weight: bold" value="Check links" id="submit" /> </form> <?php if (isset($_POST['submit'])){ $page1 = ($_POST['page1']); $baseurl = ($_POST['url']); $pages = array(); $i=($_POST['linkdepth']); $maxlinks = (integer)$_POST['maxlinks']; $domain= extract_domain_name($baseurl); echo '<p class="small">Extracted domain name: <strong>'.$domain.'</strong>. '; echo 'Maximum depth: <strong>'.$i.'</strong></p>'; function get_urls($page){ global $domain, $i; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $page); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, true); /* Spoof the User-Agent header value; just to be safe */ curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'); /* I set timeout values for the connection and download because I don't want my script to get stuck downloading huge files or trying to connect to a nonresponsive server. These are optional. */ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 100); curl_setopt($ch, CURLOPT_TIMEOUT, 100); /* This ensures 404 Not Found (and similar) will be treated as errors */ curl_setopt($ch, CURLOPT_FAILONERROR, 0); /* Download the page */ $html = curl_exec($ch); /* in case of an error*/ if(curl_exec($ch) === false) { echo '<p class="small">Error. Please check URL: <strong style="color:#ae3100">' . curl_error($ch).'</p></strong>'; } curl_close($ch); if(!$html) return false; /* Extract the BASE tag (if present) for relative-to-absolute URL conversions later */ if(preg_match('/<base[\s]+href=\s*[\"\']?([^\'\" >]+)[\'\" >]/i',$html, $matches)){ $base_url=$matches[1]; echo $base_url; } else { $base_url=$page; //base url = strani4ka s kotoroy na4inaetsa novaja porverka } $links=array(); $html = str_replace("\n", ' ', $html); preg_match_all('/<a[\s]+[^>]*href\s*=\s*[\"\']?([^\'\" >]+)[\'\" >]/i', $html, $m); /* this regexp is a combination of numerous versions I saw online*/ foreach($m[1] as $url) { $url=trim($url); /* get rid of PHPSESSID, #linkname, & and javascript: */ $url=preg_replace( array('/([\?&]PHPSESSID=\w+)$/i','/(#[^\/]*)$/i', '/&/','/^(javascript:.*)/i'), array('','','&',''), $url); /* turn relative URLs into absolute URLs. relative2absolute() is defined further down below on this page. */ $url = relative2absolute($base_url, $url); // check if in the same (sub-)$domain if(preg_match("/^http[s]?:\/\/[^\/]*".str_replace('.', '\.', $domain)."/i", $url)) { $depth= substr_count($url, "/")-2 ; /* Counts slashes in URL Responsible for link depth */ if ($depth <= $i){ if(!in_array($url, $links, check)) $links[]=$url; } } } return $links; } // Functions to crawl the next page function next_page(){ global $pages; $k=0; foreach( array_keys($pages) as $k=> $page){ if($pages[$page] == NULL){ $k++; echo "[$k] - "; return $page; } } return NULL; } function add_urls($page){ // ads new unique urls in to array and checks each url for Server Header Status global $pages, $maxlinks; $start = microtime(); $urls = get_urls($page); $resptime = microtime() - $start; // with microtime it is possible to find out on which page the crowler stops responding. //Start checking for Server Header $ch = curl_init($page); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Execute curl_exec($ch); $info = curl_getinfo($ch); print "$page"; // If the status code os 200, then print OK, else = NO // if($info['http_code']==200) { $page1 = ($_POST['page1']); $page1data = file_get_contents($page1); $page2 = file_get_contents($page); $i = similar_text($page1data, $page2, $p); $p = round($p, 2); echo ' - Match Percentage:' . $p . '%'; // } else { // echo '<strong style="color:#ba3d00"> NO </strong>';} /* echo substr(($resptime),0,5). " seconds"; */ // Activate ths to see how much time it takes to crawl echo '<br/>'; curl_close($ch); // Close handle $pages[$page] = array ('resptime' => floor($resptime * 9000), 'url' => $page); foreach($urls as $url){ if(!array_key_exists($url, $pages) && !in_array($url, $pages) && count($pages)<$maxlinks){ $pages[$url] = NULL; } } } echo '[1] - '; // this is for the first input url, as it will be extracted from input add_urls($baseurl); while(($page= next_page()) != NULL ) //while there are urls available { add_urls($page); } echo '<p class="small">Amount of crawled links: <strong>'.count ($pages).'</strong></p>'; if (count($pages)<$maxlinks) echo '<p class="small">Sorry, no more links to crawl!!</p>';// count all extracted Urls } ?><?php function extract_domain_name($url){ /* old domain extractor if(preg_match('@^(?:http:\/\/)?([^\/]+)@i', $url, $matches)) { return trim(strtolower($matches[1])); } else { return ''; }*/ preg_match("/^(http:\/\/)?([^\/]+)/i", $url, $matches); $host = $matches[2]; // get last two segments of host name preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches); return $matches[0]; } function relative2absolute($absolute, $relative) { $p = parse_url($relative); if($p["scheme"])return $relative; extract(parse_url($absolute)); $path = dirname($path); if($relative{0} == '/') { $newPath = array_filter(explode("/", $relative)); } else { $aparts = array_filter(explode("/", $path)); $rparts = array_filter(explode("/", $relative)); $cparts = array_merge($aparts, $rparts); $k = 0; $newPath = array(); foreach($cparts as $i => $part) { if($part == '..') { $k = $k - 1; $newPath[$k] = null; } else { $newPath[$k] = $cparts[$i]; $k = $k + 1; } } $newPath = array_filter($newPath); } $path = implode("/", $newPath); $url = ""; if($scheme) { $url = "$scheme://"; } if($user) { $url .= "$user"; if($pass) { $url .= ":$pass"; } $url .= "@"; } if($host) { $url .= "$host/"; } $url .= $path; return $url; } ################################################## ?> Hi, I want to show part of the text from a page containing my article on my main page. The article resides in a database in mysql. How do I limit the amount of text that is shown without setting up a separate excerpt box for the article. I want to then provide a link so the user can go to another page that displays the entire article. Thanks for any suggestions. Hi I am trying to hide the image filepath and found this tutorial http://www.bounmis.com/en/PHP/How_To_Hide_Image_Source.html which I am currently using. It works but I need an additional security here so this script parses images only if the user is logged in to wordpress here's what i have so far: <?php include('wp-config.php'); $wp->init(); $wp->parse_request(); $wp->query_posts(); $wp->register_globals(); Header('Content-type: image/jpeg'); $exp=GMDate('D, d M Y H:i:s',time()+999); Header('Expires: $exp GMT'); $image_path = 'pathtoimages/'; $file=$image_path . $_GET["img"]; // getting image name and your image path if ( is_user_logged_in() ) { $file=$image_path.'authorized.jpg'; } else { $file=$image_path.'notauthorized.jpg'; }; if (file_exists($file)){ $info=getimagesize($file); $width=$info[0]; $height=$info[1]; if ($info[2]==1){ $img=@imagecreatefromgif($file); } else if ($info[2]==2){ $img=@imagecreatefromjpeg($file); } else if ($info[2]==3){ $img=@imagecreatefrompng($file); } else { $width=800; $height=600; $file = 'notauthorized.jpg'; // if there is not such image, it will show default image $img=@imagecreatefrompng($file); } ImageJpeg($img); imagedestroy($img); } ?> the script doesnt work. I think it's because i set headers Header('Content-type: image/jpeg'); What can I do to make it work? Please help thanks |