Want to delete a PHP Session?

March 15th, 2007 by Quatrux

A lot of PHP novice programmers which don’t want to understand how the sessions work in the beginning, usually doesn’t delete a session the right way, so I wanted to post an example PHP script session_delete(); which deletes everything as needed.

  1. function session_delete($sname = ‘Current User’) {
  2.         # Set Session Name to a Variable
  3.         $name = session_name();
  4.         /* Empty the Cookie from Session */
  5.         if (!headers_sent() ) { setcookie($name,"",0,"/"); }
  6.         /* Remove the Cookie Value */
  7.         unset($_COOKIE[$name]);
  8.         /* Remove all the Info from the Super Global */
  9.         $_SESSION = array();
  10.         /* Free all session variables */
  11.         session_unset();
  12.         /* Destroy all data registered to a session */
  13.         if (session_destroy() === FALSE) {
  14.                 return FALSE;
  15.         } else {
  16.                 return TRUE;
  17.         }       
  18. }

Posted in PHP | No Comments »

What is the difference between ["PHP_SELF"], ["SCRIPT_NAME"] and ["REQUEST_URI"]?

March 15th, 2007 by Quatrux

What is the difference between ‘PHP_SELF’, ‘SCRIPT_NAME’ and ‘REQUEST_URI’ in the superglobal $_SERVER[] or also known as $HTTP_SERVER_VARS which is deprecated since PHP 4.1.0 and isn’t really a superglobal, but anyway, what is the difference? On different support channels and forums people ask this question and I tried to search google and didn’t find an answer, so I thought to write it here.

$_SERVER['PHP_SELF'];

The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar.

  • http://example.com/ — – — /index.php
  • http://example.com/test/index.php — – — /test/index.php
  • http://example.com/index.php?q=submit — – — /index.php
  • http://example.com/index.php/test/ — – — /index.php/test

So actually it returns the path to the current filename typed in the url without the QUERY_STRING, but when we us index.php/test/download/ it shows the path to ../test/download/ as we want it to do that, because usually using PHP_SELF is very useful with submitting forms, so having the PATH_INFO included in the PHP_SELF is a good idea and if you don’t want it, just use SCRIPT_NAME which will always show the executing file.

$_SERVER['SCRIPT_NAME'];

Contains the current script’s path. This is useful for pages which need to point to themselves.

  • http://example.com/ — – — /index.php
  • http://example.com/test/index.php — – — /test/index.php
  • http://example.com/index.php?q=submit — – — /index.php
  • http://example.com/index.php/test/ — – — /index.php/

So it is similar to PHP_SELF, just the PATH_INFO isn’t included, so you just point to the current filename executing. Note; that SCRIPT_FILENAME actually is the same, but it also returns the server root and acts the same as $_SERVER['DOCUMENT_ROOT']; . ” . $_SERVER['SCRIPT_NAME'];

$_SERVER['REQUEST_URI'];

The URI which was given in order to access this page; for instance, ‘/index.html’.

A lot of people usually don’t understand the usage of this, for example if you wanted to access index.html but it didn’t exist on the server, you get redirected to say 404.php page which says that the filename doesn’t exist, when you will try to use any other value, like PHP_SELF or SCRIPT_NAME it will print you /404.php and not the file you requested, but when you will use REQUEST_URI, it will print the full URL which you typed in order to get to that page, this sometimes is quite useful.

In addition, I recommend to use the constant __FILE__ if you want to get the absolute path to your current dir and if you want to set an include path, it is best to do it also with this constant by adding the function dirname(); like this: dirname(__FILE__);

  1. /* Change Super Global */
  2. $s =& $_SERVER;
  3. /* Set the Default Include Path */
  4. set_include_path( dirname( $s[‘SCRIPT_FILENAME’] ).‘/includes’. PATH_SEPARATOR . dirname(__FILE__) );

If you ask if this is different, when I will say yes it is. The first value points to the currently executing file like /index.php and the second value is pointing to the current included file directory, it even can be outside /public_html/ somewhere in /home/user

Sometimes people don’t want to get the filename, but only the Query of the GET method, so there is a value $_SERVER['QUERY_STRING']; which returns everything after the ?

  • http://example.com// — – — (nothing)
  • http://example.com/test/index.php — – — (nothing)
  • http://example.com/index.php?q=submit — – — q=submit
  • http://example.com/index.php/test/ — – — (nothing)
  • http://example.com/index.php/test/?q=submit — – — q=submit

Furthermore, if you want to get the server root, you can use $_SERVER['DOCUMENT_ROOT']; which usually returns something like /home/user/public_html/

Moreover, sometimes you can have an headache if you want to get the domain the script is currently running on, you ask why? because sometimes you can use not the right $_SERVER array key for that.. if you’ll be using $_SERVER['SERVER_NAME']; you will get the domain of the server, but say you’re using CPanel and added a domain through it and you will execute under it, you will still get the original server domain, this is called virtual host, in order to get it you need to use $_SERVER['HTTP_HOST'];

Read more about Reserved Server Variables on PHP dot net Manual!

Posted in PHP | No Comments »

3 Column CSS layout

March 5th, 2007 by Quatrux

3 Column CSS layout can be made in different ways, but I wanted to make one with divs and not html tables.. the way I wanted to make it is: I need a left menu bar, a right sidebar and the middle content bar.. the hardest thing for me was to make it without any width with set pixels, this was hard, but I managed to create such a layout with display: table; table-row and table-cell, where I created three table-cells for it, the secret is that the sidebars are using white-space: nowrap; I need them to stretch and be as wide as the text there is, I don’t want the links to break to a new line, if I don’t break a line with br, same with the other sidebar, but that means that the middle bar automatically will need to shrink when the sidebars stretch, this is quite hard to do, using html tables it would be quite easy.. using css display: table; is also easy, so where is the problem? Internet Explorer, that is the fucking problem! It doesn’t support display: table; as it should, so I created another stylesheet for IE, where the left sidebar is floating to the left and the right bat is floating to the right, I didn’t set any width, they are as wide as text, but how the hell to put the middle bar to use all the middle left space? Well, on IE you can write expressions, javascript expressions, so I just using javascript in css file (all my layout width) – (left sidebar width + right sidebar width) and got the middle width, it doesn’t work if javascript is off, but people who browse with javascript turned off understand that they are not getting all the features they can, besides, if you have javascript off, you will see the same layout, just not using all the available width! oh yea, I forgot to mention, that the middle bar is also floating to the left with float: left; here is the expressions code:

  1. div#content {
  2.         float: left;
  3.         width: expression((774(document.getElementById(‘menu’).clientWidth + document.getElementById(’sidebar’).clientWidth)) + "px");
  4. }

So this solves the issue with IE, this is a little hack to make it work as with display: table; If I haven’t thought of this, I was ready to make pages of my site which browse with IE that IE sucks and suck a dick if you browse with it :D

Posted in Webmastering | No Comments »

Multiple versions of IE?

March 5th, 2007 by Quatrux

When IE7 appeared for Windows XP, a lot of whom installed it and wanted to test their pages with IE6? Yeah, the same for me, but once I found this software package called Multiple IE, it has a simple and working msi installer and with time most of the IE problems running on one system got solved, the dll files and similar.. So using this software, you can run different versions of Internet Explorer on your Windows installation, no need to go to a friend and test your page ;D It includes IE5, IE6 and it is best to install it when you have already installed IE7.. of course it also includes IE4 and IE3, but I don’t think these browsers matter very much, when I am talking about IE5, I talk about 5.01 and 5.5 ;)

I found it very comfortable for a web designer, also I know that there is a similar project on Linux, a batch script or something which installs the same stuff on wine, for a designer to use! Anyone want to create a package, where you can have Opera6, Opera7 and Opera8? Well, most now browse with Opera9 and some still with Opera8 :P and as I know, everyone updates their Firefox :D

http://tredosoft.com/Multiple_IE

Posted in Computers, Windows | No Comments »

KHTML for Windows?

March 5th, 2007 by Quatrux

A lot of us, web designers, or tech web programmers want to have a khtml browser on Windows and Today, I found that a Webkit rendering engine is being ported to Windows, it is an application called Swift, which is a Web Browser for Microsoft Windows based around the WebKit rendering engine. It’s extremely fast! Swift is backed behind some hard work by a team of developers. As we know, Webkit rendering engine is used by Safari a MacOS browser, which passed the Acid2 test, as we know, Webkit is based on KHTML just with changes for the MacOS, so currently, the Swift version is 0.2 and most of the pages are very nice, some pages break though.. So I believe, that this browser is going to be a very popular one and going to be in the race among other browsers on Windows, the poll, which is the best browser for windows will need to have Opera, Firefox, Swift and Internet Explorer.. four different engines and only Firefox doesn’t pass the Acid2 test, well only the Firefox3 alpha version ;D

www.getswift.org

Posted in Personal | 2 Comments »

Moon Landing was a Fake!

March 5th, 2007 by Quatrux

People need to understand that America didn’t land on the Moon in the cold war, the Moon Landing itself is a fake, they just wanted to win the space race, which they were loosing, due to the Russians were the first ones to send an artificial satellite to the space, they were the first ones to send a human to the space, USA weren’t the first ones in the space race, so they wanted to reach the moon and win the space race, but when they understood that it is impossible, they thought to cheat and fool all the world which at that time wouldn’t even think to to think that it was a fraud.. So how can you believe America? I don’t believe them and a lot of intelligent people who has analytical thinking and can think logically, knows the basics of physics, chemistry, biology, astronomy, information technologies and politics with history, can understand that all this Moon Landing is bullshit!

Almost all the people were killed after some time involved with the Apollo project? They were a threat to USA government at the cold war, even the America President John Kennedy which in my opinion knew about it was killed and don’t know if only about this issue, but this is another topic.. After a year of the great expedition, 11 people who were involved with the Apollo program died, 7 died in car accidents and 3 burnt down in test capsules although they were high-class pilots. So this is really obvious, the ones who live, has “fame and glory”, I am talking about people who don’t talk about this and lie. Therefore, I read that even more people died with time involved with Apollo program and only several people know the truth, all the people are to stupid to understand that, but a person is smart enough, so usually this blog is read by separate people. I won’t start talking about the fake move, that is obvious and proved in most of the books, I will start to talk about the Moon rocks, how did they get to Earth and where did America/NASA get them?

As I know, the Moon rocks are real, a lot of very advanced chemistry guys didn’t find anything what could be a hoax, fake, fraud and etc. they are several billion years old and other stuff, that is not the main part, they are real and people who wanted to prove that all this is a hoax didn’t prove it.. So was a man on the Moon to pick up those Moon rocks? I will talk theoretically, they might have been, but it wasn’t Neil Armstrong and that other guy, that movie is a fake, we all know that, so that only means that the Moon rocks could have been found on Earth, say in Arctic or Antarctica, those rocks could have been faked, very well faked, but in my opinion it would be to hard to make them so unique, so the last theory I believe is that they are really from the Moon and that means that a man was on the Moon!? The primitive technology of USA/NASA at that time would send a Man to the Moon? They would get a very high dose of radiation and after some time would die, so this might of happened, the primitive technology of that time couldn’t have created a robot smart enough to pick up a Moon rock, so NASA and USA were sacrificing people, I call them heroes, the real heroes who deserve the glory and not Armstrong, who is just or almost a Good Actor and has a nice smile and can lie watching into the eyes.. Anyway those people died in different expeditions, I just can guess how many there were, but some might have died in space, on the Moon or after the expedition when without any strength and full of radiation they came back with the Moon rocks and died on Earth. I read somewhere, that in that period of Apollo program, several good astronauts were lost without notice and some died without being able to recognise the body, isn’t this obvious? that NASA was doing something? America couldn’t show the world those kind of movies/pictures to the world, where their astronauts are suffering in agony from radiation or another issue, they didn’t have the technology to transmit this kind of expedition, but they needed to prove that they were on the Moon and landed there, but they needed to show it with fame and glory, that noone suffered, so the Movie and pictures were created to show that! the Movie is a fake, the moon rocks are real, how else can you prove it? can you explain it? We all just can guess, but the truth is somewhere there, I wish to know the truth, but only a little part of it, I am happy to live in a world full of lies and frauds..

So now, talking further.. NASA was unsuccessful to fly a man to the space at those time, so how the hell can we believe that those Apollo projects, all three of them with man on board were successful? In my opinion, they weren’t successful, due to if they were, NASA wouldn’t need to do all that movie fake and Today we have to admit, that no country at that time had the technology to safely deliver a Man to the Moon! Another issue is the produced pictures on the Moon by astronauts, as I know they weren’t photographers, on the moon temperature, a normal film would have melt and wouldn’t photograph anything there, so they used a special film which is unknown and secret to us, they couldn’t even press a button or focus on the picturesque, but they still came back with perfect pictures of which even professional photographers could be jealous.. All the pictures don’t have stars in the atmosphere, everything is black, where the hell are stars? the shadows are also strange, the only light source on the moon is the Sun and they have taken such perfect pictures, that even a Hollywood photographer with special light effects would also be jealous.. When you watch all the pictures and the movies, you can see different shadows.. Also, the the hell the USA flag is gently moving? as I know on the Moon there are no wind, due to there is no atmosphere, so the flag should be just like a stick with some cloth..

The Apollo computers performed poorer than some simple todays calculators, how the hell they the astronauts could survive in open space on the moon, where the temperatures are 250 Fahrenheit degrees below zero, there are no atmospheric layers and magnetic fields.. their space suits were made of rubber and cloth?! Such fucking high radiation and noone got sick? I don’t believe it.. Another issue is again the moon rocks, it is unlikely that 382 kg of moon soil could be delivered to the Earth after only three expeditions, as I read Soviet moon research vehicles could only carry 0.3kg at one time, due to it is very risky to pick up more additional cargo.. Moreover, the landing of Apollo was quite strange, the running engine didn’t move a single stone or any dust on the surface, the pressure of a jet engine would make a crater on the place of landing while braking, as we know the moon gravitation makes up 1/6 of Earth gravitation, so the could of dust should be 6 times higher than on the photos taken on the Moon!

Do you want to hear how everything cost? The cost of the entire Apollo program: USD $25.4 billion -1969 Dollars ($135-billion in 2005 Dollars). Well, I don’t think I will ever find so much money in my pocket, but if it was filmed in a studio, it was much cheaper and again, the moon rocks is a mystery, so I can talk only theoretically.. it might have been that the film/movie and pictures were destroyed by radiation and stuff, so thats is why they needed to create all this bullshit, but I don’t know, I don’t care, all the history books write that America was the first country to visit the Moon! Anyway, even the moon rocks can be faked, so everything is a fake and this is in my opinion the biggest conspiracy ever, America fooled all the world, all the people! they think that we are fools, then they are morons, which they are!

Posted in Personal | No Comments »