Page 1 of 3
Could anybody please help me???
Posted: Sun Nov 06, 2005 5:39 am
by Praveen
Hi
I know asp to some extent and php nothing. I want a session script in php. Could anybody help me?
In ASP the code works like this.
Code: Select all
<%
Session("session_name") = "123"
%>
<%
If Session("session_name") = "123" Then
%>
Execute these HTML codes.
<%
Else
%>
Execute these false HTML codes.
<%
End If
%>
I want a code in php. Please help.
Edited by moderator. For code use code tags !!
Posted: Sun Nov 06, 2005 6:01 am
by johnjg75
Code: Select all
<?php
session_start();
$sessionname = "123";
session_register('sessionname');
?>
<?php
if($_SESSION[sessionname] = "123")
{
?>
Execute these HTML codes.
<?php
}else{
?>
Execute these false HTML codes.
<?php
}
?>
That's my closest guess, i haven't used PHP in awhile.
Edited by moderator. For code use code tags !!
Posted: Mon Nov 07, 2005 3:21 am
by UNDERCOVER
Posted: Mon Nov 07, 2005 5:46 am
by johnjg75
that looks fairly close to mine, right?
Posted: Mon Nov 07, 2005 10:17 am
by Praveen
Thaaaaaaaaaaaaaaaaaaaanks a lot!
Posted: Mon Nov 07, 2005 12:48 pm
by Praveen
But I have a little problem.
Iam getting the error:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at c:\Inetpub\www\Workings\55psd\index.php:4) in c:\Inetpub\www\Workings\55psd\index.php on line 80
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at c:\Inetpub\www\Workings\55psd\index.php:4) in c:\Inetpub\www\Workings\55psd\index.php on line 80
Notice: Use of undefined constant sessionname - assumed 'sessionname' in c:\Inetpub\www\Workings\55psd\index.php on line 85
Edited by moderator. For errors use quote tags !!
Posted: Mon Nov 07, 2005 12:59 pm
by Praveen
If you can please remodify this in php. Please do the same.
index.asp
Code: Select all
<html>
<head>
<title>Check ASP</title>
</head>
<body link=#0000FF alink=#0000FF vlink=#0000FF text=#000000 bgcolor=#ffffff>
<font face=tahoma size=3>
<%
If Session("mysite") <> "me" Then
%>
Not Me, [url=login.asp]Change[/url]
<%
Else
%>
Me, [url=logout.asp]Change[/url]
<%
End If
%>
</font>
</body>
</html>
login.asp
Code: Select all
<%
Session("mysite") = "me"
Response.Redirect "index.asp"
%>
logout.asp
Code: Select all
<%
Session.Abandon
Response.Redirect "index.asp"
%>
Edited by moderator. For code use code tags !!
Posted: Tue Nov 08, 2005 8:12 am
by Lixas
index.php
Code: Select all
<?$mysite=$_SESSION["mysite"];?>
<html>
<head>
<title>Check ASP</title>
</head>
<body link=#0000FF alink=#0000FF vlink=#0000FF text=#000000 bgcolor=#ffffff>
<font face=tahoma size=3>
<?
If ($mysite != "me" )
echo "[url=login.asp]Change[/url]";
else
echo "[url=logout.asp]Change[/url]";
?>
</font>
</body>
</html>
login.php
Code: Select all
<?
session_start();
$_SESSION["mysite"] = "me";
// header must be before any output, it would be best if u use separate file for sesion registration, like here- only session registration and redirection
Header(location:index.php);
?>
logout.php
Code: Select all
<?
session_destroy();
header("location: index.php");
?>
Try this, it should be ok. If somthing will not work, paste here and error
Posted: Tue Nov 08, 2005 11:51 am
by Praveen
The same code, with this result in index.php.
Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in c:\Inetpub\www\phplogin\index.php on line 11
Posted: Tue Nov 08, 2005 11:55 am
by Praveen
I changed the code of index.php to
Code: Select all
<?$mysite=$_SESSION["mysite"];?>
<html>
<head>
<title>Check ASP</title>
</head>
<body link=#0000FF alink=#0000FF vlink=#0000FF text=#000000 bgcolor=#ffffff>
<font face=tahoma size=3>
<?
If ($mysite != "me" )
echo "[url=login.php]Login[/url]";
else
echo "[url=logout.php]Logout[/url]";
?>
</font>
</body>
</html>
Then the error was:
Parse error: parse error, unexpected ':' in c:\Inetpub\www\phplogin\login.php on line 6