Jump to content

php code not executing in /xampp/htdocs folder


qmqmqm

Recommended Posts

Hi

 

I am new to php and this forum.

I have this following piece of code in a php file, which I put inside the /xampp/htdocs folder.

 

session_start();
$ses_startvar = "started";
session_register("ses_startvar");

//code after the HTML form
if (isset($posted)) {
if (strlen($_COOKIE[phpSESSID]) == 32) {
echo "Session ID is being maintained in a cookie<br> and is " . $_COOKIE[phpSESSID];
} else {
echo "Session ID is being maintained in a querystring<br> and is " . $GLOBALS[phpSESSID];
}

 

The php file loads fine. But when I click on the button, it should show me the cookie id. However when I click on the button nothing is echoed.

 

Does anyone know why?

 

Thanks,

 

Tom

Thank you The Little Guy. Unfortunately that does not solve the problem.

 

In fact I am having some trouble with other php code as well, such as:

 

$my_var = $form_var;

echo "The value of \$my_var is $my_var <br>";

if (is_numeric($my_var)) {

$my_var = $my_var * 1;

}

if ($my_var == "true" or $my_var == "false" or $my_var == "yes" or $my_var == "no") {

settype($my_var, "boolean");

}

echo "The data type of \$my_var is " . gettype($my_var);

 

Nothing would be echoed on the webpage when I click on the button.

 

Anybody knows why?

 

Thanks.

 

Tom

The code you posted relies on a feature (register_globals) that was turned off almost 7 years ago in php4.2 and has been removed in php6. You either need to fix the code or find more up to date code that does what you want.

No mistake. The following problems exist in the code you posted -

 

session_register("ses_startvar") does not work. Code needs to use the correct $_SESSION variable.

 

$posted appears to be from a form field and does not work. Code needs to use the correct $_POST or $_GET variable.

 

$_COOKIE[phpSESSID] is incorrect syntax. The correct syntax is $_COOKIE['PHPSESSID']. The first form does function but goes through a painfully slow defined constant search and error handling/recovery process before the actual array variable is referenced.

 

In the last code you posted $form_var appears from a form, like the $posted variable and has the same problem.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.