I am developing a custom homepage background,in my html have
<form action="'.$_SERVER['PHP_SELF'].'">
<input type="text" width="128px" name="mybg">
<input type="submit" value="Set as background">
</form>
<b style="position:absolute;height:100%;width:100%;top:0;left:0;z-index:-1;background:url('<?=$_SESSION['mybg'];?>');"></b>
and my php file:
if(isset($_GET['mybg'])){
session_set_cookie_params(3600 * 24 * 7);
session_start();
$_SESSION['mybg'] = $_GET['mybg'];
}
and my background image shown as post url,the url like "http://si.te/?mybg=http%3A%2F%2Fabc.com%2Fpic.jpg" but when i go back to the homepage(index.php) and the background image disappeared,how can I save that in the session?
I don’t want to use any sql please do not suggest that.
Your code is mainly correct, but you have to move the
session_start()outside theifcondition. If you don’t, the session will not be started when you go back to your homepage, and$_SESSION['mybg']will not be set.