i use get function in some my php pages and it will display the url as site.com/index.php?id=xyz i wish to hide the "?id=xyz" portion from all the urls and display url simply as site.com/index.php What should i do to acheive this?
i dont know if your up to it, but it seems like what you want is URL rewriting http://www.sitepoint.com/article/guide-url-rewriting
dear bokiatenxi , thanks a lot for the info .. cud u explain the 2nd suggestion (ie, using sessions)?
something like this... session_start(); if(isset($_GET['id'])) { $_SESSION['id'] = $_GET['id']; header("Location: index.php"); exit; } what this does is after using get to go to index.php?id=xyz, you save the value of id to a session variable then redirect back to index.php (without the ?id=xyz). After this, use the session variable instead of the get variable. this is not hiding the url for it will still show, but it will redirect quickly to the clean URL before the page actually loads. I would not recommend this, for me this is a waste of code, but I think this is the only way besides URL rewriting to be able to hide the get variables. Like I said before, if you want to hide the data being passed, the most efficient way for me is to use post instead of get...
thanks but i am getting this error Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/xxxxxxx/public_html/yyyyy/index.php:4) in /home/xxxxxxx/public_html/yyyyy/index.php on line 5 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/xxxxxxx/public_html/yyyyy/index.php:4) in /home/xxxxxxx/public_html/yyyyy/index.php on line 5
this is the actual code of index.php <html> <head><title>Welcome</title></head> <body> <?php session_start(); if(isset($_GET['id'])) { $_SESSION['id'] = $_GET['id']; header("Location: index.php"); exit; } include "header.html"; print (isset($_GET['name']) ? "\"" : "")."".(isset($_GET['name']) ? $_GET['name']."\"" : "name"); include "footer.html"; ?> PHP: Please help
you need to put session_start() at the very first line of your code for it to work... Also, the header function will only work if you put it before any html codes, echo statements or print statements.. this is how it should look... <?php session_start(); if(isset($_GET['id'])) { $_SESSION['id'] = $_GET['id']; header("Location: index.php"); exit; } ?> <html> <head> <title>Welcome</title> </head> <body> <?php include "header.html"; print (isset($_GET['name']) ? "\"" : "")."".(isset($_GET['name']) ? $_GET['name']."\"" : "name"); include "footer.html"; ?>
Also, print (isset($_GET['name']) ? "\"" : "")."".(isset($_GET['name']) ? $_GET['name']."\"" : "name"); after redirection, the get variables are gone, so the above line will no longer output the get variables. you should also add the get variable 'name' in a session variable
depends on how complicated you want it to be. I just use .htacess mod_rewrite. http://www.ilovejackdaniels.com/cheat-sheets/mod_rewrite-cheat-sheet/
but now another problem. It is simply printing "id" in the final redirected page (index.php). what should i do to display the contend (GET_funtion) in the final page
tried session_start(); if(isset($_GET['id'])) { $_SESSION['id'] = $_GET['id']; print_r($_SESSION); header("Location: java.v"); exit; but not getting desired results
here is code . Please do the correction <?php session_start(); if(isset($_GET['id'])) { $_SESSION['id'] = $_GET['id']; header("Location: index.php"); exit; } ?> <html> <head><title>Welcome</title></head> <body> <?php print_r($_SESSION); include "head.html"; print (isset($_GET['id']) ? "\"Welcome" : "")."".(isset($_GET['id']) ? $_GET['id']."\"" : "id"); include "foot.html"; ?>