Any problem with PHP can be disscused here
Praveen
Posts: 146 Joined: Fri Oct 21, 2005 11:47 am
Contact:
Post
by Praveen » Sun Nov 06, 2005 5:39 am
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 !!
johnjg75
Posts: 108 Joined: Thu Nov 03, 2005 2:31 am
Post
by johnjg75 » Sun Nov 06, 2005 6:01 am
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 !!
johnjg75
Posts: 108 Joined: Thu Nov 03, 2005 2:31 am
Post
by johnjg75 » Mon Nov 07, 2005 5:46 am
that looks fairly close to mine, right?
Praveen
Posts: 146 Joined: Fri Oct 21, 2005 11:47 am
Contact:
Post
by Praveen » Mon Nov 07, 2005 10:17 am
Thaaaaaaaaaaaaaaaaaaaanks a lot!
Praveen
Posts: 146 Joined: Fri Oct 21, 2005 11:47 am
Contact:
Post
by Praveen » Mon Nov 07, 2005 12:48 pm
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 !!
Praveen
Posts: 146 Joined: Fri Oct 21, 2005 11:47 am
Contact:
Post
by Praveen » Mon Nov 07, 2005 12:59 pm
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 !!
Lixas
Posts: 750 Joined: Wed Feb 16, 2005 4:21 pm
Post
by Lixas » Tue Nov 08, 2005 8:12 am
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
Praveen
Posts: 146 Joined: Fri Oct 21, 2005 11:47 am
Contact:
Post
by Praveen » Tue Nov 08, 2005 11:51 am
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
Praveen
Posts: 146 Joined: Fri Oct 21, 2005 11:47 am
Contact:
Post
by Praveen » Tue Nov 08, 2005 11:55 am
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