PHP - Can I Use Request To Add Text To My Page From Url
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?
Similar TutorialsHi, suppose the user requests a page www.foo2.php. Now if it is a link embedded in another page, say www.foo1.php, then Javascript can send the server browser info before furnishing the page. But is it possible to let the server know which browser is being used when the user requests the page by just typing the url http://www.foo2.php and hitting enter? Hi everyone, I am making a screen scraper in php which scrapes the usernames from forum posts and stores them in an SQL database. I need some help with part of the preg_match code if possible please? The code and also the pseudo code I have so far is:(the pseudocode I am having trouble with but will try to solve my self if possible). Edit: sorry, editted the page as was confusing to read. Please ask for clarificaiton if there is anything I have failed to explain properly. thank you. //I will be placing the following php in the confirmation page people see after making a new post, so for this example lets say the referrer header says: http://www.mysite.com/showthread.php?tid=1' Code: [Select] $threadurl=$_SERVER['HTTP_REFERER']; // scrape the page Code: [Select] $content = file_get_contents($threadurl); // find the pattern in source which makes it easy to find the username- the only things that change are the uid and the color Code: [Select] if (preg_match("/\b uid=792"><span style="color:#ffcc00">fapafap</span></a>\b /i", $content)) { //extract username from this string search Don't know! //copy the username (in this case 'fapafap') to the database along with the referral ID Code: [Select] $query_insert="INSERT INTO newpostersdatabase(username,referrerurl) VALUES('$username','$threadurl')" ; $result=mysql_query ( $query_insert); if(!$result){ die(mysql_error()); } Thank you so much for any guidance, I know that I have totally messed up with the string search also but my brain is too small it seems! Hello, I need to execute a remote web page (distant server) every X seconds. How is it possible and is there any way to make it look exactly like a normal user request through a standard browser like Firefox, Chrome, etc. ? I've heard of cURL, but it seems that servers may block it, so there must be somehow a difference between a usual user request and a cURL execution. Thank you for any help ! :-) Matthew Doing something wrong, but don't see it. How should one retrieve a POST parameter? My $request->toArray()['html'] works, but I am sure it is not the "right way". <?php namespace App\DataPersister; use ApiPlatform\Core\DataPersister\DataPersisterInterface; use Symfony\Component\HttpFoundation\RequestStack; class ArchivePersister implements DataPersisterInterface { public function __construct(RequestStack $requestStack) { $request = $requestStack->getCurrentRequest(); syslog(LOG_ERR, '$request->getMethod(): '.$request->getMethod()); syslog(LOG_ERR, '$request->getContent(): '.$request->getContent()); syslog(LOG_ERR, '$request->request->get(html): '.$request->request->get('html')); syslog(LOG_ERR, '$request->query->get(html): '.$request->query->get('html')); syslog(LOG_ERR, '$request->get(html): '.$request->get('html')); syslog(LOG_ERR, '$request->toArray(): '.json_encode($request->toArray())); syslog(LOG_ERR, '$request->toArray()[html]: '.$request->toArray()['html']); } } output $request->getMethod(): POST $request->getContent(): {"project":"/projects/1","description":"","html":"<p>{{ project_name }}</p>"} $request->request->get(html): $request->query->get(html): $request->get(html): $request->toArray(): {"project":"\/projects\/1","description":"","html":"<p>{{ project_name }}<\/p>"} $request->toArray()[html]: <p>{{ project_name }}</p> 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. 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! 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? 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 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. 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; } ################################################## ?> 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
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, 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. How can I move my intro text shown in step 2 to the same place in step 1? 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. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=347332.0 Hello. I currently have a web page that allows a user to enter text into a form then select a "Submit Query" button; upon doing this the entered text is saved to a database and displayed for the user on the same page (the page where the form and "Submit Query" button are located). My question is as follows: I wish the results to be displayed on a new page when the "Submit Query" button is clicked, not displayed on the same page. Is this achieved through targeting? I am a bit lost at this point on how to achieve this result. Thank-you in advance for any help. ~Matty hi, can anyone please check my code it has an error Quote invalid content type for request: application/x-www-form-urlencoded Code: [Select] <?php $request = "<?xml version='1.0'?><request><br> <authentication><br> <username>username</username><br> <password>password</password><br> </authentication><br> <operation>getResellerProducts</operation><br> <params><br> <int>22</int><br> </params><br> </request></myXML> "; $url = "https://testapi.ssl.trustwave.com/3.0/"; // fake - obviosly! $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $request); // what to post curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $result = curl_exec($ch); curl_close($ch); print $result; ?> thanks! Hi Everyone First off I don't know PHP except the includes statement which I use regularly to make the site a little easier to update. But anyways am having an issue. I am trying to make a standard template page. On a prior site I had it set up this way with the code I will post below and it worked for me but I have tried to implement it on this site and am not having any luck. Few things on the code below. It was designed for another site. So what I need is as follows. The home page should bring up the default index.txt file. That has the home page info on it. Second the code below has a table in the coding as I required a table on my site so that is in the code but for this site don't need the table. There is also one image in the code. That too is no longer required. I will just leave these in place that way you can see the code I am working with so you can hopefully correct it to work for me as I am going nuts trying to get this to work. Also somewhere in the coding it seems maybe there is an open link tag as I did get this to work a little bit but for some reason when it was the TXT file information was also being made to be a link even though the txt file for time being only contains basic text no coding what so ever. Now what I need is as follows. Default home page TXT file loaded when home page loads. But the link below is what I was using for my site and when this was clicked it would load the TXT file for that page so the example link below would open up a members page that was associated with my message board I was using. Code: [Select] <a href="members.php?categories_file=Members">Forum Members Websites</a> that link would bring up file members.txt which was stored in the text folder Below is the code that in both cases was and is placed in the main window of the table I am using for layout. Last time this all worked perfectly but this time not sure why it refuses to load the page like it use to. Can anyways sort this code so it works fine for me. Thanks!! Dave Code: [Select] <?php if ($_GET['categories_file']) $fp = fopen("text/$categories_file.txt", "r") or die("Could not open $categories_file."); while (!feof($fp)) { $line = fgets($fp, 512); $categories[] = $line; } asort($categories) or die("Could not sort array."); $table_column_counter = 0; echo "<table border='0' cellpadding='0' cellspacing='0' width='90%'>"; foreach ($categories as $item) { if ($table_column_counter == 0) { echo "<tr>\r\n"; } $link = explode(",", $item); echo "<td><img src='images/green.gif' width='13' height='13'><a href='$link[1]' target='_blank'>".$link[0]."</a></td>"; if ($table_column_counter == 2) { echo "</tr>\r\n"; } $table_column_counter = $table_column_counter + 1; if ( $table_column_counter >= 2 ) { $table_column_counter = 0; } } ?> |