-2
4:$textik = $_POST['text']; 

and im getting

notice: Undefined index: text in path/to/script on line 4.

why?

the url is
http://somesite.domain/path/to/script?text=something
Thanks for answers

edit: full script in path/to/script is

 <?php session_start(); if(isset($_SESSION['name'])){ $textik = $_POST['text']; date_default_timezone_set(date_default_timezone_get()); $time = date('h:i', time()); $fp = fopen("log.html", 'a'); fwrite($fp, "<li class='other'> <div class='msg'> <div class='user'>".$_SESSION['name']."</div> <p>".stripslashes(htmlspecialchars($textik))."</p> <time>".$time."</time> </div> </li>"); fclose($fp); } ?> 

and in path/to/anotherscript is

<?php session_start (); function loginForm() { echo ' <div id="loginform"> <form action="index.php" method="post"> <p>Please enter your name to continue:</p> <label for="name">Name:</label> <input type="text" name="name" id="name" /> <input type="submit" name="enter" id="enter" value="Enter" /> </form> </div> '; } if (isset ( $_POST ['enter'] )) { if ($_POST ['name'] != "") { $_SESSION ['name'] = stripslashes ( htmlspecialchars ( $_POST ['name'] ) ); $fp = fopen ( "log.html", 'a' ); date_default_timezone_set(date_default_timezone_get()); $time = date('h:i', time()); fwrite ( $fp, "<p class='notification'> ". $_SESSION ['name'] . " left the group <time>". $time."</time></p>" ); fclose ( $fp ); } else { echo '<span class="error">Please type in a name</span>'; } } if (isset ( $_GET ['logout'] )) { // Simple exit message $fp = fopen ( "log.html", 'a' ); fwrite ( $fp, "<div class='msgln'><i>User " . $_SESSION ['name'] . " has left the chat session.</i><br></div>" ); fclose ( $fp ); session_destroy (); header ( "Location: index.php" ); // Redirect the user } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel='stylesheet' type='text/css' href='new.css'> <title>AZsites chat</title> </head> <body> <?php if (! isset ( $_SESSION ['name'] )) { loginForm (); } else { ?> <div id="wrapper"> <ol class="chat"> <div class="menu"> <a href="#" class="back"><i class="fa fa-angle-left"></i> <img src="https://i.imgur.com/G4EjwqQ.jpg" draggable="false"/></a> <div class="name">AZsites chat</div> <div class="members"><b><?php echo $_SESSION['name']; ?></b> a dalsi</div> </div><?php if (file_exists ( "log.html" ) && filesize ( "log.html" ) > 0) { $handle = fopen ( "log.html", "r" ); $contents = fread ( $handle, filesize ( "log.html" ) ); fclose ( $handle ); echo $contents; } ?></ol></div> <div class="typezone"> <form name="message" action='' method='post'><textarea name="text" id="usermsg" size="63"type="text" placeholder="Napis neco"></textarea><input type="submit" class="send" value="odeslat"/></form> <div class="emojis"></div></div> </div> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript"> // jQuery Document $(document).ready(function(){ }); //jQuery Document $(document).ready(function(){ //If user wants to end session $("#exit").click(function(){ var exit = confirm("Are you sure you want to end the session?"); if(exit==true){window.location = 'index.php?logout=true';} }); }); //If user submits the form $("#submitmsg").click(function(){ var clientmsg = $("#usermsg").val(); $.post("post.php", {text: clientmsg}); $("#usermsg").attr("value", ""); loadLog; return false; }); function loadLog(){ var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20; //Scroll height before the request $.ajax({ url: "log.html", cache: false, success: function(html){ $("#chatbox").html(html); //Insert chat log into the #chatbox div //Auto-scroll var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20; //Scroll height after the request if(newscrollHeight > oldscrollHeight){ $("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div } }, }); } setInterval (loadLog, 500); </script> <?php } ?> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript"> </script> </body> </html> 

so i need to have post because it run in background, normal user don't see it, but here it has an edit to see it, but i don't know how to edit it to normal state..... Please, help me... thanks!

1
  • 1
    should be a GET Commented Aug 2, 2017 at 9:47

2 Answers 2

1

You are using $_POST instead of $_GET. Your URL is http://somesite.domain/path/to/script?text=something and text is the GET parameter.

So you need to change

$textik = $_POST['text']; 

to

$textik = $_GET['text']; 
Sign up to request clarification or add additional context in comments.

1 Comment

True, but i edited it and than it works, but it more like before, it has POST, not GET. But thanks, now i know how to do it.
0

You need to use GET, not POST

$textik = $_GET['text']; 

Have a read of this W3Schools article for further clarity.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.