Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I'm trying to make a cookie expire, I've saw the code that does it, and I've done it already.
So, what I've done already was making the expire date like this time() - 10 this would make the cookie time limit expire immediately, but I can't seem to make it work.
$number_of_days = 30 ;
$date_of_expiry = time() + 60 * 60 * 24 * $number_of_days ;
setcookie( "userlogin", $user_hash, $date_of_expiry, "/" ) ;
This should work:
setcookie("cookie_name", "", time()-3600);
If that does not work, you have any output before, you have to call it before any echo or html output. Otherwise the headers will be already sent and you can't change any cookie information.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have some PHP that displays the users session name in the HTML and if the user is not logged in, then I would like it to display "User" instead.
Can I have an if statement in this case? I tried it myself but I got header errors.
This is what I've tried so far but each practical attempt just spits out more errors at me.
This is a different approach I have tried.
<?=$_SESSION['sess_user'] or ("User");?>!
<?php echo (isset($_SESSION['sess_user']) ? $_SESSION['sess_user'] : "User"); ?>
This will check if the session is set, if it is then echo the session, if it isn't then it will echo "User".
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm working with cookies in php, and I define some inside a class function. It's curious, because if I just specify the name, content and path, they all work, but when I also specify the domain, it doesn't work (I mean that it doesn't show in browser cookies and when I try to get it, it doesn't exist.) don't know why. My code is exactly as I described, and I'm sure there's no syntax error (basically because PhP would tell me).
setcookie('rememberme', $cookie_string, time() + COOKIE_RUNTIME, "/", COOKIE_DOMAIN);
Cokie domain is ".127.0.0.1", but i also tried with other domains, and the same.
Can somebody tell me why? Thank you.
It would help to know the value of:
COOKIE_RUNTIME
The correct syntax is:
setcookie(name,value,expire,path,domain,secure)
This works:
$expire=time()+60*60*24*30;
setcookie("japagou", 1, $expire, "/", "yourdomain.tld");
Check some examples
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
When using PHP to do time() and store it in a MySQL server and then retrieve it,
when I try to convert it into seconds, it returns strange results.
1386787112 = 35 seconds ago (What my PHP says)
1386787112 was actually 1 second ago (What my current time says).
$da = date("s",1386787112);
This code is meant to returns the current time in second but it only updates if the time is bigger than 60 seconds. Am I doing something wrong?
Using the time() function will do what you're looking for. It's in fact defined just like your requirements.
Now, if you wanted seconds ago you could then use the time() function to do that:
$secs = time() - dbTimeValOfRecord;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I have two PHP files: A.php and B.php. A passes $id to B using POST and B can get $id the first time but I need to jump back to B again using Header. This time the parameter gets lost.
How can I pass the parameter when I use Header to jump back?
You must Use $_REQUEST instead of $_POST so it will work in both case . and when you use header to jump back again use query string with same name.
you can pass id variable in the query string when you redirect.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have two timestamps: one from time() function, other selects user in front-end. I need to compare this two timestamps, but ignore the seconds or set it to 00. What is the proper way to do this?
Had some time for an example:
$nr = 1111111122;
$nr = substr($nr, 0, strlen($nr)-2) . "00";
echo strtotime(date('Y-m-d H:i:00', time()));