Failed to write session data Please verify the current setting of session.save_path

PHP No Comments »

I was updating a project. When i checked my work i got this warning and in could not login in to the site.
Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp).

Then i searched and got the following snippet and it worked but still i have to make it bug free and i am working on it but not immediate.

session_save_path('/home/site/public_html/session');
ini_set('session.gc_probability', 1);

I created a directory ’session’ in the root folder and gave the write permission.
The above script is just an example.
I ran the script and it worked.

Here we have to think about how the old session files are deleted and what is the need for the ini setting session.gc.probability… instead of me explaining this you better go to the url which i have given below.

If you face the same problem and try the above. And then you should read this article. I, yet to completely test that only then i can post anything here.

If anybody would like to give me more information about this the you can comment on this. And your objections are welcomed.

show html elements on top of youtube video - youtube embed z index - wmode transparent

PHP No Comments »

Assume that you are managing youtube videos in your site admin panel. So they are dynamically displayed in web pages.
Youtube video embed code, as i have seen does not include the option of making the video go behind HTML elements.
When we do some animation you can see that the youtube video is on top of all.

So we need to include the wmode transparent option in the embedd code before displaying.
This attribute(param) will make the youtube video go behing any popups.

Here is the simple code to insert the wmode transparent option into the url before displaying it.

<div class='youtubevideo'>
$string = $url;//youtube video url from database
$string = str_replace("<embed","<param name='wmode' value='transparent'></param><embed",$string);
$string = str_replace("<embed","<embed wmode='transparent' ",$string);
echo $string;
</div>


How to replace the width and height of an embed code or youtube video

print div content - Print only the content of an HTML element and not the whole document

JavaScript 7 Comments »

This snippet will print the contents of any html element and not the entire page.
Get the contents of the innerhtml of the element. Here it is a div. We are going to print the contents of a div.
Define an iframe (better before this script).
This iframe is hidden on the screen by giving the style so and so.
Get a reference to the iframe’s contentwindow so that you can write the contents of the div in to the body of the iframe.
Use the close command like in the script else you can see that the browser is still loading the page even if you have completely written all the text into the content window.
So when you do close call you specify that there is no more contents to write to.
And then we make the iframe as the active window because when you print the active windows total body content will gets printed.
and then we call the print command. voila.
Without any modification this code snippet works well for me so hope it would be the same case for you guys.

The JavaScript code

var content = document.getElementById("divcontents");
var pri = document.getElementById("ifmcontentstoprint").contentWindow;
pri.document.open();
pri.document.write(content.innerHTML);
pri.document.close();
pri.focus();
pri.print();

The HTML Code

<iframe id="ifmcontentstoprint" style="height: 0px; width: 0px; position: absolute"></iframe>

Why the need of an iframe?
as you all know when you print the whole document gets printed.
So we create a hidden new document with the help of an iframe and we assign the contents we want to print to the body of the iframe.
So the iframe will contain only the contents which we want to print.
And since the iframe is hidden everything will appear normal at the same the work is done.

Scroll DIV, HTML elements using Javascript

JavaScript 1 Comment »

Javascript Code

<script>
var sc, maxscroll, minscroll=0;
var uptime, downtime
var pixelsteps=5;
window.onload = function()
{
	sc = document.getElementById('wn3');
	maxscroll = sc.scrollHeight - sc.offsetHeight
	minscroll = 0		
}
 
function scrollup()
{
	uptime = window.setInterval('scrollUp()',1)
}
function scrolldown()
{
	downtime = window.setInterval('scrollDown()',1)
}
 
function scrollUp()
{
	if(sc.scrollTop>0)
		sc.scrollTop = sc.scrollTop - pixelsteps
	window.location.hash = sc.scrollTop		
}
function scrollDown()
{
	if(sc.scrollTop<maxscroll)
		sc.scrollTop = sc.scrollTop +  pixelsteps
	window.location.hash = sc.scrollTop
}
 
function clearscroll()
{
	if(uptime)window.clearInterval(uptime)
	if(downtime)window.clearInterval(downtime)	
}
</script>

HTML Code

 
<img src="up.gif" onmousedown="scrollup();" onmouseup="clearscroll();" /><br>
<img src="dn.gif" onmousedown="scrolldown();" onmouseup="clearscroll()"  />

== Version 2 ==

var sc, maxscroll, minscroll=0;
var uptime, downtime
var pixelsteps=2;
var delay = 10
function inscroll(src)
{
	if(arguments.length>1)pixelsteps = arguments[1]	
	if(arguments.length>2)delay = arguments[2]		
 
	sc = document.getElementById(src);
	maxscroll = sc.scrollHeight - sc.offsetHeight
	minscroll = 0		
}
 
function scrollup()
{
	uptime = window.setInterval('scrollUp()',delay)
}
function scrolldown()
{
	downtime = window.setInterval('scrollDown()',delay)
}
 
function scrollUp()
{
	if(sc.scrollTop>0)
		sc.scrollTop = sc.scrollTop - pixelsteps
}
function scrollDown()
{
	if(sc.scrollTop<maxscroll)
		sc.scrollTop = sc.scrollTop +  pixelsteps
}
 
function clearscroll()
{
	if(uptime)window.clearInterval(uptime)
	if(downtime)window.clearInterval(downtime)	
}

You have to call inscroll(’divid’,pixelincrementvalue,delay);

force download - authenticated download

PHP No Comments »

Basically downloads are normal direct link to real files in the server with a complete static url link to the file. So any body can click the link and can download the file. Any cross site script can access the file any time or any user can access the file from anywhere.

What if you want to allow file downloads only if the user is logged in.
what if you want to hide the actual file and its folder from displaying it to the user instead you want to show a different url which could probably be a server side script file (.php for example). and that could fetch the actual file with a different name.

For that i use the force download concept. I will just send the id of a file for which its filename and location are always hidden. take this for example…

<a href='sitename.com/files/files.php?id=45'>Click here to download</a>

and in files.php firstly i will check whether the users has logged in and only then i will let the file to download… else nothing happens.

here is a sample code to do a force download.

//select fn from tablename where id=$_request[id]
//assume that the file is in the junk named folder
// the the force download script will look like the following
 
$filename = "doc_O1jtIYi4jkg8Xh2k/$fn";
header("Cache-Control: no-store");
header("Expires: 0");
header("Content-Type: application/octet-stream");
header("Content-disposition: attachment; filename=\"".basename($filename)."\"");
header("Content-Transfer-Encoding: binary");
header('Content-Length: '. filesize($filename));
readfile($filename);

the readfile function reads the contents of a file and outputs to the client.
cache control no-store if for geko browsers and no-cache can be included for IE browsers
You can either use the exact mime type if you know in the place of content-type.

This works in all browsers. People either download, save and view the file or they directly open the file. When they do the second and if their browser is IE 6 then you get a message that ‘cannot access file from temporary internet folder’ so for IE 6 the users has to save the file first and then they have to open it.

If you find any sense if not appropriate then please post a comment.

prevent reloading flash movie on every page by using flashvars

Flash No Comments »

You can prevent the flash showing the loading progress on each page by using the flashvars.

I wanted the menus in flash to be highlighted when the page is under that menu. for example i have home, about, services, contact. now i am in home page. when i click services page that page loads and i want services to be highlighted in a different color. so when ever you are in any page the menu for that page should be highlighted. for doing that i use.

<param name="movie" value="flash/header2_fv8.swf?button=0">

the number for button will vary for each menu. the button number is the reference for menus which are to be highlighted when a page is in view.

so on any page home can be button 0 and so on… and in html of any page what ever button number you give in object tag that menu in the flash is highlighted…

if you use a query string directly like

<object data="flash/header2_fv8.swf?button=0">

or

like

<param name="movie" value="flash/header2_fv8.swf?button=0">

then for every page load

the flash movie will show the loading progress.

The reason might be that every time you send a query string and flash could assume it as a

new url and it loads as if it is loading for the first time. just an assumption. and some

people too said so.

so to prevent this that is to prevent flash to show the loading progress again and again
you can use the FlashVars attribute like in the following.

<param name="movie" value="flash/header2_fv8.swf?button=0">

here is a sample code

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,24" width="980" height="394">
<param name="movie" value="flash/header2_fv8.swf" />
<param name="quality" value="high" />
<param name="menu" value="false" />
<param name="wmode" value="transparent" />
<param name="FlashVars" value="button=1">
 
 
      <!--[if !IE]> <-->
	<object data="flash/header2_fv8.swf" width="980" height="394" type="application/x-shockwave-flash">
        <param name="quality" value="high" />
	<param name="FlashVars" value="button=1">
        <param name="menu" value="false" />
        <param name="pluginurl" value="http://www.macromedia.com/go/getflashplayer" />
        <param name="wmode" value="transparent" />       
      </object>
 
      <!--> <![endif]-->
    </object>


session side effect session.bug_compat_42 or session.bug_compat_warn

PHP 3 Comments »

Warning: Unknown: Your script possibly relies on a session
side-effect which existed until PHP 4.2.3. Please be advised that
the session extension does not consider global variables as a
source of data, unless register_globals is enabled. You can disable
this functionality and this warning by setting
session.bug_compat_42 or session.bug_compat_warn to off,
respectively. in Unknown on line 0

This error likely appears when setting some thing like this $_SESSION['something'] = NULL; or you are assigning a variables value to a session which is null. hopefully.

what people say is better turn off this warning by
 
1. "session.bug_compat_42 = 0" in your php.ini
 
2. setting the following in your .htaccess file
    php_flag session.bug_compat_42 0
    php_flag session.bug_compat_warn 0
 
3. Directly write the following code in your php script where you want to 
stop the warning. It is better if you set it in a common include file.
 
ini_set('session.bug_compat_42',0);
ini_set('session.bug_compat_warn',0);
...

embedding flash in html for XHTML strict doc type

HTML No Comments »

Normally when we include flash html code it will have an object tag which will have a child tag which works well i all browsers with html document type transitional.

When we set html document type to strict then w3c validation shows error on embed tag. So what could be the alternate to include a flash code for w3c strict mode.

i found this code in google codes… and i have given the link below to the resource which is in detail and also has a java script alternate of including flash content in a html page.

 
      <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="780" height="420">
        <param name="movie" value="myContent.swf" />
        <!--[if !IE]>-->
        <object type="application/x-shockwave-flash" data="myContent.swf" width="780" height="420">
        <!--<![endif]-->
          <p>Alternative content</p>
        <!--[if !IE]>-->
        </object>
        <!--<![endif]-->
      </object>

the complete documentation can be found at the following url…

http://code.google.com/p/swfobject/wiki/documentation

sending mail from localhost in php

PHP 3 Comments »

Use the basic phpmailer code which comes with the phpmailer zip form phpclasses.org
the following code is the default one which sends mail from your server by using the default server settings.

the host name is set to localhost and authentication is false(which takes the default). these are the two lines which
vary when sending mail form localhost.

include("includes/phpmailer/class.phpmailer.php");
 
$mail = new phpmailer();
$mail->PluginDir = "/include/";
$mail->IsSMTP(); // send via SMTP
 
$mail->From = "noreplysample.com";
$mail->FromName = "From Name";
$mail->AddAddress("address@host.com");
$mail->WordWrap = 65; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Mail Subject";
 
$mail->SMTPAuth = false; // turn off SMTP authentication			
$mail->Host = "localhost"; // SMTP servers
 
$mail->Body = $msg;
$mail->send();

the code to send mail form your localhost to any remote email server
the difference in the above and the following is i have given the important part which need to send mail from localhost
the first below two lines differ from the above. and the last two lines are added.
you have to give your servers auth information to send mail. So when ever mail is sent from localhost to a remote server
a server reference is needed. which means… mail is sent form localhost on-behalf of your server.

 
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Host = "samplesite.com"; // SMTP servers
$mail->Userame = "testing@testing.com";
$mail->Password = "testing";

so when the above lines gets executed this code connects to your site for verification
and then the mail is sent with reference to your server. so
you need a server by using which you can send mails from localhost.

here is the full code which sends mail from localhost.

include("includes/phpmailer/class.phpmailer.php");
 
$mail = new phpmailer();
$mail->PluginDir = "/include/";
$mail->IsSMTP(); // send via SMTP
 
$mail->From = "noreplysample.com";
$mail->FromName = "From Name";
$mail->AddAddress("address@host.com");
$mail->WordWrap = 65; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Mail Subject";
 
$mail->SMTPAuth = true; 						
$mail->Host = "samplesite.com"; // SMTP servers
$mail->Userame = "testing@samplesite.com";
$mail->Password = "testing";
 
$mail->Body = $msg;
$mail->send();

the from address should be a valid domain string. else mostly your mail will not be sent.

using virtual host in apache like virtual directory in windows

Apache No Comments »

by default we have our files stored in a user defined path like d:\www\xampp\htdocs\site1
when we access we give as localhost/site1

using virtual host option you can use like the following
consider you have your site in d:\www\xampp\htdocs\site2
you can access your site as “http://site2″ or “http://site2.com” or “http://site2.local” … by updating the httpd.conf file
which will be present in the apache/conf folder of your installation.

edit your httpd.conf file and go to the bottom of it. and you can add like the following.
i assume that your default document root is d:\www\xampp\htdocs

NameVirtualHost 127.0.0.1
 
<VirtualHost 127.0.0.1>
   DocumentRoot "d:\www\xampp\htdocs\site1"
   ServerName site1
</VirtualHost>

before using this you have to do two steps

one is restarting apache and the other is as follows

since we are going to give http://site1 windows will connect to the internet to fetch the site but we have to inform windows
not to connect to the www and instead connect to the local site1. for this you have to add the site1 in a windows file which
is stored in the following folder

C:\WINDOWS\system32\drivers\etc

the file name is “hosts” without extension

you have to add the following line in the file “hosts”

127.0.0.1       site1 or
127.0.0.1       site1.com [if you want to access that way] or any of your wish

consider that you are having your site outside the default path of apache say d:\mysite
then you have to follow the steps below to include that

<Directory "D:\mysite">
  Order Deny,Allow
  Allow from all
</Directory>
 
and this besides the similar code
 
<VirtualHost 127.0.0.1>
   DocumentRoot "d:\mysite"
   ServerName mysite
</VirtualHost>

include the above better before NameVirtualHost 127.0.0.1

so you have two sites now and you can run your sites like the following
type in the address bar after restarting apache as “site1″ which will automatically be called as “http://site1″ and mysite whic will be like “http://mysite”

try it and enjoy…

Entries RSS