Jump to content

young_coder

Members
  • Posts

    27
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

young_coder's Achievements

Member

Member (2/5)

0

Reputation

  1. maybe someone will find it useful it can be done by adding following code to the theme's 404.php page <?php header("HTTP/1.1 301 Moved Permanently"); header("Location: ".dirname($_SERVER['REQUEST_URI']).'/'); exit(); ?>
  2. Hello guys, There are some Wordpress plugins for permanent redirection of all 404's to the main blog URL (plugin '404 Redirection') or all 404's to one specified page (plugin '404-to-start'). Also, it can be done by adding following code to the theme's 404.php page. <?php header("HTTP/1.1 301 Moved Permanently"); header("Location: ".get_bloginfo('url')); exit(); ?> I need to redirect all 404's from one directory to index page of that directory. Does anybody know how this can be done? Thank you!
  3. I’m sorry, but I am bad with PHP and I do not understand where to make changes
  4. Please, can somebody help me with this script? This redirect script takes the number from the end of link and assigns to URL from array. Number 1 is second element (yahoo), number 2 is third element (google) etc. I would like to change number at the end of URL with keyword and put pairs in array like: array ( "yahoo" => "http://yahoo.com", "google" => "http:// google.com" ); So, when somebody come on page via URL "domain.com/?mn=yahoo" I would like to redirected him to http://yahoo.com. <?php //Standalone CPA Redirector v2.1 with multioffers //Settings http://dexony.com/insurance2/?mn=google //put in your desired offers in the array below , you can add as many as you want , but make sure to enclose them with "" // to match the desired domain you wonna link to , set the magicnumber to the position in the array below // to use your desired offer use http://www.yourdomain.com/?mn=offernumber $offers = array ( "", // must be empty "http://www.yahoo.com/", // ?mn=1 "http://www.google.com/" // ?mn=2 ); //you can specify a safenumber here, what it does it sets the magicnumber of the offer you would like + it's value //you normally don't need this, but if you don't want your magic numbers to start at 1 you can change it here // example if you set this to 50 and you want to use your first number it would be index.php?mn=51 $safemode = 0; //Don't edit below this line unless you know what you are doing. $PHP_SELF = preg_replace( "/index.php/", "", $_SERVER['PHP_SELF'] ); if (isset($_GET['mn'])) { $magic_number = $_GET['mn'] - $safemode; $cpa_offer_url = $offers[$magic_number]; setcookie("mnval",$magic_number,time()+10,"/"); setcookie("cpaval",$cpa_offer_url,time()+10,"/"); echo '<html><head><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"></head><body><form action="' . 'http://'.$_SERVER['HTTP_HOST'].$PHP_SELF. '" method="post" id="form1"> <input type="hidden" name="mn" value="' . $magic_number . '" /></form> <script language="JavaScript"> document.getElementById(\'form1\').submit();</script></body></html>'; return true; exit(); } if (($_POST['mn']== $_COOKIE['mnval']) && (isset($_COOKIE['mnval']))) { $magic_number = $_COOKIE['mnval']; echo '<html><head><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"></head><body><form action="' . 'http://'.$_SERVER['HTTP_HOST'].$PHP_SELF. '" method="post" id="form1"> <input type="hidden" name="mn" value="' . $magic_number . $magic_number . '" /></form> <script language="JavaScript"> document.getElementById(\'form1\').submit();</script></body></html>'; return true; exit(); } $dom = preg_replace( "/^www\./", "", $_SERVER[ 'HTTP_HOST' ] ) ; $ref= $_SERVER['HTTP_REFERER']; if (((strpos($ref, $dom)!=FALSE) || (trim($ref)=="" ) ) && (!isset($_GET['mn'])) && ($_POST['mn']==$_COOKIE['mnval'].$_COOKIE['mnval']) && (isset($_COOKIE['mnval']))){ $cpa_offer_url = $_COOKIE['cpaval']; header( 'Location: ' . $cpa_offer_url); exit(); setcookie("mnval","",time()-60); setcookie("cpaval","",time()-60); } ?> <html> <head> <title>your fake landing page</title> </head> <body> <br><br><br><br> <center><h1>text</h1></center> </body> </html>
  5. Here's a script I found http://www.mwasif.com/2007/4/save-image-in-mysql-with-php/
  6. Dear all, I have a problem that I need to be helped with using one form and storing the images in database. I would like to upload multiple images with same title from "title" field. Can somebody help me with this? <?php $db_host = 'localhost'; // don't forget to change $db_user = 'mysql-user'; $db_pwd = 'mysql-password'; $database = 'test'; $table = 'ae_gallery'; // use the same name as SQL table $password = '123'; // simple upload restriction, // to disallow uploading to everyone if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); // This function makes usage of // $_GET, $_POST, etc... variables // completly safe in SQL queries function sql_safe($s) { if (get_magic_quotes_gpc()) $s = stripslashes($s); return mysql_real_escape_string($s); } // If user pressed submit in one of the forms if ($_SERVER['REQUEST_METHOD'] == 'POST') { // cleaning title field $title = trim(sql_safe($_POST['title'])); if ($title == '') // if title is not set $title = '(empty title)';// use (empty title) string if ($_POST['password'] != $password) // cheking passwors $msg = 'Error: wrong upload password'; else { if (isset($_FILES['photo'])) { @list(, , $imtype, ) = getimagesize($_FILES['photo']['tmp_name']); // Get image type. // We use @ to omit errors if ($imtype == 3) // cheking image type $ext="png"; // to use it later in HTTP headers elseif ($imtype == 2) $ext="jpeg"; elseif ($imtype == 1) $ext="gif"; else $msg = 'Error: unknown file format'; if (!isset($msg)) // If there was no error { $data = file_get_contents($_FILES['photo']['tmp_name']); $data = mysql_real_escape_string($data); // Preparing data to be used in MySQL query mysql_query("INSERT INTO {$table} SET ext='$ext', title='$title', data='$data'"); $msg = 'Success: image uploaded'; } } elseif (isset($_GET['title'])) // isset(..title) needed $msg = 'Error: file not loaded';// to make sure we've using // upload form, not form // for deletion if (isset($_POST['del'])) // If used selected some photo to delete { // in 'uploaded images form'; $id = intval($_POST['del']); mysql_query("DELETE FROM {$table} WHERE id=$id"); $msg = 'Photo deleted'; } } } elseif (isset($_GET['show'])) { $id = intval($_GET['show']); $result = mysql_query("SELECT ext, UNIX_TIMESTAMP(image_time), data FROM {$table} WHERE id=$id LIMIT 1"); if (mysql_num_rows($result) == 0) die('no image'); list($ext, $image_time, $data) = mysql_fetch_row($result); $send_304 = false; if (php_sapi_name() == 'apache') { // if our web server is apache // we get check HTTP // If-Modified-Since header // and do not send image // if there is a cached version $ar = apache_request_headers(); if (isset($ar['If-Modified-Since']) && // If-Modified-Since should exists ($ar['If-Modified-Since'] != '') && // not empty (strtotime($ar['If-Modified-Since']) >= $image_time)) // and grater than $send_304 = true; // image_time } if ($send_304) { // Sending 304 response to browser // "Browser, your cached version of image is OK // we're not sending anything new to you" header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ts).' GMT', true, 304); exit(); // bye-bye } // outputing Last-Modified header header('Last-Modified: '.gmdate('D, d M Y H:i:s', $image_time).' GMT', true, 200); // Set expiration time +1 year // We do not have any photo re-uploading // so, browser may cache this photo for quite a long time header('Expires: '.gmdate('D, d M Y H:i:s', $image_time + 86400*365).' GMT', true, 200); // outputing HTTP headers header('Content-Length: '.strlen($data)); header("Content-type: image/{$ext}"); // outputing image echo $data; exit(); } ?> <html><head> <title>MySQL Blob Image Gallery Example</title> </head> <body> <?php if (isset($msg)) // this is special section for // outputing message { ?> <p style="font-weight: bold;"><?=$msg?> <br> <a href="<?=$PHP_SELF?>">reload page</a> <!-- I've added reloading link, because refreshing POST queries is not good idea --> </p> <?php } ?> <h1>Blob image gallery</h1> <h2>Uploaded images:</h2> <form action="<?=$PHP_SELF?>" method="post"> <!-- This form is used for image deletion --> <?php $result = mysql_query("SELECT id, image_time, title FROM {$table} ORDER BY id DESC"); if (mysql_num_rows($result) == 0) // table is empty echo '<ul><li>No images loaded</li></ul>'; else { echo '<ul>'; while(list($id, $image_time, $title) = mysql_fetch_row($result)) { // outputing list echo "<li><input type='radio' name='del' value='{$id}'>"; echo "<a href='{$PHP_SELF}?show={$id}'>{$title}</a> – "; echo "<small>{$image_time}</small></li>"; } echo '</ul>'; echo '<label for="password">Password:</label><br>'; echo '<input type="password" name="password" id="password"><br><br>'; echo '<input type="submit" value="Delete selected">'; } ?> </form> <h2>Upload new image:</h2> <form action="<?=$PHP_SELF?>" method="POST" enctype="multipart/form-data"> <label for="title">Title:</label><br> <input type="text" name="title" id="title" size="64"><br><br> <label for="photo">Photo:</label><br> <input type="file" name="photo" id="photo"><br><br> <label for="password">Password:</label><br> <input type="password" name="password" id="password"><br><br> <input type="submit" value="upload"> </form> </body> </html>
  7. Yes.. this working and this is what I needed.. Thank you
  8. Dear all, I want to remove all lines less than 3 words longs so I can stuff the rest into a db. Can somebody help me? Thank you in advance
  9. Thank you Floydian.. I will try with help of php.net...
  10. Dear all, Can somebody help me please? Instead of ‘username’ and 'password', I need random values from CSV file. Can somebody show me how can I do this? My CSV file looks like this: user001,userpass001 user002,userpass002 user003,userpass003 My script looks like this: <?php $t= new post(); $t->username='username'; $t->password='password'; $res = $t->update('This is some text.'); ?> Thank you very much advance.
  11. I’m new with PHP, and now I try to figure out how to do next thing. I think that is best solution might be, if rss.xml file (file where is RSS feed stored) will be check out and if it is changed in last 24 hours, than to run script, else if rss.xml is unchanged to do nothing. Does anybody think that there is better solution?
  12. Hello guys, Can somebody show me how to modify this script? I wish to execute it WITHOUT cron job, but I wish to limit that it can not be executed more than once a day (for instance after 86400 seconds or more) when first time is required in index.php. Can somebody help me with this? Thank you <?php // Please, edit these variables to your needs $blogTitle="Title Of your blog"; $blogUrl="http://www.yourblog.url/"; $pingListFile="pinglist.txt"; $showDebugInfo=FALSE; // Do you want verbose output? // Stop editing here // PingRPC.php // // 2007 by Sascha Tayefeh // http://www.tayefeh.de // // This is a PHP5-based XML-RPC ping script. It reads a one-column // fully qualified URL-list from a file ($pingListFile). Here is // an example how this file must look like: // ---------------------- // http://rpc.icerocket.com:10080/ // http://rpc.pingomatic.com/ // http://rpc.technorati.com/rpc/ping // http://rpc.weblogs.com/RPC2 // ---------------------- $replacementCount=0; $userAgent="pingrpc.php by tayefeh"; // Read pinglist file. Must contain one fully qualified URL // (e.g: http://rpc.technorati.com/rpc/ping) PER LINE (-> // delimiter is an ASCII-linebreak) $fp=fopen($pingListFile,"r"); while ( ! feof( $fp) ) { $line = trim(fgets( $fp, 4096)); // get the hostname $host=$line; // Make a copy of $line $host=preg_replace('/^.*http:\/\//','',$host); // Delete anything before http:// $host=preg_replace('/\/.*$/','',$host); // Delete anything after behind the hostname // get the path $path=$line; // Make another copy of $line $path=preg_replace('/^.*http:\/\/[a-zA-Z0-9\-_\.]*\.[a-zA-Z]{1,3}\//','',$path,-1,$replacementCount); // Delete anything before the path if(!$replacementCount) $path=''; // if there was no replacement (i.e. no explicit path), act appropiately if($host) $myList[$host]=$path; } echo "<h1>Ping process started</h1>"; echo "<p>Reading URLs from file $pingListFile: "; echo count($myList)." urls read.</p>"; // Use DOM to create the XML-File $xml= new DOMDocument('1.0'); $xml->formatOutput=true; $xml->preserveWhiteSpace=false; $xml->substituteEntities=false; // Create the xml structure $methodCall=$xml->appendChild($xml->createElement('methodCall')); $methodName=$methodCall->appendChild($xml->createElement('methodName')); $params=$methodCall->appendChild($xml->createElement('params')); $param[1]=$params->appendChild($xml->createElement('param')); $value[1]=$param[1]->appendChild($xml->createElement('value')); $param[2]=$params->appendChild($xml->createElement('param')); $value[2]=$param[2]->appendChild($xml->createElement('value')); // Set the node values $methodName->nodeValue="weblogUpdates.ping"; $value[1]->nodeValue=$blogTitle; $value[2]->nodeValue=$blogUrl; $xmlrpcReq = $xml->saveXML(); // Write the document into a string $xmlrpcLength = strlen( $xmlrpcReq ); // Get the string length. echo "Here's the xml-message I generated (size: $xmlrpcLength bytes):"; echo "\n<pre>\n"; echo htmlentities($xmlrpcReq); echo "</pre>"; echo "<dl>"; // Proceed every link read from file foreach ( $myList as $host => $path) { if($showDebugInfo) echo "<hr/>"; echo "<dt><strong>Pinging host: $host </strong>"; $httpReq = "POST /" . $path . " HTTP/1.0\r\n"; $httpReq .= "User-Agent: " . $userAgent. "\r\n"; $httpReq .= "Host: " . $host . "\r\n"; $httpReq .= "Content-Type: text/xml\r\n"; $httpReq .= "Content-length: $xmlrpcLength\r\n\r\n"; $httpReq .= "$xmlrpcReq\r\n"; echo "</dt>"; if($showDebugInfo) { echo "<dd><strong>Request:</strong><pre><span style=\"color: #cc9900\">".htmlentities($httpReq)."</span></pre>"; echo "<strong>Answer</strong>:<span style=\"color: #99cc00\"><pre>"; } // Actually, send ping if ( $pinghandle = @fsockopen( $host, 80 ) ) { @fputs( $pinghandle, $httpReq ); while ( ! feof( $pinghandle ) ) { $pingresponse = @fgets( $pinghandle, 128 ); if($showDebugInfo) echo htmlentities($pingresponse); } @fclose( $pinghandle ); } if($showDebugInfo) echo "</span></pre></dd>"; } echo "</dl>"; echo "<p>FINISHED</p>"; ?>
  13. Dear all, Can somebody help me to modify this script to scrape more than just one page? Thank you very much advance. <?php $url = "http://www.example.com"; $fp = fopen( $url, ‘r’ ); $content = ""; while( !feof( $fp ) ) { $buffer = trim( fgets( $fp, 4096 ) ); $content .= $buffer; } $start = '<title>'; $end = '<\/title>'; preg_match( "/$start(.*)$end/s", $content, $match ); $title = $match[ 1 ]; $metatagarray = get_meta_tags( $url ); $keywords = $metatagarray[ "keywords" ]; $description = $metatagarray[ "description" ]; echo "<div><strong>URL:</strong> $url</div>\n"; echo "<div><strong>Title:</strong> $title</div>\n"; echo "<div><strong>Description:</strong> $description</div>\n"; echo "<div><strong>Keywords:</strong> $keywords</div>\n"; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.